|
|
@@ -198,9 +198,25 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
}
|
|
|
public void checkIfSmsAlertNeeded(GasMonitorData resultData){
|
|
|
- //用MAC地址作为设备的设备编号
|
|
|
- String deviceId = resultData.getMacAddress();
|
|
|
- boolean hasAlarm = false;
|
|
|
+ String deviceId = resultData == null ? null : resultData.getMacAddress();
|
|
|
+ try {
|
|
|
+ if (resultData == null || deviceId == null || deviceId.trim().isEmpty()) {
|
|
|
+ log.warn("可燃气体报警数据缺少设备编码,跳过状态覆盖");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean hasAlarm = evaluateAlarmStatus(resultData);
|
|
|
+ updateDeviceAlarmStatus(deviceId, hasAlarm ? 1 : 0);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 评估不完整时不覆盖上一状态,避免异常数据误清除报警
|
|
|
+ log.error("可燃气体设备报警处理失败,保留原报警状态:deviceCode={}", deviceId, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 评估单条采集数据是否存在报警。只有完整评估成功才允许同步设备状态。 */
|
|
|
+ private boolean evaluateAlarmStatus(GasMonitorData resultData){
|
|
|
+ //用MAC地址作为设备的设备编号
|
|
|
+ String deviceId = resultData.getMacAddress();
|
|
|
+ boolean hasAlarm = false;
|
|
|
|
|
|
//获取温度阈值
|
|
|
String temWarningCode = "WARN-GAS-TEMPERATURE";
|
|
|
@@ -390,8 +406,7 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
hasAlarm = true;
|
|
|
}
|
|
|
|
|
|
- // 同步设备报警状态到 equipment_status 表
|
|
|
- updateDeviceAlarmStatus(deviceId, hasAlarm ? 1 : 0);
|
|
|
+ return hasAlarm;
|
|
|
}
|
|
|
|
|
|
private WarningThreshold checkThreshold(String deviceCode, String warningCode) {
|
|
|
@@ -485,10 +500,14 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
HttpEntity<Map<String, Object>> request = new HttpEntity<>(params, headers);
|
|
|
|
|
|
- restTemplate.postForObject(deviceStatusApiUrl, request, Map.class);
|
|
|
+ Map<?, ?> response = restTemplate.postForObject(deviceStatusApiUrl, request, Map.class);
|
|
|
+ if (response == null || !Boolean.TRUE.equals(response.get("success"))) {
|
|
|
+ log.warn("设备报警状态更新未成功: deviceCode={}, alarmStatus={}, response={}", deviceCode, alarmStatus, response);
|
|
|
+ return;
|
|
|
+ }
|
|
|
log.info("设备报警状态更新成功: deviceCode={}, alarmStatus={}", deviceCode, alarmStatus);
|
|
|
} catch (Exception e) {
|
|
|
log.error("更新设备报警状态失败: deviceCode={}, alarmStatus={}", deviceCode, alarmStatus, e);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|