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

init_data.sql 4.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. -- 阈值表
  2. CREATE TABLE IF NOT EXISTS threshold (
  3. id BIGSERIAL PRIMARY KEY,
  4. device_id VARCHAR(100) NOT NULL,
  5. device_type VARCHAR(50),
  6. region VARCHAR(50),
  7. parameter VARCHAR(100) NOT NULL,
  8. min_value DOUBLE PRECISION,
  9. max_value DOUBLE PRECISION,
  10. warning_min DOUBLE PRECISION,
  11. warning_max DOUBLE PRECISION,
  12. unit VARCHAR(20),
  13. description TEXT,
  14. status INTEGER DEFAULT 1 COMMENT '1-启用,0-禁用',
  15. create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  16. update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  17. );
  18. -- 信息发布表
  19. CREATE TABLE IF NOT EXISTS notification (
  20. id BIGSERIAL PRIMARY KEY,
  21. title VARCHAR(200) NOT NULL,
  22. content TEXT NOT NULL,
  23. type VARCHAR(20) NOT NULL COMMENT 'forecast-预报,warning-预警,info-通知',
  24. region VARCHAR(50),
  25. priority VARCHAR(20) DEFAULT 'medium' COMMENT 'high-高,medium-中,low-低',
  26. status INTEGER DEFAULT 1 COMMENT '1-草稿,2-已发布,3-已归档',
  27. publisher VARCHAR(100),
  28. publish_time TIMESTAMP,
  29. create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  30. update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  31. );
  32. -- 设备表
  33. CREATE TABLE IF NOT EXISTS equipment (
  34. id BIGSERIAL PRIMARY KEY,
  35. device_name VARCHAR(100) NOT NULL,
  36. device_type VARCHAR(50),
  37. model VARCHAR(100),
  38. serial_number VARCHAR(100),
  39. region VARCHAR(50),
  40. location TEXT,
  41. status VARCHAR(20) DEFAULT 'offline' COMMENT 'online-在线,offline-离线,maintenance-维护中,fault-故障',
  42. manufacturer VARCHAR(100),
  43. installation_date DATE,
  44. last_maintenance_date DATE,
  45. next_maintenance_date DATE,
  46. latitude DOUBLE PRECISION,
  47. longitude DOUBLE PRECISION,
  48. create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  49. update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
  50. );
  51. -- 创建索引
  52. CREATE INDEX IF NOT EXISTS idx_threshold_device_id ON threshold(device_id);
  53. CREATE INDEX IF NOT EXISTS idx_threshold_region ON threshold(region);
  54. CREATE INDEX IF NOT EXISTS idx_threshold_parameter ON threshold(parameter);
  55. CREATE INDEX IF NOT EXISTS idx_notification_region ON notification(region);
  56. CREATE INDEX IF NOT EXISTS idx_notification_type ON notification(type);
  57. CREATE INDEX IF NOT EXISTS idx_notification_status ON notification(status);
  58. CREATE INDEX IF NOT EXISTS idx_equipment_device_name ON equipment(device_name);
  59. CREATE INDEX IF NOT EXISTS idx_equipment_device_type ON equipment(device_type);
  60. CREATE INDEX IF NOT EXISTS idx_equipment_region ON equipment(region);
  61. CREATE INDEX IF NOT EXISTS idx_equipment_status ON equipment(status);
  62. -- 插入示例数据
  63. -- 阈值示例
  64. INSERT INTO threshold (device_id, device_type, region, parameter, min_value, max_value, warning_min, warning_max, unit, description, status) VALUES
  65. ('DEV001', 'pressure_sensor', '精河县', 'water_pressure', 0.2, 0.8, 0.15, 0.85, 'MPa', '供水压力阈值', 1),
  66. ('DEV002', 'flow_meter', '精河县', 'water_flow', 10, 100, 8, 110, 'm³/h', '水流流量阈值', 1),
  67. ('DEV003', 'quality_sensor', '精河县', 'water_quality', 0, 1, 0.1, 0.9, 'pH', '水质pH值阈值', 1);
  68. -- 设备示例
  69. INSERT INTO equipment (device_name, device_type, model, serial_number, region, location, status, manufacturer, installation_date) VALUES
  70. ('压力传感器001', 'pressure_sensor', 'PS-3000', 'SN0012023001', '精河县', '供水站A区', 'online', '华为', '2023-01-15'),
  71. ('流量计001', 'flow_meter', 'FM-5000', 'SN0012023002', '精河县', '供水站B区', 'online', '西门子', '2023-02-20'),
  72. ('水质检测仪001', 'quality_sensor', 'QS-2000', 'SN0012023003', '精河县', '供水站C区', 'online', '霍尼韦尔', '2023-03-10');
  73. -- 信息发布示例
  74. INSERT INTO notification (title, content, type, region, priority, status, publisher, publish_time) VALUES
  75. ('停水通知', '因设备维护,预计明天9:00-12:00精河县部分区域将暂停供水', 'warning', '精河县', 'high', 2, 'system_admin', '2026-06-14T08:00:00'),
  76. ('水质提升通知', '本季度已完成水质净化设备升级,水质显著提升', 'info', '精河县', 'medium', 2, 'water_quality_team', '2026-06-01T10:00:00'),
  77. ('雨季供水保障通知', '近期降雨较多,各水厂已加强巡检,确保供水稳定', 'forecast', '精河县', 'low', 2, 'emergency_team', '2026-05-20T14:00:00');