diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningProjectTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningProjectTask.java index 85676ee..f003f65 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningProjectTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/EarlyWarningProjectTask.java @@ -3,6 +3,7 @@ package com.ningdatech.pmapi.scheduler.task; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.StopWatch; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Sets; import com.ningdatech.pmapi.common.constant.BizConst; import com.ningdatech.pmapi.projectlib.enumeration.ProjectRenewalApprovalStatusEnum; import com.ningdatech.pmapi.projectlib.enumeration.WarningFlowTypeEnum; @@ -29,7 +30,9 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.time.LocalDateTime; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; /** @@ -74,6 +77,10 @@ public class EarlyWarningProjectTask { log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); return; } + + Set projectSet = Sets.newHashSet(); + Map projectMap = projects.stream().filter(p -> projectSet.add(p.getProjectCode())) + .collect(Collectors.toMap(Project::getProjectCode, p -> p)); List warnings = projectEarlyWarningService.list(); List warningProjectCodes = warnings.stream().map(ProjectEarlyWarning::getProjectCode) .collect(Collectors.toList()); @@ -105,7 +112,17 @@ public class EarlyWarningProjectTask { projectEarlyWarningService.saveBatch(toAdd); } - //2.去查询 各个报警 是否已经正常 + //2.删除 已经不存在的项目 + List toRemove = warnings.stream() + .filter(w -> !projectMap.containsKey(w.getProjectCode())) + .collect(Collectors.toList()); + if(CollUtil.isNotEmpty(toRemove)){ + List removeIds = toRemove.stream().map(ProjectEarlyWarning::getId) + .collect(Collectors.toList()); + projectEarlyWarningService.removeBatchByIds(removeIds); + } + + //3.去查询 各个报警 是否已经正常 List trueWarnings = warnings.stream().filter(w -> Objects.nonNull(w.getNormal()) && !w.getNormal()).collect(Collectors.toList()); if(CollUtil.isEmpty(trueWarnings)){ log.info("没有异常的项目 要去查询"); @@ -113,36 +130,40 @@ public class EarlyWarningProjectTask { log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); return; } - //2.1 预警预警 如果正常了 要改会正常 + checkNormal(trueWarnings); + + stopWatch.stop(); + log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); + } + + //3.去查询 各个报警 是否已经正常 + private void checkNormal(List trueWarnings) { + //3.1 预警预警 如果正常了 要改会正常 List processWarning = trueWarnings.stream().filter(w -> Objects.nonNull(w.getProcessWarning()) && w.getProcessWarning()) .collect(Collectors.toList()); checkProcessWarning(processWarning); - //2.2 填报预警 如果正常了 要改会正常 + //3.2 填报预警 如果正常了 要改会正常 List declaredWarning = trueWarnings.stream().filter(w -> Objects.nonNull(w.getDeclaredWarning()) - && w.getDeclaredWarning()) + && w.getDeclaredWarning()) .collect(Collectors.toList()); checkDeclaredWarning(declaredWarning); - //2.3 实施预警 如果正常了 要改会正常 + //3.3 实施预警 如果正常了 要改会正常 List operationWarning = trueWarnings.stream().filter(w -> Objects.nonNull(w.getOperationWarning()) - && w.getOperationWarning()) + && w.getOperationWarning()) .collect(Collectors.toList()); checkOperationWarning(operationWarning); - //2.4 续建资金预警 如果正常了 要改会正常 + //3.4 续建资金预警 如果正常了 要改回正常 List renewalFundWarning = trueWarnings.stream().filter(w -> Objects.nonNull(w.getRenewalFundWarning()) - && w.getRenewalFundWarning()) + && w.getRenewalFundWarning()) .collect(Collectors.toList()); checkRenewalFundWarning(renewalFundWarning); - - - stopWatch.stop(); - log.info("=========== 预警项目维度任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); } private void checkRenewalFundWarning(List renewalFundWarnings) {