|
@@ -4,16 +4,15 @@ import ch.qos.logback.classic.Logger;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.cpp.common.utils.spring.SpringUtils;
|
|
import com.cpp.common.utils.spring.SpringUtils;
|
|
import com.cpp.web.domain.Alarm.AbnormalAlarm;
|
|
import com.cpp.web.domain.Alarm.AbnormalAlarm;
|
|
|
|
+import com.cpp.web.domain.Alarm.AlarmConf;
|
|
import com.cpp.web.domain.enums.AlarmEnum;
|
|
import com.cpp.web.domain.enums.AlarmEnum;
|
|
import com.cpp.web.domain.enums.DataSourcesEnum;
|
|
import com.cpp.web.domain.enums.DataSourcesEnum;
|
|
import com.cpp.web.utils.LogUtil;
|
|
import com.cpp.web.utils.LogUtil;
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -30,6 +29,8 @@ public class AlarmLog {
|
|
return LazyHolder.INSTANCE;
|
|
return LazyHolder.INSTANCE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Map<String, List<AlarmConf>> stationAlarmConfListMap = new ConcurrentHashMap<>();
|
|
|
|
+
|
|
private static class LazyHolder {
|
|
private static class LazyHolder {
|
|
private static final AlarmLog INSTANCE = new AlarmLog();
|
|
private static final AlarmLog INSTANCE = new AlarmLog();
|
|
}
|
|
}
|
|
@@ -44,11 +45,20 @@ public class AlarmLog {
|
|
*/
|
|
*/
|
|
public void info(DataSourcesEnum alarmSource, AlarmEnum alarmType, String info, String stationCode) {
|
|
public void info(DataSourcesEnum alarmSource, AlarmEnum alarmType, String info, String stationCode) {
|
|
|
|
|
|
|
|
+ List<AlarmConf> alarmConfs = stationAlarmConfListMap.get(stationCode);
|
|
|
|
+
|
|
|
|
+ Integer status = 0;
|
|
|
|
+
|
|
|
|
+ if (alarmConfs.stream().anyMatch(a -> a.getType().equals(1) ? a.getKeyword().equals(info) : info.contains(a.getKeyword()))) {
|
|
|
|
+ status = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
String key = alarmSource.getCode() + "_" + alarmType.getCode() + "_" + info + "_" + stationCode;
|
|
String key = alarmSource.getCode() + "_" + alarmType.getCode() + "_" + info + "_" + stationCode;
|
|
if (alarmDtoMap.containsKey(key)) {
|
|
if (alarmDtoMap.containsKey(key)) {
|
|
alarmDtoMap.get(key).setUpdateTime(new Date());
|
|
alarmDtoMap.get(key).setUpdateTime(new Date());
|
|
} else {
|
|
} else {
|
|
AbnormalAlarm abnormalAlarm = new AbnormalAlarm(alarmSource, alarmType, info, stationCode);
|
|
AbnormalAlarm abnormalAlarm = new AbnormalAlarm(alarmSource, alarmType, info, stationCode);
|
|
|
|
+ abnormalAlarm.setStatus(status);
|
|
SpringUtils.getBean(AbnormalAlarmService.class).save(abnormalAlarm);
|
|
SpringUtils.getBean(AbnormalAlarmService.class).save(abnormalAlarm);
|
|
AlarmDto alarmDto = new AlarmDto(abnormalAlarm, new Date());
|
|
AlarmDto alarmDto = new AlarmDto(abnormalAlarm, new Date());
|
|
alarmDtoMap.put(key, alarmDto);
|
|
alarmDtoMap.put(key, alarmDto);
|
|
@@ -59,6 +69,9 @@ public class AlarmLog {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 告警数据传输对象
|
|
|
|
+ */
|
|
@Data
|
|
@Data
|
|
public class AlarmDto {
|
|
public class AlarmDto {
|
|
private AbnormalAlarm abnormalAlarm;
|
|
private AbnormalAlarm abnormalAlarm;
|
|
@@ -107,5 +120,32 @@ public class AlarmLog {
|
|
String key = abnormalAlarm.getAlarmSource().getCode() + "_" + abnormalAlarm.getAlarmType().getCode() + "_" + abnormalAlarm.getMsg() + "_" + abnormalAlarm.getStationCode();
|
|
String key = abnormalAlarm.getAlarmSource().getCode() + "_" + abnormalAlarm.getAlarmType().getCode() + "_" + abnormalAlarm.getMsg() + "_" + abnormalAlarm.getStationCode();
|
|
alarmDtoMap.put(key, new AlarmDto(abnormalAlarm, new Date()));
|
|
alarmDtoMap.put(key, new AlarmDto(abnormalAlarm, new Date()));
|
|
}
|
|
}
|
|
|
|
+ List<AlarmConf> alarmConfs = SpringUtils.getBean(AlarmConfService.class).list(Wrappers.lambdaQuery(AlarmConf.class).select().ge(AlarmConf::getExpireTime, new Date()));
|
|
|
|
+
|
|
|
|
+ stationAlarmConfListMap = alarmConfs.stream().collect(Collectors.groupingBy(AlarmConf::getStationCode, Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void updateStationAlarmConfListMap(AlarmConf alarmConf, Boolean b) {
|
|
|
|
+
|
|
|
|
+ if (b) {
|
|
|
|
+ //更新
|
|
|
|
+ if (stationAlarmConfListMap.containsKey(alarmConf.getStationCode())){
|
|
|
|
+ List<AlarmConf> list = stationAlarmConfListMap.get(alarmConf.getStationCode());
|
|
|
|
+ list.removeIf(s->s.getId().equals(alarmConf.getId()));
|
|
|
|
+ list.add(alarmConf);
|
|
|
|
+ }else {
|
|
|
|
+ List<AlarmConf> list = new ArrayList<>();
|
|
|
|
+ list.add(alarmConf);
|
|
|
|
+ stationAlarmConfListMap.put(alarmConf.getStationCode(),list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ //删除
|
|
|
|
+ if (stationAlarmConfListMap.containsKey(alarmConf.getStationCode())){
|
|
|
|
+ List<AlarmConf> list = stationAlarmConfListMap.get(alarmConf.getStationCode());
|
|
|
|
+ list.removeIf(s->s.getId().equals(alarmConf.getId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|