在线监测算法每日更新导致告警单丢失问题

This commit is contained in:
xy
2025-12-26 11:24:22 +08:00
parent 2dccb22cf8
commit 6d8bfacd0a
4 changed files with 53 additions and 7 deletions

View File

@@ -168,10 +168,10 @@ public class DeptLineController extends BaseController {
@OperateInfo(info = LogEnum.SYSTEM_COMMON) @OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/getAllData") @PostMapping("/getAllData")
@ApiOperation("获取部门监测点表所有数据") @ApiOperation("获取部门监测点表数据(仅查询在运监测点)")
public HttpResult<List<DeptLine>> getAllData() { public HttpResult<List<DeptLine>> getAllData() {
String methodDescribe = getMethodDescribe("getAllData"); String methodDescribe = getMethodDescribe("getAllData");
List<DeptLine> list = deptLineMapper.selectList(null); List<DeptLine> list = deptLineMapper.getOnlineMonitor();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
} }
} }

View File

@@ -95,4 +95,6 @@ public interface DeptLineMapper extends BaseMapper<DeptLine> {
List<SubGetBase> selectSubStationList(@Param("param") SubstationParam substationParam); List<SubGetBase> selectSubStationList(@Param("param") SubstationParam substationParam);
List<String> getLineByDeptIdAndNewStation(@Param("ids") List<String> id,@Param("dictTree")List<String> dictTree); List<String> getLineByDeptIdAndNewStation(@Param("ids") List<String> id,@Param("dictTree")List<String> dictTree);
List<DeptLine> getOnlineMonitor();
} }

View File

@@ -300,4 +300,16 @@
</if> </if>
</where> </where>
</select> </select>
<select id="getOnlineMonitor" resultType="DeptLine">
select
t1.Line_Id lineId,
t1.Id id
from
pq_dept_line t1,
pq_line_detail t2
where
t1.Line_Id = t2.Id and t2.Run_Flag = 0
</select>
</mapper> </mapper>

View File

@@ -160,12 +160,15 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addHeBeiNorthLineWarning(String startTime, String endTime) { public void addHeBeiNorthLineWarning(String startTime, String endTime) {
List<LineWarning> result = new ArrayList<>(); List<LineWarning> result = new ArrayList<>();
List<LineWarning> channelData = new ArrayList<>();
//获取指标集合(10个指标) //获取指标集合(10个指标)
List<DictData> dataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData(); List<DictData> dataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
Map<String, DictData> targetMap = dataList.stream().collect(Collectors.toMap(DictData::getCode, Function.identity())); Map<String, DictData> targetMap = dataList.stream().collect(Collectors.toMap(DictData::getCode, Function.identity()));
//获取监测点和部门表关系 //获取监测点和部门表关系
List<DeptLine> deptLines = deptLineFeignClient.getAllData().getData(); 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); 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; 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)) { if (CollUtil.isNotEmpty(limitTarget)) {
limitTarget.forEach(item -> { 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()); 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(); List<OnlineMonitorVo> list = lineIntegrityClient.getNoData(param).getData();
if (CollUtil.isNotEmpty(list)) { if (CollUtil.isNotEmpty(list)) {
list.forEach(item -> { 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 lineWarning = new LineWarning();
lineWarning.setAlarmTime(firstDayOfMonth); lineWarning.setAlarmTime(firstDayOfMonth);
lineWarning.setDeptId(deptId); lineWarning.setDeptId(deptId);
@@ -220,7 +223,7 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
List<OnlineMonitorVo> list2 = pqDataVerifyCountClient.getAnomalousData(param).getData(); List<OnlineMonitorVo> list2 = pqDataVerifyCountClient.getAnomalousData(param).getData();
if (CollUtil.isNotEmpty(list2)) { if (CollUtil.isNotEmpty(list2)) {
list2.forEach(item -> { 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 lineWarning = new LineWarning();
lineWarning.setAlarmTime(firstDayOfMonth); lineWarning.setAlarmTime(firstDayOfMonth);
lineWarning.setDeptId(deptId); lineWarning.setDeptId(deptId);
@@ -230,9 +233,38 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
result.add(lineWarning); 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 @Override
public Page<OnlineVo> getLineWarningList(OnlineParam param) { public Page<OnlineVo> getLineWarningList(OnlineParam param) {