|
|
@@ -218,196 +218,36 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
String deviceId = resultData.getMacAddress();
|
|
|
boolean hasAlarm = false;
|
|
|
|
|
|
- //获取温度阈值
|
|
|
- String temWarningCode = "WARN-GAS-TEMPERATURE";
|
|
|
- WarningThreshold temThreshold = checkThreshold(deviceId, temWarningCode);
|
|
|
- Double temMinValue = temThreshold != null ? temThreshold.getMinValue() : null;
|
|
|
- Double temMaxValue = temThreshold != null ? temThreshold.getMaxValue() : null;
|
|
|
- String temWarningType = temThreshold != null ? temThreshold.getWarningType() : "可燃气体温度预警";
|
|
|
- String temRemark = temThreshold != null ? temThreshold.getRemark() : null;
|
|
|
-
|
|
|
- //获取湿度阈值
|
|
|
- String humWarningCode = "WARN-GAS-HUMIDITY";
|
|
|
- WarningThreshold humThreshold = checkThreshold(deviceId, humWarningCode);
|
|
|
- Double humMinValue = humThreshold != null ? humThreshold.getMinValue() : null;
|
|
|
- Double humMaxValue = humThreshold != null ? humThreshold.getMaxValue() : null;
|
|
|
- String humWarningType = humThreshold != null ? humThreshold.getWarningType() : "湿度预警";
|
|
|
- String humRemark = humThreshold != null ? humThreshold.getRemark() : null;
|
|
|
-
|
|
|
- //获取气体浓度阈值
|
|
|
+ //获取气体浓度阈值(按气体类型只监测浓度,当前仅CH4;且仅按上限判定)
|
|
|
String gasWarningCode = "WARN-GAS-CONCENTRATION";
|
|
|
WarningThreshold gasThreshold = checkThreshold(deviceId, gasWarningCode);
|
|
|
- Double gasMinValue = gasThreshold != null ? gasThreshold.getMinValue() : null;
|
|
|
Double gasMaxValue = gasThreshold != null ? gasThreshold.getMaxValue() : null;
|
|
|
String gasWarningType = gasThreshold != null ? gasThreshold.getWarningType() : "气体浓度预警";
|
|
|
String gasRemark = gasThreshold != null ? gasThreshold.getRemark() : null;
|
|
|
|
|
|
- //判断温度
|
|
|
- float temperature = resultData.getTemperature();
|
|
|
- boolean temperatureIsOverThreshold = false;
|
|
|
- if (temMinValue != null && temperature <= temMinValue) {
|
|
|
- temperatureIsOverThreshold = true;
|
|
|
- }
|
|
|
- if (temMaxValue != null && temperature >= temMaxValue) {
|
|
|
- temperatureIsOverThreshold = true;
|
|
|
- }
|
|
|
- BigDecimal temMinBd = temMinValue != null ? BigDecimal.valueOf(temMinValue) : null;
|
|
|
- BigDecimal temMaxBd = temMaxValue != null ? BigDecimal.valueOf(temMaxValue) : null;
|
|
|
- BigDecimal temActualBd = BigDecimal.valueOf(temperature);
|
|
|
- if (temMinValue != null || temMaxValue != null) {
|
|
|
- if (temperatureIsOverThreshold) {
|
|
|
- int alarmLevel = saveAlarmData(deviceId, temWarningType, temWarningCode,
|
|
|
- temMinBd, temMaxBd, temActualBd, temRemark != null ? temRemark : "可燃气体温度报警");
|
|
|
- earlyWarningAutoService.closeAutoWarning(deviceId, temWarningCode, "已达报警阈值,转报警处理");
|
|
|
- hasAlarm = true;
|
|
|
- if (alarmLevel == 1) {
|
|
|
- sendMessage(deviceId, temWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
- }
|
|
|
- } else {
|
|
|
- earlyWarningAutoService.checkAndGenerate(deviceId, temWarningType, temWarningCode,
|
|
|
- temMinBd, temMaxBd, temActualBd, temRemark);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //判断湿度
|
|
|
- float humidity = resultData.getHumidity();
|
|
|
- boolean humidityIsOverThreshold = false;
|
|
|
- if (humMinValue != null && humidity <= humMinValue) {
|
|
|
- humidityIsOverThreshold = true;
|
|
|
- }
|
|
|
- if (humMaxValue != null && humidity >= humMaxValue) {
|
|
|
- humidityIsOverThreshold = true;
|
|
|
- }
|
|
|
- BigDecimal humMinBd = humMinValue != null ? BigDecimal.valueOf(humMinValue) : null;
|
|
|
- BigDecimal humMaxBd = humMaxValue != null ? BigDecimal.valueOf(humMaxValue) : null;
|
|
|
- BigDecimal humActualBd = BigDecimal.valueOf(humidity);
|
|
|
- if (humMinValue != null || humMaxValue != null) {
|
|
|
- if (humidityIsOverThreshold) {
|
|
|
- int alarmLevel = saveAlarmData(deviceId, humWarningType, humWarningCode,
|
|
|
- humMinBd, humMaxBd, humActualBd, humRemark != null ? humRemark : "可燃气体湿度报警");
|
|
|
- earlyWarningAutoService.closeAutoWarning(deviceId, humWarningCode, "已达报警阈值,转报警处理");
|
|
|
- hasAlarm = true;
|
|
|
- if (alarmLevel == 1) {
|
|
|
- sendMessage(deviceId, humWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
- }
|
|
|
- } else {
|
|
|
- earlyWarningAutoService.checkAndGenerate(deviceId, humWarningType, humWarningCode,
|
|
|
- humMinBd, humMaxBd, humActualBd, humRemark);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //判断气体浓度
|
|
|
+ //判断气体浓度:仅当浓度达到或超过上限时视为越限;浓度低(接近0)属正常,不告警
|
|
|
BigDecimal gasConcentration = resultData.getGasConcentration();
|
|
|
- float actualGasConcentration = gasConcentration != null ? gasConcentration.floatValue() : 0f;
|
|
|
- boolean concentrationIsOverThreshold = false;
|
|
|
- if (gasMinValue != null && actualGasConcentration <= gasMinValue) {
|
|
|
- concentrationIsOverThreshold = true;
|
|
|
- }
|
|
|
- if (gasMaxValue != null && actualGasConcentration >= gasMaxValue) {
|
|
|
- concentrationIsOverThreshold = true;
|
|
|
- }
|
|
|
- BigDecimal gasMinBd = gasMinValue != null ? BigDecimal.valueOf(gasMinValue) : null;
|
|
|
- BigDecimal gasMaxBd = gasMaxValue != null ? BigDecimal.valueOf(gasMaxValue) : null;
|
|
|
- if ((gasMinValue != null || gasMaxValue != null) && gasConcentration != null) {
|
|
|
- if (concentrationIsOverThreshold) {
|
|
|
- int alarmLevel = saveAlarmData(deviceId, gasWarningType, gasWarningCode,
|
|
|
- gasMinBd, gasMaxBd, gasConcentration, gasRemark != null ? gasRemark : "可燃气体浓度报警");
|
|
|
- earlyWarningAutoService.closeAutoWarning(deviceId, gasWarningCode, "已达报警阈值,转报警处理");
|
|
|
- hasAlarm = true;
|
|
|
- if (alarmLevel == 1) {
|
|
|
+ if (gasConcentration != null && gasMaxValue != null) {
|
|
|
+ BigDecimal gasMaxBd = BigDecimal.valueOf(gasMaxValue);
|
|
|
+ if (gasConcentration.floatValue() >= gasMaxValue) {
|
|
|
+ // 越限报警:等级计算以0为下限基线(气体浓度不会低于0),保证仅上限时也能正确分级
|
|
|
+ int alarmLevel = saveAlarmData(deviceId, gasWarningType, gasWarningCode,
|
|
|
+ BigDecimal.ZERO, gasMaxBd, gasConcentration,
|
|
|
+ gasRemark != null ? gasRemark : "可燃气体浓度报警");
|
|
|
+ earlyWarningAutoService.closeAutoWarning(deviceId, gasWarningCode, "已达报警阈值,转报警处理");
|
|
|
+ hasAlarm = true;
|
|
|
+ if (alarmLevel == 1) {
|
|
|
sendMessage(deviceId, gasWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
}
|
|
|
} else {
|
|
|
+ // 未越限:接近上限时生成自动预警(min传null,仅按上限评估预警区)
|
|
|
earlyWarningAutoService.checkAndGenerate(deviceId, gasWarningType, gasWarningCode,
|
|
|
- gasMinBd, gasMaxBd, gasConcentration, gasRemark);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //获取到的数据逐一进行判断
|
|
|
- Map<String, Boolean> alarmBits = resultData.parseAlarmBits();
|
|
|
- if(alarmBits.get("unknownAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "未知报警", "WARN-UNKNOWN", null, "可燃气体未知报警");
|
|
|
- sendMessage(deviceId,"未知报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
+ null, gasMaxBd, gasConcentration, gasRemark);
|
|
|
}
|
|
|
- if(alarmBits.get("highAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "高报警", "WARN-HIGH", null, "可燃气体高报警");
|
|
|
- sendMessage(deviceId,"高报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("overRange")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "超量程", "WARN-OVER-RANGE", null, "可燃气体超量程报警");
|
|
|
- sendMessage(deviceId,"超量程",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("calibrationCycle")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "标定周期", "WARN-CALIBRATION-CYCLE", null, "可燃气体标定周期报警");
|
|
|
- sendMessage(deviceId,"标定周期",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("overLife")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "超寿命", "WARN-OVER-LIFE", null, "可燃气体超寿命报警");
|
|
|
- sendMessage(deviceId,"超寿命",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("fallAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "跌倒报警", "WARN-FALL", null, "可燃气体跌倒报警");
|
|
|
- sendMessage(deviceId,"跌倒报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("undervoltage")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "欠压报警", "WARN-UNDERVOLTAGE", null, "可燃气体欠压报警");
|
|
|
- sendMessage(deviceId,"欠压报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
}
|
|
|
- if(alarmBits.get("rangeAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "区间报警", "WARN-RANGE", null, "可燃气体区间报警");
|
|
|
- sendMessage(deviceId,"区间报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("keyAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "按键报警", "WARN-KEY", null, "可燃气体按键报警");
|
|
|
- sendMessage(deviceId,"按键报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("vibrationAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "震动报警", "WARN-VIBRATION", null, "可燃气体震动报警");
|
|
|
- sendMessage(deviceId,"震动报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("waterLevelAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "水位报警", "WARN-WATER-LEVEL", null, "可燃气体水位报警");
|
|
|
- sendMessage(deviceId,"水位报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("powerOffAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "断电报警", "WARN-POWER-OFF", null, "可燃气体断电报警");
|
|
|
- sendMessage(deviceId,"断电报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("sensorFault")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "传感器故障", "WARN-SENSOR-FAULT", null, "可燃气体传感器故障");
|
|
|
- sendMessage(deviceId,"传感器故障",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("overHumidity")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "超湿报警", "WARN-OVER-HUMIDITY", null, "可燃气体超湿报警");
|
|
|
- sendMessage(deviceId,"超湿报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("overTemperature")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "超温报警", "WARN-OVER-TEMPERATURE", null, "可燃气体超温报警");
|
|
|
- sendMessage(deviceId,"超温报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
- if(alarmBits.get("systemFault")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "系统故障", "WARN-SYSTEM-FAULT", null, "可燃气体系统故障");
|
|
|
- sendMessage(deviceId,"系统故障",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- hasAlarm = true;
|
|
|
- }
|
|
|
|
|
|
- return hasAlarm;
|
|
|
- }
|
|
|
+ return hasAlarm;
|
|
|
+ }
|
|
|
|
|
|
private WarningThreshold checkThreshold(String deviceCode, String warningCode) {
|
|
|
try {
|
|
|
@@ -452,26 +292,6 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
return alarmLevel;
|
|
|
}
|
|
|
-
|
|
|
- private void saveAlarmDataLevelOne(String deviceCode, String warningType, String warningCode,
|
|
|
- BigDecimal actualValue, String remark) {
|
|
|
- try {
|
|
|
- AlarmData alarmData = new AlarmData();
|
|
|
- alarmData.setDeviceCode(deviceCode);
|
|
|
- alarmData.setWarningType(warningType);
|
|
|
- alarmData.setWarningCode(warningCode);
|
|
|
- alarmData.setActualValue(actualValue);
|
|
|
- alarmData.setAlarmLevel(1);
|
|
|
- alarmData.setAlarmStatus(0);
|
|
|
- alarmData.setAlarmTime(LocalDateTime.now());
|
|
|
- alarmData.setRemark(remark);
|
|
|
- alarmData.setCreateTime(LocalDateTime.now());
|
|
|
- alarmDataService.saveAlarmData(alarmData);
|
|
|
- log.info("设备主动告警入库(1级): deviceCode={}, warningCode={}", deviceCode, warningCode);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("保存告警数据失败", e);
|
|
|
- }
|
|
|
- }
|
|
|
//构造发送短信参数&&发送短信
|
|
|
public void sendMessage(String deviceNo, String alarmType, BigDecimal lng, BigDecimal lat){
|
|
|
// 构造短信参数
|