migration_equipment_warning_threshold_config.sql 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. -- 统一设备报警阈值配置(KingbaseES)
  2. -- 1) equipment_warning_type 保存设备类型的预警指标元数据;
  3. -- 2) warning_threshold 保存设备编码 + warning_code 的实际阈值;
  4. -- 3) 旧供水/排水/燃气/窨井菜单统一指向同一页面,通过 query.rootTypeId 隔离设备范围。
  5. CREATE TABLE IF NOT EXISTS app_user.equipment_warning_type (
  6. id int8 GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  7. equipment_type_id int8 NOT NULL,
  8. warning_code varchar(50) NOT NULL,
  9. warning_name varchar(50) NOT NULL,
  10. warning_unit varchar(50),
  11. data_type int2 NOT NULL DEFAULT 0,
  12. remark varchar(255),
  13. create_time sys."timestamp" DEFAULT now(),
  14. update_time sys."timestamp" DEFAULT now()
  15. );
  16. COMMENT ON TABLE app_user.equipment_warning_type IS '设备预警指标类型配置';
  17. COMMENT ON COLUMN app_user.equipment_warning_type.equipment_type_id IS '设备类型ID';
  18. COMMENT ON COLUMN app_user.equipment_warning_type.warning_code IS '报警编码';
  19. COMMENT ON COLUMN app_user.equipment_warning_type.warning_name IS '报警名称';
  20. COMMENT ON COLUMN app_user.equipment_warning_type.warning_unit IS '监测单位';
  21. COMMENT ON COLUMN app_user.equipment_warning_type.data_type IS '数字类型:0最小+最大,1最小值,2最大值';
  22. CREATE INDEX IF NOT EXISTS idx_equipment_warning_type_type ON app_user.equipment_warning_type(equipment_type_id);
  23. CREATE UNIQUE INDEX IF NOT EXISTS uk_equipment_warning_type_code ON app_user.equipment_warning_type(equipment_type_id, warning_code);
  24. -- 旧入口按 menu_id 精准迁移,避免同名菜单被误改:
  25. -- 2119 供水、2194 排水、2017 窨井盖、2192 燃气。
  26. UPDATE app_user.sys_menu
  27. SET component = 'subSystem/lifeCompany/warningThreshold/index',
  28. path = 'warningThreshold',
  29. query = '{"rootTypeId":1}'
  30. WHERE menu_id = 2119;
  31. UPDATE app_user.sys_menu
  32. SET component = 'subSystem/lifeCompany/warningThreshold/index',
  33. path = 'warningThreshold',
  34. query = '{"rootTypeId":2}'
  35. WHERE menu_id = 2194;
  36. UPDATE app_user.sys_menu
  37. SET component = 'subSystem/lifeCompany/warningThreshold/index',
  38. path = 'warningThreshold',
  39. query = '{"rootTypeId":4}'
  40. WHERE menu_id = 2017;
  41. UPDATE app_user.sys_menu
  42. SET component = 'subSystem/lifeCompany/warningThreshold/index',
  43. path = 'warningThreshold',
  44. query = '{"rootTypeId":3}'
  45. WHERE menu_id = 2192;
  46. -- 生命线预警联动处置系统下新增两级菜单:
  47. -- 阈值管理(2241, parent_id=2006) -> 报警阈值(2242)。
  48. DO $$
  49. BEGIN
  50. IF NOT EXISTS (SELECT 1 FROM app_user.sys_menu WHERE menu_id = 2241) THEN
  51. INSERT INTO app_user.sys_menu
  52. (menu_id, menu_name, parent_id, order_num, path, component, query, route_name,
  53. is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
  54. VALUES
  55. (2241, '阈值管理', 2006, 30, 'thresholdManagement', 'ParentView', '',
  56. 'LifeCompanyThresholdManagement', '1', '0', 'M', '0', '0', '', 'setting', 'admin', now(), '报警阈值管理');
  57. ELSE
  58. UPDATE app_user.sys_menu
  59. SET menu_name = '阈值管理', parent_id = 2006, order_num = 30,
  60. path = 'thresholdManagement', component = 'ParentView', query = '',
  61. route_name = 'LifeCompanyThresholdManagement', menu_type = 'M',
  62. visible = '0', status = '0', icon = 'setting', remark = '报警阈值管理'
  63. WHERE menu_id = 2241;
  64. END IF;
  65. IF NOT EXISTS (SELECT 1 FROM app_user.sys_menu WHERE menu_id = 2242) THEN
  66. INSERT INTO app_user.sys_menu
  67. (menu_id, menu_name, parent_id, order_num, path, component, query, route_name,
  68. is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, remark)
  69. VALUES
  70. (2242, '报警阈值', 2241, 1, 'warningThreshold',
  71. 'subSystem/lifeCompany/warningThreshold/index', '', 'LifeCompanyAlarmThreshold',
  72. '1', '0', 'C', '0', '0', 'warning:threshold:list', 'chart', 'admin', now(), '报警阈值配置');
  73. ELSE
  74. UPDATE app_user.sys_menu
  75. SET menu_name = '报警阈值', parent_id = 2241, order_num = 1,
  76. path = 'warningThreshold', component = 'subSystem/lifeCompany/warningThreshold/index',
  77. query = '', route_name = 'LifeCompanyAlarmThreshold', menu_type = 'C',
  78. visible = '0', status = '0', perms = 'warning:threshold:list',
  79. icon = 'chart', remark = '报警阈值配置'
  80. WHERE menu_id = 2242;
  81. END IF;
  82. END $$;
  83. -- 统一菜单路由名称;menu_id 精确限定为新建的全量报警阈值入口。
  84. UPDATE app_user.sys_menu
  85. SET path = 'warningThreshold',
  86. component = 'subSystem/lifeCompany/warningThreshold/index',
  87. perms = 'warning:threshold:list'
  88. WHERE menu_id = 2242;
  89. ALTER TABLE app_user.warning_threshold DROP COLUMN IF EXISTS warning_type;
  90. ALTER TABLE app_user.warning_threshold DROP COLUMN IF EXISTS remark;