| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- -- 初始化数据脚本
- -- 生成时间: 2026-06-15
- -- 作者: bot_dev1 (基于 Issue #18 任务)
-
- -- ========= 系统初始化数据 =========
-
- -- 部门数据
- INSERT INTO sys_dept (id, parent_id, dept_name, dept_type, sort_order, status) VALUES
- (1, 0, 'XX市水利局', 'water_bureau', 1, 1),
- (2, 1, 'XX市水务集团', 'water_company', 1, 1),
- (3, 2, '供水营业部', 'water_company', 1, 1),
- (4, 2, '管网运维部', 'water_company', 2, 1),
- (5, 2, '水质监测部', 'water_company', 3, 1),
- (6, 2, '客户服务中心', 'water_company', 4, 1),
- (7, 4, '精芒片区运维组', 'ops', 1, 1),
- (8, 4, '托里片区运维组', 'ops', 2, 1),
- (9, 4, '一体化水厂运维组', 'ops', 3, 1);
-
- -- 角色数据
- INSERT INTO sys_role (id, role_name, role_key, data_scope, description) VALUES
- (1, '系统管理员', 'admin', 'ALL', '系统最高权限,可管理所有功能'),
- (2, '领导干部', 'leader', 'ALL', '分管领导,可查看全局数据'),
- (3, '部门经理', 'manager', 'DEPT', '部门负责人,管理本部门业务'),
- (4, '业务操作员', 'operator', 'DEPT', '日常业务操作人员'),
- (5, '技术维护', 'tech', 'DEPT', '系统维护和故障处理');
-
- -- 用户数据(admin用户)
- INSERT INTO sys_user (id, dept_id, username, password, real_name, role_type, status) VALUES
- (1, 1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', '系统管理员', 'admin', 1);
-
- -- admin用户密码:123456 (MD5加密)
-
- -- 菜单数据(管理员菜单)
- INSERT INTO sys_menu (id, parent_id, menu_name, menu_key, menu_type, path, component, perms, icon, sort_order, visible, status) VALUES
- (1, 0, '系统管理', 'system', 'directory', '/system', NULL, NULL, 'setting', 1, 1, 1),
- (2, 1, '用户管理', 'user', 'menu', '/system/user', 'system/user/index', 'system:user:list', 'user', 1, 1, 1),
- (3, 1, '角色管理', 'role', 'menu', '/system/role', 'system/role/index', 'system:role:list', 'team', 2, 1, 1),
- (4, 1, '菜单管理', 'menu', 'menu', '/system/menu', 'system/menu/index', 'system:menu:list', 'tree', 3, 1, 1),
- (5, 1, '部门管理', 'dept', 'menu', '/system/dept', 'system/dept/index', 'system:dept:list', 'building', 4, 1, 1),
- (6, 1, '操作日志', 'log', 'menu', '/system/log', 'system/log/index', 'system:log:list', 'log', 5, 1, 1),
- (7, 0, '物联网平台', 'iot', 'directory', '/iot', NULL, NULL, 'sensor', 10, 1, 1),
- (8, 7, '设备管理', 'device', 'menu', '/iot/device', 'iot/device/index', 'iot:device:list', 'monitor', 1, 1, 1),
- (9, 7, '设备模型', 'device-model', 'menu', '/iot/device-model', 'iot/device-model/index', 'iot:device-model:list', 'model', 2, 1, 1),
- (10, 7, '数据接入', 'data-adapter', 'menu', '/iot/data-adapter', 'iot/data-adapter/index', 'iot:data-adapter:list', 'upload', 3, 1, 1),
- (11, 0, '营业收费', 'revenue', 'directory', '/revenue', NULL, NULL, 'money', 20, 1, 1),
- (12, 11, '客户管理', 'customer', 'menu', '/revenue/customer', 'revenue/customer/index', 'revenue:customer:list', 'people', 1, 1, 1),
- (13, 11, '水表管理', 'meter', 'menu', '/revenue/meter', 'revenue/meter/index', 'revenue:meter:list', 'meter', 2, 1, 1),
- (14, 11, '抄表管理', 'reading', 'menu', '/revenue/reading', 'revenue/reading/index', 'revenue:reading:list', 'file-search', 3, 1, 1),
- (15, 11, '账单管理', 'bill', 'menu', '/revenue/bill', 'revenue/bill/index', 'revenue:bill:list', 'file-text', 4, 1, 1),
- (16, 11, '收费管理', 'payment', 'menu', '/revenue/payment', 'revenue/payment/index', 'revenue:payment:list', 'pay-circle', 5, 1, 1),
- (17, 0, '巡检系统', 'patrol', 'directory', '/patrol', NULL, NULL, 'truck', 30, 1, 1),
- (18, 17, '路线管理', 'route', 'menu', '/patrol/route', 'patrol/route/index', 'patrol:route:list', 'route', 1, 1, 1),
- (19, 17, '任务管理', 'task', 'menu', '/patrol/task', 'patrol/task/index', 'patrol:task:list', 'calendar', 2, 1, 1),
- (20, 17, '巡检记录', 'record', 'menu', '/patrol/record', 'patrol/record/index', 'patrol:record:list', 'checklist', 3, 1, 1),
- (21, 0, '报警管理', 'alert', 'directory', '/alert', NULL, NULL, 'warning', 40, 1, 1),
- (22, 21, '报警规则', 'rule', 'menu', '/alert/rule', 'alert/rule/index', 'alert:rule:list', 'rule', 1, 1, 1),
- (23, 21, '报警事件', 'event', 'menu', '/alert/event', 'alert/event/index', 'alert:event:list', 'exception', 2, 1, 1),
- (24, 21, '报警处理', 'handle', 'menu', '/alert/handle', 'alert/handle/index', 'alert:handle:list', 'service', 3, 1, 1),
- (25, 0, '数据引擎', 'data-engine', 'directory', '/data-engine', NULL, NULL, 'database', 50, 1, 1),
- (26, 25, '数据治理', 'governance', 'menu', '/data-engine/governance', 'data-engine/governance/index', 'data:governance:list', 'filter', 1, 1, 1),
- (27, 25, '数据服务', 'service', 'menu', '/data-engine/service', 'data-engine/service/index', 'data:service:list', 'api', 2, 1, 1),
- (28, 25, '数据目录', 'catalog', 'menu', '/data-engine/catalog', 'data-engine/catalog/index', 'data:catalog:list', 'folder', 3, 1, 1),
- (29, 0, '供水生产', 'production', 'directory', '/production', NULL, NULL, 'water', 60, 1, 1),
- (30, 29, '总览监测', 'overview', 'menu', '/production/overview', 'production/overview/index', 'production:overview:list', 'dashboard', 1, 1, 1),
- (31, 29, '水质管理', 'water-quality', 'menu', '/production/water-quality', 'production/water-quality/index', 'production:water-quality:list', 'science', 2, 1, 1),
- (32, 29, '调度管理', 'dispatch', 'menu', '/production/dispatch', 'production/dispatch/index', 'production:dispatch:list', 'schedule', 3, 1, 1),
- (33, 29, '报警中心', 'monitor', 'menu', '/production/monitor', 'production/monitor/index', 'production:monitor:list', 'radar', 4, 1, 1);
-
- -- 分配管理员角色和菜单
- INSERT INTO sys_user_role (user_id, role_id) VALUES (1, 1);
-
- INSERT INTO sys_role_menu (role_id, menu_id)
- SELECT 1, id FROM sys_menu WHERE status = 1;
-
- -- 分配用户角色(admin)
- INSERT INTO sys_user_role (user_id, role_id) VALUES (1, 1);
-
- -- ========= 物联网平台初始化数据 =========
-
- -- 设备模型定义
- INSERT INTO iot_device_model (id, model_key, model_name, vendor, protocol, properties, commands) VALUES
- (1, 'water_meter_dn15', 'DN15远传水表', 'XX水表厂', 'MQTT',
- '[
- {"key": "flow_rate", "name": "瞬时流量", "unit": "m³/h", "data_type": "double", "range": "0-10"},
- {"key": "total_flow", "name": "累计流量", "unit": "m³", "data_type": "double", "range": "0-999999"},
- {"key": "battery", "name": "电池电压", "unit": "V", "data_type": "double", "range": "2.8-3.6"},
- {"key": "signal", "name": "信号强度", "unit": "dBm", "data_type": "int", "range": "-120 to -30"}
- ]',
- '[
- {"key": "reset", "name": "复位", "params": []},
- {"key": "read_config", "name": "读取配置", "params": []}
- ]'),
- (2, 'pressure_sensor', '压力传感器', 'XX传感器厂', 'Modbus',
- '[
- {"key": "pressure", "name": "压力值", "unit": "MPa", "data_type": "double", "range": "0-1"},
- {"key": "temperature", "name": "温度", "unit": "°C", "data_type": "double", "range": "-20 to 80"},
- {"key": "voltage", "name": "供电电压", "unit": "V", "data_type": "double", "range": "12-24"}
- ]',
- '[
- {"key": "calibrate", "name": "校准", "params": [{"name": "pressure", "type": "double"}]}
- ]'),
- (3, 'water_quality_sensor', '水质分析仪', 'XX环保仪器厂', 'HTTP',
- '[
- {"key": "turbidity", "name": "浊度", "unit": "NTU", "data_type": "double", "range": "0-1000"},
- {"key": "ph", "name": "pH值", "unit": "", "data_type": "double", "range": "0-14"},
- {"key": "conductivity", "name": "电导率", "unit": "μS/cm", "data_type": "double", "range": "0-10000"},
- {"key": "chlorine", "name": "余氯", "unit": "mg/L", "data_type": "double", "range": "0-5"}
- ]',
- '[
- {"key": "calibrate_ph", "name": "pH校准", "params": [{"name": "standard", "type": "double"}]},
- {"key": "start_test", "name": "开始测试", "params": []}
- ]'),
- (4, 'level_sensor', '液位传感器', 'XX传感器厂', 'CoAP',
- '[
- {"key": "water_level", "name": "液位", "unit": "m", "data_type": "double", "range": "0-10"},
- {"key": "temperature", "name": "水温", "unit": "°C", "data_type": "double", "range": "0-50"}
- ]',
- '[
- {"key": "calibrate_zero", "name": "零点校准", "params": []}
- ]'),
- (5, 'valve_controller', '电动阀门控制器', 'XX自控设备厂', 'MQTT',
- '[
- {"key": "valve_position", "name": "阀门开度", "unit": "%", "data_type": "int", "range": "0-100"},
- {"key": "motor_current", "name": "电机电流", "unit": "A", "data_type": "double", "range": "0-10"},
- {"key": "status", "name": "状态", "data_type": "string", "range": "open/closing/closed/fault"}
- ]',
- '[
- {"key": "open", "name": "打开", "params": []},
- {"key": "close", "name": "关闭", "params": []},
- {"key": "stop", "name": "停止", "params": []}
- ]');
-
- -- 示例设备实例
- INSERT INTO iot_device (id, device_sn, device_name, model_id, device_type, position_type, loc_lng, loc_lat, area, station_id, status) VALUES
- (1, 'JM20260001', '精芒片区-001号水表', 1, 'flow_meter', 'village', 116.123456, 39.987654, '精芒片区', 'jm001', 'online'),
- (2, 'JM20260002', '精芒片区-002号水表', 1, 'flow_meter', 'village', 116.123789, 39.987721, '精芒片区', 'jm001', 'online'),
- (3, 'TL20260001', '托里片区-001号压力表', 2, 'pressure_sensor', 'pressure_station', 116.124123, 39.988456, '托里片区', 'tl001', 'online'),
- (4, 'TL20260002', '托里片区-002号压力表', 2, 'pressure_sensor', 'pressure_station', 116.124654, 39.988887, '托里片区', 'tl001', 'online'),
- (5, 'YT20260001', '一体化水厂-入口水质监测', 3, 'water_quality', 'water_plant', 116.125987, 39.990123, '一体化水厂', 'yt001', 'online'),
- (6, 'YT20260002', '一体化水厂-出口水质监测', 3, 'water_quality', 'water_plant', 116.126234, 39.990456, '一体化水厂', 'yt001', 'online'),
- (7, 'JM20260003', '精芒片区-1号水池液位', 4, 'level_sensor', 'water_plant', 116.123234, 39.987890, '精芒片区', 'jm002', 'online'),
- (8, 'TL20260003', '托里片区-1号阀门', 5, 'valve_controller', 'pipe_network', 116.124876, 39.988234, '托里片区', 'pn001', 'online');
-
- -- 空间坐标更新(为示例设备添加PostGIS坐标)
- UPDATE iot_device
- SET geom = ST_MakePoint(116.123456, 39.987654)
- WHERE device_sn = 'JM20260001';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.123789, 39.987721)
- WHERE device_sn = 'JM20260002';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.124123, 39.988456)
- WHERE device_sn = 'TL20260001';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.124654, 39.988887)
- WHERE device_sn = 'TL20260002';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.125987, 39.990123)
- WHERE device_sn = 'YT20260001';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.126234, 39.990456)
- WHERE device_sn = 'YT20260002';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.123234, 39.987890)
- WHERE device_sn = 'JM20260003';
-
- UPDATE iot_device
- SET geom = ST_MakePoint(116.124876, 39.988234)
- WHERE device_sn = 'TL20260003';
-
- -- ========= 营业收费初始化数据 =========
-
- -- 水费标准
- INSERT INTO rev_water_rate (id, rate_name, customer_type, step_threshold, step_rates, start_date, end_date, status) VALUES
- (1, '居民阶梯水价', 'residential',
- '[{"threshold": 0, "step": 1}, {"threshold": 12, "step": 2}, {"threshold": 24, "step": 3}]',
- '[{"rate": 2.5}, {"rate": 3.5}, {"rate": 5.0}]',
- '2026-01-01', '2026-12-31', 1),
- (2, '非居民水价', 'business',
- '[{"threshold": 0, "step": 1}]',
- '[{"rate": 3.8}]',
- '2026-01-01', '2026-12-31', 1);
-
- -- 示例客户数据
- INSERT INTO rev_customer (id, customer_no, customer_name, customer_type, area, address, phone, id_card, contract_no, status) VALUES
- (1, 'R20260001', '张三', 'residential', '精芒片区', 'XX市XX区精芒街道001号', '13800138001', '110101199001011234', 'CT20260001', 'active'),
- (2, 'R20260002', '李四', 'residential', '精芒片区', 'XX市XX区精芒街道002号', '13800138002', '110101199002022345', 'CT20260002', 'active'),
- (3, 'B20260001', 'XX超市', 'business', '托里片区', 'XX市XX区托里商圈001号', '13800138003', NULL, 'CT20260003', 'active'),
- (4, 'B20260002', 'XX酒店', 'business', '托里片区', 'XX市XX区托里商圈002号', '13800138004', NULL, 'CT20260004', 'active');
-
- -- 示例水表数据
- INSERT INTO rev_meter (id, meter_no, customer_id, device_id, caliber, meter_type, initial_reading, install_date, status) VALUES
- (1, 'M20260001', 1, 1, 'DN15', 'mechanical', 0.00, '2026-01-01', 'active'),
- (2, 'M20260002', 2, 2, 'DN15', 'mechanical', 0.00, '2026-01-01', 'active'),
- (3, 'M20260003', 3, 3, 'DN20', 'ultrasonic', 0.00, '2026-01-01', 'active'),
- (4, 'M20260004', 4, 4, 'DN20', 'ultrasonic', 0.00, '2026-01-01', 'active');
-
- -- ========= 巡检系统初始化数据 =========
-
- -- 巡检标准
- INSERT INTO patrol_standard (id, standard_name, device_type, check_items, scoring_rules) VALUES
- (1, '水表巡检标准', 'flow_meter',
- '[
- {"item": "表体完整性", "required": true, "weight": 10},
- {"item": "指示器读数清晰", "required": true, "weight": 10},
- {"item": "管道连接牢固", "required": true, "weight": 15},
- {"item": "无漏水现象", "required": true, "weight": 25},
- {"item": "防护设施完好", "required": true, "weight": 20},
- {"item": "周围环境整洁", "required": false, "weight": 5}
- ]',
- '[
- {"pass": "评分>=80分", "weight": 100},
- {"warning": "评分60-79分", "weight": 80},
- {"fail": "评分<60分", "weight": 60}
- ]'),
- (2, '压力传感器巡检标准', 'pressure_sensor',
- '[
- {"item": "表体完整性", "required": true, "weight": 15},
- {"item": "显示读数正常", "required": true, "weight": 20},
- {"item": "连接管路牢固", "required": true, "weight": 15},
- {"item": "无泄漏现象", "required": true, "weight": 25},
- {"item": "安装固定牢固", "required": true, "weight": 15},
- {"item": "供电正常", "required": true, "weight": 10}
- ]',
- '[
- {"pass": "评分>=85分", "weight": 100},
- {"warning": "评分70-84分", "weight": 80},
- {"fail": "评分<70分", "weight": 60}
- ]');
-
- -- 示例巡检路线
- INSERT INTO patrol_route (id, route_name, area, route_points, estim_duration, status) VALUES
- (1, '精芒片区日巡检路线', '精芒片区',
- '[
- {"seq": 1, "lng": 116.123456, "lat": 39.987654, "name": "JM001水表", "device_ids": [1]},
- {"seq": 2, "lng": 116.123789, "lat": 39.987721, "name": "JM002水表", "device_ids": [2]},
- {"seq": 3, "lng": 116.123234, "lat": 39.987890, "name": "JM001水池", "device_ids": [7]},
- {"seq": 4, "lng": 116.123890, "lat": 39.987945, "name": "管网检查点1", "device_ids": []}
- ]',
- 120, 1),
- (2, '托里片区日巡检路线', '托里片区',
- '[
- {"seq": 1, "lng": 116.124123, "lat": 39.988456, "name": "TL001压力站", "device_ids": [3]},
- {"seq": 2, "lng": 116.124654, "lat": 39.988887, "name": "TL002压力站", "device_ids": [4]},
- {"seq": 3, "lng": 116.124876, "lat": 39.988234, "name": "TL001阀门", "device_ids": [8]},
- {"seq": 4, "lng": 116.124234, "lat": 39.988567, "name": "管网检查点2", "device_ids": []}
- ]',
- 90, 1);
-
- -- ========= 报警管理初始化数据 =========
-
- -- 报警规则
- INSERT INTO alert_rule (id, rule_name, device_type, metric_key, alert_level, condition_expr, threshold_value, debounce_sec, notify_scheme_id, enabled) VALUES
- (1, '流量异常报警', 'flow_meter', 'flow_rate', 'warning', '> 10', '10.0', 300, 1, 1),
- (2, '压力过高报警', 'pressure_sensor', 'pressure', 'critical', '> 0.8', '0.8', 300, 1, 1),
- (3, '压力过低报警', 'pressure_sensor', 'pressure', 'warning', '< 0.1', '0.1', 300, 1, 1),
- (4, '水质浊度报警', 'water_quality_sensor', 'turbidity', 'emergency', '> 10', '10.0', 300, 1, 1),
- (5, '电池电量低报警', 'flow_meter', 'battery', 'info', '< 2.8', '2.8', 3600, 1, 1),
- (6, '设备离线报警', 'flow_meter', 'signal', 'critical', '< -100', '-100', 1800, 1, 1);
-
- -- 通知方案
- INSERT INTO alert_notify_scheme (id, scheme_name, channels, recipients, conditions, status) VALUES
- (1, '标准报警通知',
- '{
- "sms": true,
- "push": true,
- "websocket": true,
- "email": false
- }',
- '{
- "roles": ["operator", "manager"],
- "departments": [4, 7, 8, 9]
- }',
- '{
- "levels": ["info", "warning", "critical", "emergency"],
- "device_types": ["flow_meter", "pressure_sensor", "water_quality_sensor"]
- }', 1),
- (2, '紧急报警通知',
- '{
- "sms": true,
- "push": true,
- "websocket": true,
- "email": true
- }',
- '{
- "roles": ["admin", "leader", "manager"],
- "departments": [1, 2]
- }',
- '{
- "levels": ["critical", "emergency"],
- "device_types": ["water_quality_sensor"]
- }', 1);
-
- -- ========= 系统配置初始化数据 =========
-
- -- 系统参数配置
- INSERT INTO sys_config (id, config_key, config_name, config_value, config_type, description) VALUES
- (1, 'system.name', '系统名称', '智慧水务管理系统', 'string', '系统显示名称'),
- (2, 'system.version', '系统版本', '1.0.0', 'string', '当前系统版本'),
- (3, 'iot.mqtt.broker', 'MQTT服务器地址', 'mqtt://localhost:1883', 'string', 'MQTT消息服务器地址'),
- (4, 'iot.mqtt.username', 'MQTT用户名', 'water_mgt', 'string', 'MQTT认证用户名'),
- (5, 'iot.mqtt.password', 'MQTT密码', 'water_mgt_2026', 'string', 'MQTT认证密码'),
- (6, 'database.tdengine.host', 'TDengine主机地址', 'localhost', 'string', 'TDengine数据库主机'),
- (7, 'database.tdengine.port', 'TDengine端口', '6030', 'string', 'TDengine数据库端口'),
- (8, 'database.tdengine.user', 'TDengine用户名', 'root', 'string', 'TDengine数据库用户名'),
- (9, 'database.tdengine.password', 'TDengine密码', 'taosdata', 'string', 'TDengine数据库密码'),
- (10, 'notification.sms.provider', '短信服务商', 'aliyun', 'string', '短信服务提供商'),
- (11, 'notification.sms.access_key', '短信AccessKey', '', 'string', '短信服务AccessKey'),
- (12, 'notification.sms.secret_key', '短信SecretKey', '', 'string', '短信服务SecretKey'),
- (13, 'notification.push.provider', '推送服务商', 'jiguang', 'string', '推送服务提供商'),
- (14, 'notification.push.app_key', '推送AppKey', '', 'string', '推送服务AppKey'),
- (15, 'notification.push.master_secret', '推送MasterSecret', '', 'string', '推送服务MasterSecret');
-
- -- 数据字典
- INSERT INTO sys_dict (dict_type, dict_code, dict_label, dict_value, sort_order, status) VALUES
- -- 用户状态字典
- ('user_status', 'active', '正常', 'active', 1, 1),
- ('user_status', 'locked', '锁定', 'locked', 2, 1),
- ('user_status', 'disabled', '禁用', 'disabled', 3, 1),
- -- 设备状态字典
- ('device_status', 'online', '在线', 'online', 1, 1),
- ('device_status', 'offline', '离线', 'offline', 2, 1),
- ('device_status', 'maintenance', '维护中', 'maintenance', 3, 1),
- ('device_status', 'fault', '故障', 'fault', 4, 1),
- -- 报警等级字典
- ('alert_level', 'info', '提示', 'info', 1, 1),
- ('alert_level', 'warning', '警告', 'warning', 2, 1),
- ('alert_level', 'critical', '严重', 'critical', 3, 1),
- ('alert_level', 'emergency', '紧急', 'emergency', 4, 1),
- -- 客户类型字典
- ('customer_type', 'residential', '居民用户', 'residential', 1, 1),
- ('customer_type', 'business', '商业用户', 'business', 2, 1),
- ('customer_type', 'enterprise', '企业用户', 'enterprise', 3, 1),
- ('customer_type', 'institution', '机关单位', 'institution', 4, 1),
- -- 水表类型字典
- ('meter_type', 'mechanical', '机械水表', 'mechanical', 1, 1),
- ('meter_type', 'ultrasonic', '超声波水表', 'ultrasonic', 2, 1),
- ('meter_type', 'electromagnetic', '电磁水表', 'electromagnetic', 3, 1),
- ('meter_type', 'ic_card', 'IC卡水表', 'ic_card', 4, 1),
- -- 抄表类型字典
- ('read_type', 'manual', '人工抄表', 'manual', 1, 1),
- ('read_type', 'remote', '远程抄表', 'remote', 2, 1),
- ('read_type', 'estimate', '估抄', 'estimate', 3, 1);
-
- -- ========= Flyway/Liquibase 配置信息 =========
- -- 创建 Flyway 配置表
- CREATE TABLE IF NOT EXISTS flyway_schema_history (
- installed_rank INT NOT NULL,
- version VARCHAR(50) NOT NULL,
- description VARCHAR(200) NOT NULL,
- type VARCHAR(20) NOT NULL,
- script VARCHAR(1000) NOT NULL,
- checksum INT,
- installed_by VARCHAR(100) NOT NULL,
- installed_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
- execution_time INT NOT NULL,
- success TINYINT NOT NULL
- );
-
- -- 插入 Flyway 迁移记录
- INSERT INTO flyway_schema_history (installed_rank, version, description, type, script, checksum, installed_by, execution_time, success)
- VALUES (1, '1', '初始化数据库脚本', 'SQL', 'V1__init.sql', NULL, 'admin', 0, 1);
-
- -- 创建 Liquibase 配置表(可选)
- CREATE TABLE IF NOT EXISTS databasechangelog (
- id VARCHAR(255) NOT NULL,
- author VARCHAR(255) NOT NULL,
- filename VARCHAR(255) NOT NULL,
- dateexecuted TIMESTAMP NOT NULL,
- orderexecuted INT NOT NULL,
- exectype VARCHAR(10) NOT NULL,
- md5sum VARCHAR(35),
- description VARCHAR(255),
- comments VARCHAR(255),
- tag VARCHAR(255),
- liquibase VARCHAR(20),
- contexts VARCHAR(255),
- labels VARCHAR(255),
- deployment_id VARCHAR(10)
- );
-
- -- 创建数据库配置文件模板
- -- 在应用启动时,以下配置文件应该被创建:
- -- - /config/application.yml (Spring Boot 配置)
- -- - /config/flyway.conf (Flyway 配置)
- -- - /config/liquibase.properties (Liquibase 配置)
-
- -- 配置文件内容示例
- /*
- # application.yml 配置示例
- spring:
- datasource:
- url: jdbc:postgresql://localhost:5432/water_mgt
- username: postgres
- password: postgres
- driver-class-name: org.postgresql.Driver
- hikari:
- maximum-pool-size: 20
- minimum-idle: 5
- idle-timeout: 300000
- connection-timeout: 20000
- connection-test-query: SELECT 1
-
- flyway:
- enabled: true
- locations: classpath:db/postgresql
- baseline-on-migrate: true
- baseline-version: 1
-
- # TDengine 配置
- tdengine:
- host: localhost
- port: 6030
- username: root
- password: taosdata
- database: water_mgt
-
- # Redis 配置
- spring:
- redis:
- host: localhost
- port: 6379
- password:
- database: 0
- */
-
- -- ========= 初始化完成 =========
- -- 数据库初始化脚本执行完成
- -- 创建时间: 2026-06-15
- -- 执行用户: bot_dev1
- -- 创建了完整的 PostgreSQL + TDengine 数据库结构
- -- 包含用户权限体系、物联网设备管理、营业收费、巡检系统、报警管理等模块
- -- 支持空间数据(PostGIS)和时序数据(TDengine)的存储和管理
|