在线监测算法每日更新导致告警单丢失问题
This commit is contained in:
@@ -160,12 +160,15 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addHeBeiNorthLineWarning(String startTime, String endTime) {
|
||||
List<LineWarning> result = new ArrayList<>();
|
||||
List<LineWarning> channelData = new ArrayList<>();
|
||||
//获取指标集合(10个指标)
|
||||
List<DictData> dataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
|
||||
Map<String, DictData> targetMap = dataList.stream().collect(Collectors.toMap(DictData::getCode, Function.identity()));
|
||||
//获取监测点和部门表关系
|
||||
List<DeptLine> deptLines = deptLineFeignClient.getAllData().getData();
|
||||
Map<String, List<DeptLine>> deptLineMap = deptLines.stream().collect(Collectors.groupingBy(DeptLine::getLineId));
|
||||
// Map<String, List<DeptLine>> deptLineMap = deptLines.stream().collect(Collectors.groupingBy(DeptLine::getLineId));
|
||||
Map<String, DeptLine> deptLineMap = deptLines.stream().collect(Collectors.toMap(DeptLine::getLineId, Function.identity()));
|
||||
|
||||
//获取监测点按时间统计越限天数
|
||||
LocalDate firstDayOfMonth = Objects.isNull(startTime) ? LocalDate.now().minusDays(1).with(TemporalAdjusters.firstDayOfMonth()) : LocalDate.parse(startTime);
|
||||
String date = Objects.isNull(startTime) ? DateUtil.format(firstDayOfMonth.atStartOfDay(), DatePattern.NORM_DATE_PATTERN) : startTime;
|
||||
@@ -175,7 +178,7 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
|
||||
//按各指标统计越限天数
|
||||
if (CollUtil.isNotEmpty(limitTarget)) {
|
||||
limitTarget.forEach(item -> {
|
||||
String deptId = Objects.isNull(deptLineMap.get(item.getLineId())) ? null : deptLineMap.get(item.getLineId()).get(0).getId();
|
||||
String deptId = Objects.isNull(deptLineMap.get(item.getLineId())) ? null : deptLineMap.get(item.getLineId()).getId();
|
||||
//频率偏差
|
||||
LineWarning l1 = overData(firstDayOfMonth, item.getLineId(), deptId, targetMap.get(DicDataEnum.FREQUENCY_DEV.getCode()).getId(), item.getFreqDevOvertime());
|
||||
//电压偏差
|
||||
@@ -206,7 +209,7 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
|
||||
List<OnlineMonitorVo> list = lineIntegrityClient.getNoData(param).getData();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
String deptId = Objects.isNull(deptLineMap.get(item.getLineId())) ? null : deptLineMap.get(item.getLineId()).get(0).getId();
|
||||
String deptId = Objects.isNull(deptLineMap.get(item.getLineId())) ? null : deptLineMap.get(item.getLineId()).getId();
|
||||
LineWarning lineWarning = new LineWarning();
|
||||
lineWarning.setAlarmTime(firstDayOfMonth);
|
||||
lineWarning.setDeptId(deptId);
|
||||
@@ -220,7 +223,7 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
|
||||
List<OnlineMonitorVo> list2 = pqDataVerifyCountClient.getAnomalousData(param).getData();
|
||||
if (CollUtil.isNotEmpty(list2)) {
|
||||
list2.forEach(item -> {
|
||||
String deptId = Objects.isNull(deptLineMap.get(item.getLineId())) ? null : deptLineMap.get(item.getLineId()).get(0).getId();
|
||||
String deptId = Objects.isNull(deptLineMap.get(item.getLineId())) ? null : deptLineMap.get(item.getLineId()).getId();
|
||||
LineWarning lineWarning = new LineWarning();
|
||||
lineWarning.setAlarmTime(firstDayOfMonth);
|
||||
lineWarning.setDeptId(deptId);
|
||||
@@ -230,8 +233,37 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
|
||||
result.add(lineWarning);
|
||||
});
|
||||
}
|
||||
//获取时间范围内数据库的数据,然后仅替换累计超标时间
|
||||
LambdaQueryWrapper<LineWarning> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.between(LineWarning::getAlarmTime,date,endDate);
|
||||
List<LineWarning> oldData = this.list(lambdaQueryWrapper);
|
||||
if (CollUtil.isNotEmpty(oldData) && CollUtil.isNotEmpty(result)) {
|
||||
// 创建结果数据的查找Map
|
||||
Map<String, LineWarning> resultMap = result.stream()
|
||||
.collect(Collectors.toMap(
|
||||
item -> buildKey(item.getDeptId(), item.getLineId(), item.getTargetType()),
|
||||
Function.identity()
|
||||
));
|
||||
for (LineWarning oldItem : oldData) {
|
||||
String key = buildKey(oldItem.getDeptId(), oldItem.getLineId(), oldItem.getTargetType());
|
||||
LineWarning matchingResult = resultMap.get(key);
|
||||
if (matchingResult != null) {
|
||||
oldItem.setOverLimitDay(matchingResult.getOverLimitDay());
|
||||
oldItem.setUpdateTime(LocalDateTime.now());
|
||||
channelData.add(oldItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(channelData)) {
|
||||
this.saveOrUpdateBatchByMultiId(channelData);
|
||||
} else {
|
||||
this.saveOrUpdateBatchByMultiId(result);
|
||||
}
|
||||
}
|
||||
|
||||
this.saveOrUpdateBatchByMultiId(result);
|
||||
|
||||
private static String buildKey(String deptId, String lineId, String targetType) {
|
||||
return deptId + "|" + lineId + "|" + targetType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user