智慧水务管理系统 - 精河县供水工程综合管理平台

V1__seed.sql 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. -- 初始化数据脚本
  2. -- 生成时间: 2026-06-15
  3. -- 作者: bot_dev1 (基于 Issue #18 任务)
  4. -- ========= 系统初始化数据 =========
  5. -- 部门数据
  6. INSERT INTO sys_dept (id, parent_id, dept_name, dept_type, sort_order, status) VALUES
  7. (1, 0, 'XX市水利局', 'water_bureau', 1, 1),
  8. (2, 1, 'XX市水务集团', 'water_company', 1, 1),
  9. (3, 2, '供水营业部', 'water_company', 1, 1),
  10. (4, 2, '管网运维部', 'water_company', 2, 1),
  11. (5, 2, '水质监测部', 'water_company', 3, 1),
  12. (6, 2, '客户服务中心', 'water_company', 4, 1),
  13. (7, 4, '精芒片区运维组', 'ops', 1, 1),
  14. (8, 4, '托里片区运维组', 'ops', 2, 1),
  15. (9, 4, '一体化水厂运维组', 'ops', 3, 1);
  16. -- 角色数据
  17. INSERT INTO sys_role (id, role_name, role_key, data_scope, description) VALUES
  18. (1, '系统管理员', 'admin', 'ALL', '系统最高权限,可管理所有功能'),
  19. (2, '领导干部', 'leader', 'ALL', '分管领导,可查看全局数据'),
  20. (3, '部门经理', 'manager', 'DEPT', '部门负责人,管理本部门业务'),
  21. (4, '业务操作员', 'operator', 'DEPT', '日常业务操作人员'),
  22. (5, '技术维护', 'tech', 'DEPT', '系统维护和故障处理');
  23. -- 用户数据(admin用户)
  24. INSERT INTO sys_user (id, dept_id, username, password, real_name, role_type, status) VALUES
  25. (1, 1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', '系统管理员', 'admin', 1);
  26. -- admin用户密码:123456 (MD5加密)
  27. -- 菜单数据(管理员菜单)
  28. INSERT INTO sys_menu (id, parent_id, menu_name, menu_key, menu_type, path, component, perms, icon, sort_order, visible, status) VALUES
  29. (1, 0, '系统管理', 'system', 'directory', '/system', NULL, NULL, 'setting', 1, 1, 1),
  30. (2, 1, '用户管理', 'user', 'menu', '/system/user', 'system/user/index', 'system:user:list', 'user', 1, 1, 1),
  31. (3, 1, '角色管理', 'role', 'menu', '/system/role', 'system/role/index', 'system:role:list', 'team', 2, 1, 1),
  32. (4, 1, '菜单管理', 'menu', 'menu', '/system/menu', 'system/menu/index', 'system:menu:list', 'tree', 3, 1, 1),
  33. (5, 1, '部门管理', 'dept', 'menu', '/system/dept', 'system/dept/index', 'system:dept:list', 'building', 4, 1, 1),
  34. (6, 1, '操作日志', 'log', 'menu', '/system/log', 'system/log/index', 'system:log:list', 'log', 5, 1, 1),
  35. (7, 0, '物联网平台', 'iot', 'directory', '/iot', NULL, NULL, 'sensor', 10, 1, 1),
  36. (8, 7, '设备管理', 'device', 'menu', '/iot/device', 'iot/device/index', 'iot:device:list', 'monitor', 1, 1, 1),
  37. (9, 7, '设备模型', 'device-model', 'menu', '/iot/device-model', 'iot/device-model/index', 'iot:device-model:list', 'model', 2, 1, 1),
  38. (10, 7, '数据接入', 'data-adapter', 'menu', '/iot/data-adapter', 'iot/data-adapter/index', 'iot:data-adapter:list', 'upload', 3, 1, 1),
  39. (11, 0, '营业收费', 'revenue', 'directory', '/revenue', NULL, NULL, 'money', 20, 1, 1),
  40. (12, 11, '客户管理', 'customer', 'menu', '/revenue/customer', 'revenue/customer/index', 'revenue:customer:list', 'people', 1, 1, 1),
  41. (13, 11, '水表管理', 'meter', 'menu', '/revenue/meter', 'revenue/meter/index', 'revenue:meter:list', 'meter', 2, 1, 1),
  42. (14, 11, '抄表管理', 'reading', 'menu', '/revenue/reading', 'revenue/reading/index', 'revenue:reading:list', 'file-search', 3, 1, 1),
  43. (15, 11, '账单管理', 'bill', 'menu', '/revenue/bill', 'revenue/bill/index', 'revenue:bill:list', 'file-text', 4, 1, 1),
  44. (16, 11, '收费管理', 'payment', 'menu', '/revenue/payment', 'revenue/payment/index', 'revenue:payment:list', 'pay-circle', 5, 1, 1),
  45. (17, 0, '巡检系统', 'patrol', 'directory', '/patrol', NULL, NULL, 'truck', 30, 1, 1),
  46. (18, 17, '路线管理', 'route', 'menu', '/patrol/route', 'patrol/route/index', 'patrol:route:list', 'route', 1, 1, 1),
  47. (19, 17, '任务管理', 'task', 'menu', '/patrol/task', 'patrol/task/index', 'patrol:task:list', 'calendar', 2, 1, 1),
  48. (20, 17, '巡检记录', 'record', 'menu', '/patrol/record', 'patrol/record/index', 'patrol:record:list', 'checklist', 3, 1, 1),
  49. (21, 0, '报警管理', 'alert', 'directory', '/alert', NULL, NULL, 'warning', 40, 1, 1),
  50. (22, 21, '报警规则', 'rule', 'menu', '/alert/rule', 'alert/rule/index', 'alert:rule:list', 'rule', 1, 1, 1),
  51. (23, 21, '报警事件', 'event', 'menu', '/alert/event', 'alert/event/index', 'alert:event:list', 'exception', 2, 1, 1),
  52. (24, 21, '报警处理', 'handle', 'menu', '/alert/handle', 'alert/handle/index', 'alert:handle:list', 'service', 3, 1, 1),
  53. (25, 0, '数据引擎', 'data-engine', 'directory', '/data-engine', NULL, NULL, 'database', 50, 1, 1),
  54. (26, 25, '数据治理', 'governance', 'menu', '/data-engine/governance', 'data-engine/governance/index', 'data:governance:list', 'filter', 1, 1, 1),
  55. (27, 25, '数据服务', 'service', 'menu', '/data-engine/service', 'data-engine/service/index', 'data:service:list', 'api', 2, 1, 1),
  56. (28, 25, '数据目录', 'catalog', 'menu', '/data-engine/catalog', 'data-engine/catalog/index', 'data:catalog:list', 'folder', 3, 1, 1),
  57. (29, 0, '供水生产', 'production', 'directory', '/production', NULL, NULL, 'water', 60, 1, 1),
  58. (30, 29, '总览监测', 'overview', 'menu', '/production/overview', 'production/overview/index', 'production:overview:list', 'dashboard', 1, 1, 1),
  59. (31, 29, '水质管理', 'water-quality', 'menu', '/production/water-quality', 'production/water-quality/index', 'production:water-quality:list', 'science', 2, 1, 1),
  60. (32, 29, '调度管理', 'dispatch', 'menu', '/production/dispatch', 'production/dispatch/index', 'production:dispatch:list', 'schedule', 3, 1, 1),
  61. (33, 29, '报警中心', 'monitor', 'menu', '/production/monitor', 'production/monitor/index', 'production:monitor:list', 'radar', 4, 1, 1);
  62. -- 分配管理员角色和菜单
  63. INSERT INTO sys_user_role (user_id, role_id) VALUES (1, 1);
  64. INSERT INTO sys_role_menu (role_id, menu_id)
  65. SELECT 1, id FROM sys_menu WHERE status = 1;
  66. -- 分配用户角色(admin)
  67. INSERT INTO sys_user_role (user_id, role_id) VALUES (1, 1);
  68. -- ========= 物联网平台初始化数据 =========
  69. -- 设备模型定义
  70. INSERT INTO iot_device_model (id, model_key, model_name, vendor, protocol, properties, commands) VALUES
  71. (1, 'water_meter_dn15', 'DN15远传水表', 'XX水表厂', 'MQTT',
  72. '[
  73. {"key": "flow_rate", "name": "瞬时流量", "unit": "m³/h", "data_type": "double", "range": "0-10"},
  74. {"key": "total_flow", "name": "累计流量", "unit": "m³", "data_type": "double", "range": "0-999999"},
  75. {"key": "battery", "name": "电池电压", "unit": "V", "data_type": "double", "range": "2.8-3.6"},
  76. {"key": "signal", "name": "信号强度", "unit": "dBm", "data_type": "int", "range": "-120 to -30"}
  77. ]',
  78. '[
  79. {"key": "reset", "name": "复位", "params": []},
  80. {"key": "read_config", "name": "读取配置", "params": []}
  81. ]'),
  82. (2, 'pressure_sensor', '压力传感器', 'XX传感器厂', 'Modbus',
  83. '[
  84. {"key": "pressure", "name": "压力值", "unit": "MPa", "data_type": "double", "range": "0-1"},
  85. {"key": "temperature", "name": "温度", "unit": "°C", "data_type": "double", "range": "-20 to 80"},
  86. {"key": "voltage", "name": "供电电压", "unit": "V", "data_type": "double", "range": "12-24"}
  87. ]',
  88. '[
  89. {"key": "calibrate", "name": "校准", "params": [{"name": "pressure", "type": "double"}]}
  90. ]'),
  91. (3, 'water_quality_sensor', '水质分析仪', 'XX环保仪器厂', 'HTTP',
  92. '[
  93. {"key": "turbidity", "name": "浊度", "unit": "NTU", "data_type": "double", "range": "0-1000"},
  94. {"key": "ph", "name": "pH值", "unit": "", "data_type": "double", "range": "0-14"},
  95. {"key": "conductivity", "name": "电导率", "unit": "μS/cm", "data_type": "double", "range": "0-10000"},
  96. {"key": "chlorine", "name": "余氯", "unit": "mg/L", "data_type": "double", "range": "0-5"}
  97. ]',
  98. '[
  99. {"key": "calibrate_ph", "name": "pH校准", "params": [{"name": "standard", "type": "double"}]},
  100. {"key": "start_test", "name": "开始测试", "params": []}
  101. ]'),
  102. (4, 'level_sensor', '液位传感器', 'XX传感器厂', 'CoAP',
  103. '[
  104. {"key": "water_level", "name": "液位", "unit": "m", "data_type": "double", "range": "0-10"},
  105. {"key": "temperature", "name": "水温", "unit": "°C", "data_type": "double", "range": "0-50"}
  106. ]',
  107. '[
  108. {"key": "calibrate_zero", "name": "零点校准", "params": []}
  109. ]'),
  110. (5, 'valve_controller', '电动阀门控制器', 'XX自控设备厂', 'MQTT',
  111. '[
  112. {"key": "valve_position", "name": "阀门开度", "unit": "%", "data_type": "int", "range": "0-100"},
  113. {"key": "motor_current", "name": "电机电流", "unit": "A", "data_type": "double", "range": "0-10"},
  114. {"key": "status", "name": "状态", "data_type": "string", "range": "open/closing/closed/fault"}
  115. ]',
  116. '[
  117. {"key": "open", "name": "打开", "params": []},
  118. {"key": "close", "name": "关闭", "params": []},
  119. {"key": "stop", "name": "停止", "params": []}
  120. ]');
  121. -- 示例设备实例
  122. INSERT INTO iot_device (id, device_sn, device_name, model_id, device_type, position_type, loc_lng, loc_lat, area, station_id, status) VALUES
  123. (1, 'JM20260001', '精芒片区-001号水表', 1, 'flow_meter', 'village', 116.123456, 39.987654, '精芒片区', 'jm001', 'online'),
  124. (2, 'JM20260002', '精芒片区-002号水表', 1, 'flow_meter', 'village', 116.123789, 39.987721, '精芒片区', 'jm001', 'online'),
  125. (3, 'TL20260001', '托里片区-001号压力表', 2, 'pressure_sensor', 'pressure_station', 116.124123, 39.988456, '托里片区', 'tl001', 'online'),
  126. (4, 'TL20260002', '托里片区-002号压力表', 2, 'pressure_sensor', 'pressure_station', 116.124654, 39.988887, '托里片区', 'tl001', 'online'),
  127. (5, 'YT20260001', '一体化水厂-入口水质监测', 3, 'water_quality', 'water_plant', 116.125987, 39.990123, '一体化水厂', 'yt001', 'online'),
  128. (6, 'YT20260002', '一体化水厂-出口水质监测', 3, 'water_quality', 'water_plant', 116.126234, 39.990456, '一体化水厂', 'yt001', 'online'),
  129. (7, 'JM20260003', '精芒片区-1号水池液位', 4, 'level_sensor', 'water_plant', 116.123234, 39.987890, '精芒片区', 'jm002', 'online'),
  130. (8, 'TL20260003', '托里片区-1号阀门', 5, 'valve_controller', 'pipe_network', 116.124876, 39.988234, '托里片区', 'pn001', 'online');
  131. -- 空间坐标更新(为示例设备添加PostGIS坐标)
  132. UPDATE iot_device
  133. SET geom = ST_MakePoint(116.123456, 39.987654)
  134. WHERE device_sn = 'JM20260001';
  135. UPDATE iot_device
  136. SET geom = ST_MakePoint(116.123789, 39.987721)
  137. WHERE device_sn = 'JM20260002';
  138. UPDATE iot_device
  139. SET geom = ST_MakePoint(116.124123, 39.988456)
  140. WHERE device_sn = 'TL20260001';
  141. UPDATE iot_device
  142. SET geom = ST_MakePoint(116.124654, 39.988887)
  143. WHERE device_sn = 'TL20260002';
  144. UPDATE iot_device
  145. SET geom = ST_MakePoint(116.125987, 39.990123)
  146. WHERE device_sn = 'YT20260001';
  147. UPDATE iot_device
  148. SET geom = ST_MakePoint(116.126234, 39.990456)
  149. WHERE device_sn = 'YT20260002';
  150. UPDATE iot_device
  151. SET geom = ST_MakePoint(116.123234, 39.987890)
  152. WHERE device_sn = 'JM20260003';
  153. UPDATE iot_device
  154. SET geom = ST_MakePoint(116.124876, 39.988234)
  155. WHERE device_sn = 'TL20260003';
  156. -- ========= 营业收费初始化数据 =========
  157. -- 水费标准
  158. INSERT INTO rev_water_rate (id, rate_name, customer_type, step_threshold, step_rates, start_date, end_date, status) VALUES
  159. (1, '居民阶梯水价', 'residential',
  160. '[{"threshold": 0, "step": 1}, {"threshold": 12, "step": 2}, {"threshold": 24, "step": 3}]',
  161. '[{"rate": 2.5}, {"rate": 3.5}, {"rate": 5.0}]',
  162. '2026-01-01', '2026-12-31', 1),
  163. (2, '非居民水价', 'business',
  164. '[{"threshold": 0, "step": 1}]',
  165. '[{"rate": 3.8}]',
  166. '2026-01-01', '2026-12-31', 1);
  167. -- 示例客户数据
  168. INSERT INTO rev_customer (id, customer_no, customer_name, customer_type, area, address, phone, id_card, contract_no, status) VALUES
  169. (1, 'R20260001', '张三', 'residential', '精芒片区', 'XX市XX区精芒街道001号', '13800138001', '110101199001011234', 'CT20260001', 'active'),
  170. (2, 'R20260002', '李四', 'residential', '精芒片区', 'XX市XX区精芒街道002号', '13800138002', '110101199002022345', 'CT20260002', 'active'),
  171. (3, 'B20260001', 'XX超市', 'business', '托里片区', 'XX市XX区托里商圈001号', '13800138003', NULL, 'CT20260003', 'active'),
  172. (4, 'B20260002', 'XX酒店', 'business', '托里片区', 'XX市XX区托里商圈002号', '13800138004', NULL, 'CT20260004', 'active');
  173. -- 示例水表数据
  174. INSERT INTO rev_meter (id, meter_no, customer_id, device_id, caliber, meter_type, initial_reading, install_date, status) VALUES
  175. (1, 'M20260001', 1, 1, 'DN15', 'mechanical', 0.00, '2026-01-01', 'active'),
  176. (2, 'M20260002', 2, 2, 'DN15', 'mechanical', 0.00, '2026-01-01', 'active'),
  177. (3, 'M20260003', 3, 3, 'DN20', 'ultrasonic', 0.00, '2026-01-01', 'active'),
  178. (4, 'M20260004', 4, 4, 'DN20', 'ultrasonic', 0.00, '2026-01-01', 'active');
  179. -- ========= 巡检系统初始化数据 =========
  180. -- 巡检标准
  181. INSERT INTO patrol_standard (id, standard_name, device_type, check_items, scoring_rules) VALUES
  182. (1, '水表巡检标准', 'flow_meter',
  183. '[
  184. {"item": "表体完整性", "required": true, "weight": 10},
  185. {"item": "指示器读数清晰", "required": true, "weight": 10},
  186. {"item": "管道连接牢固", "required": true, "weight": 15},
  187. {"item": "无漏水现象", "required": true, "weight": 25},
  188. {"item": "防护设施完好", "required": true, "weight": 20},
  189. {"item": "周围环境整洁", "required": false, "weight": 5}
  190. ]',
  191. '[
  192. {"pass": "评分>=80分", "weight": 100},
  193. {"warning": "评分60-79分", "weight": 80},
  194. {"fail": "评分<60分", "weight": 60}
  195. ]'),
  196. (2, '压力传感器巡检标准', 'pressure_sensor',
  197. '[
  198. {"item": "表体完整性", "required": true, "weight": 15},
  199. {"item": "显示读数正常", "required": true, "weight": 20},
  200. {"item": "连接管路牢固", "required": true, "weight": 15},
  201. {"item": "无泄漏现象", "required": true, "weight": 25},
  202. {"item": "安装固定牢固", "required": true, "weight": 15},
  203. {"item": "供电正常", "required": true, "weight": 10}
  204. ]',
  205. '[
  206. {"pass": "评分>=85分", "weight": 100},
  207. {"warning": "评分70-84分", "weight": 80},
  208. {"fail": "评分<70分", "weight": 60}
  209. ]');
  210. -- 示例巡检路线
  211. INSERT INTO patrol_route (id, route_name, area, route_points, estim_duration, status) VALUES
  212. (1, '精芒片区日巡检路线', '精芒片区',
  213. '[
  214. {"seq": 1, "lng": 116.123456, "lat": 39.987654, "name": "JM001水表", "device_ids": [1]},
  215. {"seq": 2, "lng": 116.123789, "lat": 39.987721, "name": "JM002水表", "device_ids": [2]},
  216. {"seq": 3, "lng": 116.123234, "lat": 39.987890, "name": "JM001水池", "device_ids": [7]},
  217. {"seq": 4, "lng": 116.123890, "lat": 39.987945, "name": "管网检查点1", "device_ids": []}
  218. ]',
  219. 120, 1),
  220. (2, '托里片区日巡检路线', '托里片区',
  221. '[
  222. {"seq": 1, "lng": 116.124123, "lat": 39.988456, "name": "TL001压力站", "device_ids": [3]},
  223. {"seq": 2, "lng": 116.124654, "lat": 39.988887, "name": "TL002压力站", "device_ids": [4]},
  224. {"seq": 3, "lng": 116.124876, "lat": 39.988234, "name": "TL001阀门", "device_ids": [8]},
  225. {"seq": 4, "lng": 116.124234, "lat": 39.988567, "name": "管网检查点2", "device_ids": []}
  226. ]',
  227. 90, 1);
  228. -- ========= 报警管理初始化数据 =========
  229. -- 报警规则
  230. INSERT INTO alert_rule (id, rule_name, device_type, metric_key, alert_level, condition_expr, threshold_value, debounce_sec, notify_scheme_id, enabled) VALUES
  231. (1, '流量异常报警', 'flow_meter', 'flow_rate', 'warning', '> 10', '10.0', 300, 1, 1),
  232. (2, '压力过高报警', 'pressure_sensor', 'pressure', 'critical', '> 0.8', '0.8', 300, 1, 1),
  233. (3, '压力过低报警', 'pressure_sensor', 'pressure', 'warning', '< 0.1', '0.1', 300, 1, 1),
  234. (4, '水质浊度报警', 'water_quality_sensor', 'turbidity', 'emergency', '> 10', '10.0', 300, 1, 1),
  235. (5, '电池电量低报警', 'flow_meter', 'battery', 'info', '< 2.8', '2.8', 3600, 1, 1),
  236. (6, '设备离线报警', 'flow_meter', 'signal', 'critical', '< -100', '-100', 1800, 1, 1);
  237. -- 通知方案
  238. INSERT INTO alert_notify_scheme (id, scheme_name, channels, recipients, conditions, status) VALUES
  239. (1, '标准报警通知',
  240. '{
  241. "sms": true,
  242. "push": true,
  243. "websocket": true,
  244. "email": false
  245. }',
  246. '{
  247. "roles": ["operator", "manager"],
  248. "departments": [4, 7, 8, 9]
  249. }',
  250. '{
  251. "levels": ["info", "warning", "critical", "emergency"],
  252. "device_types": ["flow_meter", "pressure_sensor", "water_quality_sensor"]
  253. }', 1),
  254. (2, '紧急报警通知',
  255. '{
  256. "sms": true,
  257. "push": true,
  258. "websocket": true,
  259. "email": true
  260. }',
  261. '{
  262. "roles": ["admin", "leader", "manager"],
  263. "departments": [1, 2]
  264. }',
  265. '{
  266. "levels": ["critical", "emergency"],
  267. "device_types": ["water_quality_sensor"]
  268. }', 1);
  269. -- ========= 系统配置初始化数据 =========
  270. -- 系统参数配置
  271. INSERT INTO sys_config (id, config_key, config_name, config_value, config_type, description) VALUES
  272. (1, 'system.name', '系统名称', '智慧水务管理系统', 'string', '系统显示名称'),
  273. (2, 'system.version', '系统版本', '1.0.0', 'string', '当前系统版本'),
  274. (3, 'iot.mqtt.broker', 'MQTT服务器地址', 'mqtt://localhost:1883', 'string', 'MQTT消息服务器地址'),
  275. (4, 'iot.mqtt.username', 'MQTT用户名', 'water_mgt', 'string', 'MQTT认证用户名'),
  276. (5, 'iot.mqtt.password', 'MQTT密码', 'water_mgt_2026', 'string', 'MQTT认证密码'),
  277. (6, 'database.tdengine.host', 'TDengine主机地址', 'localhost', 'string', 'TDengine数据库主机'),
  278. (7, 'database.tdengine.port', 'TDengine端口', '6030', 'string', 'TDengine数据库端口'),
  279. (8, 'database.tdengine.user', 'TDengine用户名', 'root', 'string', 'TDengine数据库用户名'),
  280. (9, 'database.tdengine.password', 'TDengine密码', 'taosdata', 'string', 'TDengine数据库密码'),
  281. (10, 'notification.sms.provider', '短信服务商', 'aliyun', 'string', '短信服务提供商'),
  282. (11, 'notification.sms.access_key', '短信AccessKey', '', 'string', '短信服务AccessKey'),
  283. (12, 'notification.sms.secret_key', '短信SecretKey', '', 'string', '短信服务SecretKey'),
  284. (13, 'notification.push.provider', '推送服务商', 'jiguang', 'string', '推送服务提供商'),
  285. (14, 'notification.push.app_key', '推送AppKey', '', 'string', '推送服务AppKey'),
  286. (15, 'notification.push.master_secret', '推送MasterSecret', '', 'string', '推送服务MasterSecret');
  287. -- 数据字典
  288. INSERT INTO sys_dict (dict_type, dict_code, dict_label, dict_value, sort_order, status) VALUES
  289. -- 用户状态字典
  290. ('user_status', 'active', '正常', 'active', 1, 1),
  291. ('user_status', 'locked', '锁定', 'locked', 2, 1),
  292. ('user_status', 'disabled', '禁用', 'disabled', 3, 1),
  293. -- 设备状态字典
  294. ('device_status', 'online', '在线', 'online', 1, 1),
  295. ('device_status', 'offline', '离线', 'offline', 2, 1),
  296. ('device_status', 'maintenance', '维护中', 'maintenance', 3, 1),
  297. ('device_status', 'fault', '故障', 'fault', 4, 1),
  298. -- 报警等级字典
  299. ('alert_level', 'info', '提示', 'info', 1, 1),
  300. ('alert_level', 'warning', '警告', 'warning', 2, 1),
  301. ('alert_level', 'critical', '严重', 'critical', 3, 1),
  302. ('alert_level', 'emergency', '紧急', 'emergency', 4, 1),
  303. -- 客户类型字典
  304. ('customer_type', 'residential', '居民用户', 'residential', 1, 1),
  305. ('customer_type', 'business', '商业用户', 'business', 2, 1),
  306. ('customer_type', 'enterprise', '企业用户', 'enterprise', 3, 1),
  307. ('customer_type', 'institution', '机关单位', 'institution', 4, 1),
  308. -- 水表类型字典
  309. ('meter_type', 'mechanical', '机械水表', 'mechanical', 1, 1),
  310. ('meter_type', 'ultrasonic', '超声波水表', 'ultrasonic', 2, 1),
  311. ('meter_type', 'electromagnetic', '电磁水表', 'electromagnetic', 3, 1),
  312. ('meter_type', 'ic_card', 'IC卡水表', 'ic_card', 4, 1),
  313. -- 抄表类型字典
  314. ('read_type', 'manual', '人工抄表', 'manual', 1, 1),
  315. ('read_type', 'remote', '远程抄表', 'remote', 2, 1),
  316. ('read_type', 'estimate', '估抄', 'estimate', 3, 1);
  317. -- ========= Flyway/Liquibase 配置信息 =========
  318. -- 创建 Flyway 配置表
  319. CREATE TABLE IF NOT EXISTS flyway_schema_history (
  320. installed_rank INT NOT NULL,
  321. version VARCHAR(50) NOT NULL,
  322. description VARCHAR(200) NOT NULL,
  323. type VARCHAR(20) NOT NULL,
  324. script VARCHAR(1000) NOT NULL,
  325. checksum INT,
  326. installed_by VARCHAR(100) NOT NULL,
  327. installed_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  328. execution_time INT NOT NULL,
  329. success TINYINT NOT NULL
  330. );
  331. -- 插入 Flyway 迁移记录
  332. INSERT INTO flyway_schema_history (installed_rank, version, description, type, script, checksum, installed_by, execution_time, success)
  333. VALUES (1, '1', '初始化数据库脚本', 'SQL', 'V1__init.sql', NULL, 'admin', 0, 1);
  334. -- 创建 Liquibase 配置表(可选)
  335. CREATE TABLE IF NOT EXISTS databasechangelog (
  336. id VARCHAR(255) NOT NULL,
  337. author VARCHAR(255) NOT NULL,
  338. filename VARCHAR(255) NOT NULL,
  339. dateexecuted TIMESTAMP NOT NULL,
  340. orderexecuted INT NOT NULL,
  341. exectype VARCHAR(10) NOT NULL,
  342. md5sum VARCHAR(35),
  343. description VARCHAR(255),
  344. comments VARCHAR(255),
  345. tag VARCHAR(255),
  346. liquibase VARCHAR(20),
  347. contexts VARCHAR(255),
  348. labels VARCHAR(255),
  349. deployment_id VARCHAR(10)
  350. );
  351. -- 创建数据库配置文件模板
  352. -- 在应用启动时,以下配置文件应该被创建:
  353. -- - /config/application.yml (Spring Boot 配置)
  354. -- - /config/flyway.conf (Flyway 配置)
  355. -- - /config/liquibase.properties (Liquibase 配置)
  356. -- 配置文件内容示例
  357. /*
  358. # application.yml 配置示例
  359. spring:
  360. datasource:
  361. url: jdbc:postgresql://localhost:5432/water_mgt
  362. username: postgres
  363. password: postgres
  364. driver-class-name: org.postgresql.Driver
  365. hikari:
  366. maximum-pool-size: 20
  367. minimum-idle: 5
  368. idle-timeout: 300000
  369. connection-timeout: 20000
  370. connection-test-query: SELECT 1
  371. flyway:
  372. enabled: true
  373. locations: classpath:db/postgresql
  374. baseline-on-migrate: true
  375. baseline-version: 1
  376. # TDengine 配置
  377. tdengine:
  378. host: localhost
  379. port: 6030
  380. username: root
  381. password: taosdata
  382. database: water_mgt
  383. # Redis 配置
  384. spring:
  385. redis:
  386. host: localhost
  387. port: 6379
  388. password:
  389. database: 0
  390. */
  391. -- ========= 初始化完成 =========
  392. -- 数据库初始化脚本执行完成
  393. -- 创建时间: 2026-06-15
  394. -- 执行用户: bot_dev1
  395. -- 创建了完整的 PostgreSQL + TDengine 数据库结构
  396. -- 包含用户权限体系、物联网设备管理、营业收费、巡检系统、报警管理等模块
  397. -- 支持空间数据(PostGIS)和时序数据(TDengine)的存储和管理