From 872fbeb9a2360a8154a4cca76bbd1a8e32f784eb Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Wed, 22 Nov 2023 10:00:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E5=8F=B0=20=E9=A2=84?= =?UTF-8?q?=E8=AD=A6=20=E5=82=AC=E5=8A=9E=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/task/EarlyWarningProjectTask.java | 45 ++++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) 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) {