|
|
@@ -1,7 +1,9 @@
|
|
|
package com.zksy.gas.utils;
|
|
|
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.zksy.api.domain.WarningThreshold;
|
|
|
+import com.zksy.api.service.EarlyWarningAutoService;
|
|
|
import com.zksy.api.service.WarningThresholdService;
|
|
|
import com.zksy.api.domain.AlarmData;
|
|
|
import com.zksy.api.service.AlarmDataService;
|
|
|
@@ -22,10 +24,16 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -40,11 +48,18 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
@Autowired
|
|
|
private AlarmDataService alarmDataService;
|
|
|
@Autowired
|
|
|
- private SmsUtil smsUtil;
|
|
|
+ private EarlyWarningAutoService earlyWarningAutoService;
|
|
|
@Autowired
|
|
|
- private DevicePhoneFetchUtil devicePhoneFetchUtil;
|
|
|
+ private SmsUtil smsUtil;
|
|
|
@Autowired
|
|
|
- private AlarmUtil alarmUtil;
|
|
|
+ private DevicePhoneFetchUtil devicePhoneFetchUtil;
|
|
|
+ @Autowired
|
|
|
+ private AlarmUtil alarmUtil;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Value("${device.status.api.url:http://zk-api-service/equipmentStatus/updateAlarmStatus}")
|
|
|
+ private String deviceStatusApiUrl;
|
|
|
|
|
|
@Autowired
|
|
|
public MessageHandler(GasMonitorDataService firefightingPressureService) {
|
|
|
@@ -177,8 +192,9 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
}
|
|
|
public void checkIfSmsAlertNeeded(GasMonitorData resultData){
|
|
|
- //用MAC地址作为设备的设备编号
|
|
|
- String deviceId = resultData.getMacAddress();
|
|
|
+ //用MAC地址作为设备的设备编号
|
|
|
+ String deviceId = resultData.getMacAddress();
|
|
|
+ boolean hasAlarm = false;
|
|
|
|
|
|
//获取温度阈值
|
|
|
String temWarningCode = "WARN-GAS-TEMPERATURE";
|
|
|
@@ -213,13 +229,21 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
if (temMaxValue != null && temperature >= temMaxValue) {
|
|
|
temperatureIsOverThreshold = true;
|
|
|
}
|
|
|
- if(temperatureIsOverThreshold){
|
|
|
- int alarmLevel = saveAlarmData(deviceId, temWarningType, temWarningCode,
|
|
|
- temMinValue != null ? BigDecimal.valueOf(temMinValue) : null,
|
|
|
- temMaxValue != null ? BigDecimal.valueOf(temMaxValue) : null,
|
|
|
- BigDecimal.valueOf(temperature), temRemark != null ? temRemark : "可燃气体温度报警");
|
|
|
- if (alarmLevel == 1) {
|
|
|
- sendMessage(deviceId, temWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -232,13 +256,21 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
if (humMaxValue != null && humidity >= humMaxValue) {
|
|
|
humidityIsOverThreshold = true;
|
|
|
}
|
|
|
- if(humidityIsOverThreshold){
|
|
|
- int alarmLevel = saveAlarmData(deviceId, humWarningType, humWarningCode,
|
|
|
- humMinValue != null ? BigDecimal.valueOf(humMinValue) : null,
|
|
|
- humMaxValue != null ? BigDecimal.valueOf(humMaxValue) : null,
|
|
|
- BigDecimal.valueOf(humidity), humRemark != null ? humRemark : "可燃气体湿度报警");
|
|
|
- if (alarmLevel == 1) {
|
|
|
- sendMessage(deviceId, humWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -252,85 +284,111 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
if (gasMaxValue != null && actualGasConcentration >= gasMaxValue) {
|
|
|
concentrationIsOverThreshold = true;
|
|
|
}
|
|
|
- if(concentrationIsOverThreshold){
|
|
|
- int alarmLevel = saveAlarmData(deviceId, gasWarningType, gasWarningCode,
|
|
|
- gasMinValue != null ? BigDecimal.valueOf(gasMinValue) : null,
|
|
|
- gasMaxValue != null ? BigDecimal.valueOf(gasMaxValue) : null,
|
|
|
- gasConcentration, gasRemark != null ? gasRemark : "可燃气体浓度报警");
|
|
|
- if (alarmLevel == 1) {
|
|
|
- sendMessage(deviceId, gasWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
+ 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) {
|
|
|
+ sendMessage(deviceId, gasWarningType, resultData.getLongitude(), resultData.getLatitude());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ 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());
|
|
|
- }
|
|
|
- if(alarmBits.get("highAlarm")){
|
|
|
- saveAlarmDataLevelOne(deviceId, "高报警", "WARN-HIGH", null, "可燃气体高报警");
|
|
|
- sendMessage(deviceId,"高报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
- }
|
|
|
+ saveAlarmDataLevelOne(deviceId, "未知报警", "WARN-UNKNOWN", null, "可燃气体未知报警");
|
|
|
+ sendMessage(deviceId,"未知报警",resultData.getLongitude(),resultData.getLatitude());
|
|
|
+ hasAlarm = true;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步设备报警状态到 equipment_status 表
|
|
|
+ updateDeviceAlarmStatus(deviceId, hasAlarm ? 1 : 0);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private WarningThreshold checkThreshold(String deviceCode, String warningCode) {
|
|
|
+ private WarningThreshold checkThreshold(String deviceCode, String warningCode) {
|
|
|
try {
|
|
|
return warningThresholdService.getWarningThresholdByDeviceAndCode(deviceCode, warningCode);
|
|
|
} catch (Exception e) {
|
|
|
@@ -404,5 +462,27 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
List<String> phoneListByDeviceId = devicePhoneFetchUtil.getPhoneListByDeviceId(deviceNo);
|
|
|
Map<String, Boolean> sendResults = smsUtil.sendBatchSms(phoneListByDeviceId, params.toJSONString());
|
|
|
log.info("发送信息完成");
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新设备报警状态
|
|
|
+ * @param deviceCode 设备编码
|
|
|
+ * @param alarmStatus 报警状态:0-正常,1-报警
|
|
|
+ */
|
|
|
+ private void updateDeviceAlarmStatus(String deviceCode, int alarmStatus) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("deviceCode", deviceCode);
|
|
|
+ params.put("alarmStatus", alarmStatus);
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ HttpEntity<Map<String, Object>> request = new HttpEntity<>(params, headers);
|
|
|
+
|
|
|
+ restTemplate.postForObject(deviceStatusApiUrl, request, Map.class);
|
|
|
+ log.info("设备报警状态更新成功: deviceCode={}, alarmStatus={}", deviceCode, alarmStatus);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新设备报警状态失败: deviceCode={}, alarmStatus={}", deviceCode, alarmStatus, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|