|
@@ -11,6 +11,7 @@ import vip.xiaonuo.coldchain.core.alarm.bean.SensorThreshold;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.config.ColdChainAlarmMessageProperties;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.enums.SensorAlarmType;
|
|
|
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.event.SensorAlarmEvent;
|
|
@@ -29,6 +30,7 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
private final SensorThresholdService thresholdService;
|
|
|
private final ColdChainAlarmMessageProperties alarmMessageProperties;
|
|
|
private final ApplicationEventPublisher applicationEventPublisher;
|
|
|
+ private final RedisSensorAlarmMessagePushService redisSensorAlarmMessagePushService;
|
|
|
|
|
|
private final DeviceOfflineDetectionService deviceOfflineDetectionService;
|
|
|
|
|
@@ -78,16 +80,23 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
String unit = getUnit(type);
|
|
|
if (noNull(upperThreshold) && value > upperThreshold) {
|
|
|
// 超过上限,触发超标报警
|
|
|
- publishAlarm(type + "超标", value, unit, time, upperThreshold, monitorTargetRegion);
|
|
|
+ publishAlarm(type + "超标", value, unit, time, upperThreshold, monitorTargetRegion
|
|
|
+ , SensorAlarmType.DATA_ALARM.getDeviceCode());
|
|
|
alarmTriggered = true;
|
|
|
} else if (noNull(lowerThreshold) && value < lowerThreshold) {
|
|
|
// 低于下限,触发低于阈值报警
|
|
|
- publishAlarm(type + "过低", value, unit, time, lowerThreshold, monitorTargetRegion);
|
|
|
+ publishAlarm(type + "过低", value, unit, time, lowerThreshold, monitorTargetRegion
|
|
|
+ , SensorAlarmType.DATA_ALARM.getDeviceCode());
|
|
|
alarmTriggered = true;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
+ //todo
|
|
|
// SensorAlarmType.DATA_RESTORE_ALARM
|
|
|
- log.info("针对异常设备数据恢复?设备正常");
|
|
|
-
|
|
|
+ if (redisSensorAlarmMessagePushService.hasExceededPushLimit("*", monitorTargetRegion.getDeviceCode(), monitorTargetRegion.getSensorRoute(),type + "??")) {
|
|
|
+ publishAlarm(type + "恢复", value, unit, time, upperThreshold, monitorTargetRegion
|
|
|
+ , SensorAlarmType.DATA_RESTORE_ALARM.getDeviceCode());
|
|
|
+ alarmTriggered = true;
|
|
|
+ log.info("针对异常设备数据恢复?设备正常");
|
|
|
+ }
|
|
|
}
|
|
|
return alarmTriggered;
|
|
|
}
|
|
@@ -100,11 +109,13 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
* @param value 传感器数据值
|
|
|
* @param unit 传感器数据单位
|
|
|
* @param time 时间戳
|
|
|
+ * @param type SensorAlarmType
|
|
|
*/
|
|
|
- private void publishAlarm(String alarmType, Float value, String unit, String time, float threshold, MonitorTargetRegion monitorTargetRegion) {
|
|
|
+ private void publishAlarm(String alarmType, Float value, String unit, String time
|
|
|
+ , float threshold, MonitorTargetRegion monitorTargetRegion, String type) {
|
|
|
String monitorTargetId = monitorTargetRegion.getMonitorTargetId();
|
|
|
Integer sensorRoute = monitorTargetRegion.getSensorRoute();
|
|
|
- String sensorCode = monitorTargetRegion.getSensorCode();
|
|
|
+ String sensorCode = monitorTargetRegion.getSensorCode();
|
|
|
String deviceName = monitorTargetRegion.getName();
|
|
|
String deviceId = monitorTargetRegion.getId();
|
|
|
String alarmMessage = getAlarmMessage(alarmType, value, unit, deviceName, time, threshold);
|
|
@@ -127,8 +138,8 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
List<SensorAlarmUser> alarmUsers = monitorTargetRegion.getAlarmUsers();
|
|
|
sensorAlarm.setAlarmUsers(alarmUsers);
|
|
|
sensorAlarm.setThreshold(threshold);
|
|
|
- // 修改TODO
|
|
|
- sensorAlarm.setType(SensorAlarmType.DATA_ALARM.getDeviceCode());
|
|
|
+ // TODO
|
|
|
+ sensorAlarm.setType(type);
|
|
|
// 设置报警人机构 所属用户和机构
|
|
|
sensorAlarm.setCreateUser(monitorTargetRegion.getCreateUser());
|
|
|
sensorAlarm.setCreateOrg(monitorTargetRegion.getCreateOrg());
|
|
@@ -171,6 +182,15 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
case "二氧化碳过低":
|
|
|
messageTemplate = alarmMessageProperties.getCo2BelowLimit();
|
|
|
break;
|
|
|
+ case "温度恢复":
|
|
|
+ messageTemplate = alarmMessageProperties.getTemperatureRecover();
|
|
|
+ break;
|
|
|
+ case "湿度恢复":
|
|
|
+ messageTemplate = alarmMessageProperties.getHumidityRecover();
|
|
|
+ break;
|
|
|
+ case "二氧化碳恢复":
|
|
|
+ messageTemplate = alarmMessageProperties.getCo2Recover();
|
|
|
+ break;
|
|
|
default:
|
|
|
messageTemplate = "{alarmType}: 当前值:{value} {unit}";
|
|
|
break;
|