|
|
@@ -4,6 +4,7 @@ import com.github.jfcloud.influxdb.util.InfluxDBDateFormatter;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.bean.NotificationChannel;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.bean.SensorAlarm;
|
|
|
@@ -15,6 +16,7 @@ import vip.xiaonuo.coldchain.core.alarm.offline.DeviceOfflineDetectionService;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.service.messagepush.RedisSensorAlarmMessagePushService;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.service.threshold.SensorThresholdService;
|
|
|
import vip.xiaonuo.coldchain.core.bean.influxdb.SensorData;
|
|
|
+import vip.xiaonuo.coldchain.core.config.JfcloudColdChainConstants;
|
|
|
import vip.xiaonuo.coldchain.core.event.SensorAlarmEvent;
|
|
|
import vip.xiaonuo.coldchain.modular.monitortargetregion.entity.MonitorTargetRegion;
|
|
|
|
|
|
@@ -22,6 +24,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
@Component
|
|
|
@RequiredArgsConstructor
|
|
|
@@ -33,7 +36,7 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
private final ColdChainAlarmMessageProperties alarmMessageProperties;
|
|
|
private final ApplicationEventPublisher applicationEventPublisher;
|
|
|
private final RedisSensorAlarmMessagePushService redisSensorAlarmMessagePushService;
|
|
|
-
|
|
|
+ private final RedisTemplate<String, Object> redisTemplate;
|
|
|
private final DeviceOfflineDetectionService deviceOfflineDetectionService;
|
|
|
|
|
|
@Override
|
|
|
@@ -89,6 +92,42 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
if (noNull(sensorData.getBattery())) {
|
|
|
alarmTriggered |= checkThreshold(sensorData.getBattery(), null, threshold.getBatteryDown(), "电量", monitorTargetRegion);
|
|
|
}
|
|
|
+ if (noNull(sensorData.getCh2o())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getCh2o(), threshold.getCh2oUp(), threshold.getCh2oDown(), "甲醛 ", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getO3())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getO3(), threshold.getO3Up(), threshold.getO3Down(), "臭氧", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getH2s())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getH2s(), threshold.getH2sUp(), threshold.getH2sDown(), "硫化氢", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getCh4())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getCh4(), threshold.getCh4Up(), threshold.getCh4Down(), "甲烷", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getNo2())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getNo2(), threshold.getNo2Up(), threshold.getNo2Down(), "二氧化氮", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getSo2())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getSo2(), threshold.getSo2Up(), threshold.getSo2Down(), "二氧化硫", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getH2())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getH2(), threshold.getH2Up(), threshold.getH2Down(), "氢气", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getH2s())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getH2s(), threshold.getH2sUp(), threshold.getH2sDown(), "硫化氢", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getDB())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getDB(), threshold.getDBUp(), threshold.getDBDown(), "噪声", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getOdor())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getOdor(), threshold.getOdorUp(), threshold.getOdorDown(), "异味", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getTsp())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getTsp(), threshold.getTspUp(), threshold.getTspDown(), "TSP", monitorTargetRegion);
|
|
|
+ }
|
|
|
+ if (noNull(sensorData.getSmoke())) {
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getSmoke(), threshold.getSmokeUp(), threshold.getSmokeDown(), "烟雾", monitorTargetRegion);
|
|
|
+ }
|
|
|
return alarmTriggered;
|
|
|
}
|
|
|
|
|
|
@@ -119,8 +158,17 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
//todo
|
|
|
// SensorAlarmType.DATA_RESTORE_ALARM
|
|
|
if (redisSensorAlarmMessagePushService.hasExceededPushLimitLike(monitorTargetRegion.getId(), monitorTargetRegion.getSensorRoute(),type + "*")) {
|
|
|
- publishAlarm(type + "恢复", value, unit, time, upperThreshold, monitorTargetRegion
|
|
|
- , SensorAlarmType.DATA_RESTORE_ALARM.getDeviceCode());
|
|
|
+ String key = generateAlarmHistoryKey(monitorTargetRegion.getId(), monitorTargetRegion.getSensorRoute(), type + "*");
|
|
|
+ Set<String> keys = redisTemplate.keys(key);
|
|
|
+ for (String k : keys) {
|
|
|
+ if (k.contains("过低")) {
|
|
|
+ publishAlarm(type + "恢复", value, unit, time, lowerThreshold, monitorTargetRegion
|
|
|
+ , SensorAlarmType.DATA_RESTORE_ALARM.getDeviceCode());
|
|
|
+ } else if (k.contains("超标")) {
|
|
|
+ publishAlarm(type + "恢复", value, unit, time, upperThreshold, monitorTargetRegion
|
|
|
+ , SensorAlarmType.DATA_RESTORE_ALARM.getDeviceCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
alarmTriggered = true;
|
|
|
log.info("针对异常设备数据恢复?设备正常");
|
|
|
}
|
|
|
@@ -128,6 +176,11 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
return alarmTriggered;
|
|
|
}
|
|
|
|
|
|
+ private String generateAlarmHistoryKey(String deviceID, Integer sensorRoute, String alarmType) {
|
|
|
+ return JfcloudColdChainConstants.REDIS_ALARM_HISTORY_KEY_PREFIX
|
|
|
+ + ":" + deviceID + ":" + sensorRoute + ":" + alarmType;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 发布报警事件
|