fastbee/sql/init_threshold_with_table.sql
2026-09-10 21:00:05 +08:00

77 lines
5.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================================
-- 报告阈值表创建 + 行业标准默认值初始化
-- 数据库:fastbee
-- 执行方式:mysql -u root -p fastbee < sql/init_threshold_with_table.sql
-- ============================================================
-- 1. 创建阈值表
CREATE TABLE IF NOT EXISTS iot_report_threshold (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
product_id BIGINT NOT NULL DEFAULT 0 COMMENT '产品ID(0=全局默认)',
device_id BIGINT NOT NULL DEFAULT 0 COMMENT '设备ID(0=不限定设备)',
monitor_category_code VARCHAR(50) COMMENT '监测分类编码',
metric_identifier VARCHAR(100) NOT NULL COMMENT '物模型标识符',
warning_value DECIMAL(10,4) COMMENT '预警值',
alarm_value DECIMAL(10,4) COMMENT '报警值',
control_value DECIMAL(10,4) COMMENT '控制值',
unit VARCHAR(20) COMMENT '单位',
create_by VARCHAR(64) COMMENT '创建者',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
update_by VARCHAR(64) COMMENT '更新者',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_product_device (product_id, device_id),
INDEX idx_metric_identifier (metric_identifier)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='报告结构化阈值表';
-- 2. 初始化行业标准默认阈值(product_id=0 全局默认)
-- 来源:JGJ 8-2016《建筑变形测量规范》、GB 50497-2019《建筑基坑工程监测标准》
-- 深部位移:累计位移控制值 30-100mm,速率预警值 2mm/d
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'DEEP_DISPLACEMENT', 'displacement', 20.00, 30.00, 50.00, 'mm', 'admin', NOW());
-- 静力水准:累计沉降控制值 20-60mm,速率预警值 2mm/d
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'STATIC_LEVEL', 'settlement', 15.00, 25.00, 40.00, 'mm', 'admin', NOW());
-- 裂缝计:裂缝宽度控制值 0.3-1.0mm,变化量预警值 0.2mm
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'CRACK_METER', 'crack_width', 0.30, 0.50, 1.00, 'mm', 'admin', NOW());
-- 测距仪:收敛变形控制值 20-50mm
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'RANGING_METER', 'distance', 15.00, 25.00, 40.00, 'mm', 'admin', NOW());
-- 倾角计:倾斜角度控制值 1°-3°
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'INCLINOMETER', 'inclination', 1.00, 2.00, 3.00, '°', 'admin', NOW());
-- 水位计:水位变化控制值 0.5-2.0m
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'WATER_LEVEL', 'water_level', 0.50, 1.00, 2.00, 'm', 'admin', NOW());
-- 应变计:应变控制值 ±1000με
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'STRAIN_GAUGE', 'strain', 500.00, 800.00, 1000.00, 'με', 'admin', NOW());
-- 振弦式传感器:频率变化控制值 ±50Hz
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'VIBRATING_WIRE', 'frequency', 30.00, 40.00, 50.00, 'Hz', 'admin', NOW());
-- 温度计:温度变化控制值 ±15℃
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'THERMOMETER', 'temperature', 10.00, 15.00, 20.00, '℃', 'admin', NOW());
-- 雨量计:累计降雨量预警值 50mm/d
INSERT INTO iot_report_threshold (product_id, device_id, monitor_category_code, metric_identifier, warning_value, alarm_value, control_value, unit, create_by, create_time)
VALUES (0, 0, 'RAIN_GAUGE', 'rainfall', 25.00, 50.00, 100.00, 'mm', 'admin', NOW());
-- ============================================================
-- 重要说明:
-- 1. metric_identifier 需与产品物模型的标识符匹配
-- 如果物模型标识符不同,请修改 UPDATE 语句更新对应记录
-- 示例:UPDATE iot_report_threshold SET metric_identifier='X_axis_displacement' WHERE monitor_category_code='DEEP_DISPLACEMENT';
-- 2. 预警值 < 报警值 < 控制值,系统会按当前值与阈值的比较自动判断安全等级
-- 3. 如需针对特定产品配置阈值,复制以上记录并修改 product_id
-- 4. 如需针对特定设备配置阈值,复制以上记录并修改 device_id
-- ============================================================