feat(alarm): 更新告警系统以支持在线率和完整性监控

- 移除原有的中断计数功能,改为在线率和完整性告警判断
- 新增CsAlarmData类用于存储在线率和完整性详细数据
- 更新AlarmVO数据结构,替换interruptCounts为onlineRateIsWarn和integrityIsWarn字段
- 修改告警服务实现,从JSON解析List<List<String>>改为解析CsAlarmData对象
- 新增channelRunDataAlarm方法用于运行数据告警算法,处理在线率和完整性阈值判断
- 实现完整的告警数据构建逻辑,包括设备在线率计算和监测点完整性评估
- 更新统计服务中的数据去重逻辑,避免重复计算设备和监测点数据
This commit is contained in:
xy
2026-05-14 09:22:26 +08:00
parent 82e5d6c8e2
commit aa36c077f2
8 changed files with 348 additions and 55 deletions

View File

@@ -19,6 +19,7 @@ import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csharmonic.mapper.CsAlarmMapper;
import com.njcn.csharmonic.pojo.po.CsAlarm;
import com.njcn.csharmonic.pojo.po.CsAlarmData;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.AlarmVO;
@@ -118,13 +119,12 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsAlarmMapper, CsAlarm> impl
alarmVO.setDevIds(matchedDevIds);
alarmVO.setIsRead(userEvents.stream().filter(item1->item1.getEventId().equals(alarm.getId())).findFirst().map(CsEventUserPO::getStatus).orElse(1));
int interruptCounts = 0;
int warnCounts = 0;
ObjectMapper objectMapper = new ObjectMapper();
List<List<String>> resultList;
List<CsAlarmData> resultList;
List<List<String>> resultList2;
try {
resultList = objectMapper.readValue(alarm.getInterruptEvent(), new TypeReference<List<List<String>>>() {});
resultList = objectMapper.readValue(alarm.getInterruptEvent(), new TypeReference<List<CsAlarmData>>() {});
resultList2 = objectMapper.readValue(alarm.getAlarmEvent(), new TypeReference<List<List<String>>>() {});
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
@@ -133,12 +133,17 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsAlarmMapper, CsAlarm> impl
for (String matchedDevId : matchedDevIds) {
for (int j = 0; j < devIds.length; j++) {
if (Objects.equals(matchedDevId, devIds[j])) {
interruptCounts = interruptCounts + (Objects.isNull(resultList.get(j)) ? 0 : resultList.get(j).get(0).split("").length);
warnCounts = warnCounts + (Objects.isNull(resultList2.get(j)) ? 0 : resultList2.get(j).size());
}
}
}
alarmVO.setInterruptCounts(interruptCounts);
//根据resultList 来查询在线率和完整是否有true的如果有就设置alarmVO的属性
resultList.forEach(item->{
alarmVO.setOnlineRateIsWarn(item.getOnlineRate().getIsAbnormal());
boolean hasAbnormal = item.getIntegrity().getMonitorPoints().stream()
.anyMatch(CsAlarmData.IntegrityAlarm.MonitorPointIntegrity::getIsAbnormal);
alarmVO.setIntegrityIsWarn(hasAbnormal);
});
alarmVO.setWarnCounts(warnCounts);
return alarmVO;
})
@@ -147,35 +152,6 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsAlarmMapper, CsAlarm> impl
.collect(Collectors.toList());
page1.setRecords(result);
}
// if (CollectionUtil.isNotEmpty(list)) {
// //获取用户推送事件
// List<CsEventUserPO> userEvents = csEventUserPOService.queryEventListByUserId(RequestUtil.getUserIndex(), list.stream().map(CsAlarm::getId).collect(Collectors.toList()));
//
// List<String> finalDevList = devList;
// List<AlarmVO> result = list.stream()
// .map(alarm -> {
// AlarmVO alarmVO = new AlarmVO();
// alarmVO.setEventId(alarm.getId());
// alarmVO.setDate(alarm.getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
//
// String devListStr = alarm.getDevList();
// String[] devIds = devListStr.split(",");
// List<String> matchedDevIds = Arrays.stream(devIds)
// .filter(devId -> StrUtil.isNotBlank(devId.trim()))
// .filter(finalDevList::contains)
// .collect(Collectors.toList());
// alarmVO.setWarnNums(matchedDevIds.size());
// alarmVO.setDevIds(matchedDevIds);
// alarmVO.setIsRead(userEvents.stream().filter(item1->item1.getEventId().equals(alarm.getId())).findFirst().map(CsEventUserPO::getStatus).orElse(1));
// return alarmVO;
// })
// .filter(alarmVO -> alarmVO.getWarnNums() > 0)
// .sorted((a1, a2) -> a2.getDate().compareTo(a1.getDate()))
// .collect(Collectors.toList());
// page1.setRecords(result);
// }
}
}
return page1;
@@ -212,20 +188,16 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsAlarmMapper, CsAlarm> impl
if (ObjectUtil.isNotNull(alarm.getInterruptEvent())) {
String interruptEvent = alarm.getInterruptEvent();
List<List<String>> resultList = new ArrayList<>();
List<CsAlarmData> resultList = new ArrayList<>();
if (StrUtil.isNotBlank(interruptEvent)) {
try {
ObjectMapper objectMapper = new ObjectMapper();
resultList = objectMapper.readValue(interruptEvent, new TypeReference<List<List<String>>>() {});
resultList = objectMapper.readValue(interruptEvent, new TypeReference<List<CsAlarmData>>() {});
alarmDetail.setDataDetails(resultList.get(i));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
List<String> interruptDetails = resultList.get(i);
if (CollectionUtil.isNotEmpty(interruptDetails)) {
alarmDetail.setInterruptCounts(interruptDetails.get(0).split("").length);
alarmDetail.setInterruptDetails(interruptDetails);
}
}
if (ObjectUtil.isNotNull(alarm.getAlarmEvent())) {
String alarmEvent = alarm.getAlarmEvent();

View File

@@ -107,8 +107,8 @@ public class StatisticsDataDataServiceImpl implements IStatisticsDataDataService
List<CsLinePO> csLineList = csLineFeignClient.getLinesByDevList(devList).getData();
if (CollectionUtil.isNotEmpty(csLineList)) {
Map<String,List<CsLinePO>> devMap = csLineList.stream().collect(Collectors.groupingBy(CsLinePO::getDeviceId));
List<String> lineList = csLineList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
List<String> deviceList = csLineList.stream().map(CsLinePO::getDeviceId).collect(Collectors.toList());
List<String> lineList = csLineList.stream().map(CsLinePO::getLineId).distinct().collect(Collectors.toList());
List<String> deviceList = csLineList.stream().map(CsLinePO::getDeviceId).distinct().collect(Collectors.toList());
//获取监测点数据完整性
IcdBzParam param1 = new IcdBzParam();
param1.setLineList(lineList);