From 97f35481130ad5db820da8e28c105e6f794995e9 Mon Sep 17 00:00:00 2001 From: CMM <2198256324@qq.com> Date: Sat, 31 Aug 2024 19:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=AD=A6=E9=A1=B9=E7=9B=AE=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A0=A1=E9=AA=8C=E4=BB=BB=E5=8A=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/task/EarlyWarningProjectTask.java | 75 ++++++++++++++++------ .../com/hz/pm/api/warning/DelayWarningTest.java | 43 +++++++------ 2 files changed, 78 insertions(+), 40 deletions(-) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java index 09a576b..61d9b72 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/task/EarlyWarningProjectTask.java @@ -58,7 +58,7 @@ public class EarlyWarningProjectTask { private final IPurchaseStatusChangeService purchaseStatusChangeService; @Scheduled(fixedDelay = 5, initialDelay = 5, timeUnit = TimeUnit.MINUTES) - public void doEarlyWarningDeclared() { + public void doEarlyWarningDelayed() { log.info("=========== 预警项目状态校验任务开始 ==========="); StopWatch stopWatch = new StopWatch(); stopWatch.start(); @@ -94,22 +94,46 @@ public class EarlyWarningProjectTask { 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); + //@Scheduled(fixedDelay = 5, initialDelay = 5, timeUnit = TimeUnit.MINUTES) + public void doEarlyWarningDeclared() { + log.info("=========== 预警项目状态校验任务开始 ==========="); + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + List projects = projectService.list(Wrappers.lambdaQuery(Project.class) + .eq(Project::getNewest, Boolean.TRUE)); - // 3.2 填报预警 如果正常了 要改会正常 - List declaredWarning = trueWarnings.stream().filter(w -> - Objects.nonNull(w.getDeclaredWarning()) - && w.getDeclaredWarning()) + if (CollUtil.isEmpty(projects)) { + 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 toRemove = warnings.stream() + .filter(w -> !projectMap.containsKey(w.getProjectCode())) .collect(Collectors.toList()); - checkDeclaredWarning(declaredWarning); + if (CollUtil.isNotEmpty(toRemove)) { + List removeIds = toRemove.stream().map(ProjectEarlyWarning::getId) + .collect(Collectors.toList()); + projectEarlyWarningService.removeBatchByIds(removeIds); + } + + // 去查询 各个报警 是否已经正常 + List trueWarnings = warnings.stream().filter(w -> Objects.nonNull(w.getNormal()) && !w.getNormal()).collect(Collectors.toList()); + if (CollUtil.isEmpty(trueWarnings)) { + return; + } + checkNormal(trueWarnings); + stopWatch.stop(); + log.info("=========== 预警项目状态校验任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); + } - // 3.3 滞后预警 如果正常了 要改会正常 + // 3.去查询 各个报警 是否已经正常 + private void checkNormal(List trueWarnings) { + // 滞后预警 如果正常了 要改回正常 List delayWarning = trueWarnings.stream().filter(w -> Objects.nonNull(w.getDelayWarning()) && w.getDelayWarning()) @@ -144,9 +168,8 @@ public class EarlyWarningProjectTask { // 已经不是这个状态了 说明已经被提交了 if (!projectStatus.eq(project.getStatus())) { checkCommited(delay, flowTypeEnum, projectCode); - // 其它几种 都没有 说明已经正常了 - if (Boolean.FALSE.equals(delay.getProcessWarning()) && - Boolean.FALSE.equals(delay.getDeclaredWarning())) { + // 如果滞后预警正常了 改回正常 + if (Boolean.FALSE.equals(delay.getDelayWarning())){ delay.setNormal(Boolean.TRUE); delay.setStatus(ProjectEarlyWarningStatusEnum.NORMAL.name()); } @@ -202,7 +225,11 @@ public class EarlyWarningProjectTask { ProjectStatusChange projectStatusChange = projectStatusChangeService.getLastOne(projectCode, events); // 说明进行了采购&合同信息备案 if (Objects.nonNull(projectStatusChange)) { - warning.setDeclaredWarning(Boolean.FALSE); + if (WarningRuleTypeEnum.DECLARED_WARNING.getCode().equals(warning.getRuleType())) { + warning.setDeclaredWarning(Boolean.FALSE); + }else if (WarningRuleTypeEnum.DELAY_WARNING.getCode().equals(warning.getRuleType())){ + warning.setDelayWarning(Boolean.FALSE); + } } } break; @@ -213,7 +240,11 @@ public class EarlyWarningProjectTask { PurchaseStatusChange purchaseStatusChange = purchaseStatusChangeService.getLastOne(projectCode, events); // 说明进行了单位确认 if (Objects.nonNull(purchaseStatusChange)) { - warning.setDeclaredWarning(Boolean.FALSE); + if (WarningRuleTypeEnum.DECLARED_WARNING.getCode().equals(warning.getRuleType())) { + warning.setDeclaredWarning(Boolean.FALSE); + }else if (WarningRuleTypeEnum.DELAY_WARNING.getCode().equals(warning.getRuleType())){ + warning.setDelayWarning(Boolean.FALSE); + } } } @@ -225,7 +256,11 @@ public class EarlyWarningProjectTask { ProjectStatusChange projectStatusChange = projectStatusChangeService.getLastOne(projectCode, events); // 说明提交了终验申请 if (Objects.nonNull(projectStatusChange)) { - warning.setDeclaredWarning(Boolean.FALSE); + if (WarningRuleTypeEnum.DECLARED_WARNING.getCode().equals(warning.getRuleType())) { + warning.setDeclaredWarning(Boolean.FALSE); + }else if (WarningRuleTypeEnum.DELAY_WARNING.getCode().equals(warning.getRuleType())){ + warning.setDelayWarning(Boolean.FALSE); + } } } break; diff --git a/hz-pm-api/src/test/java/com/hz/pm/api/warning/DelayWarningTest.java b/hz-pm-api/src/test/java/com/hz/pm/api/warning/DelayWarningTest.java index c362d6b..46aa3fc 100644 --- a/hz-pm-api/src/test/java/com/hz/pm/api/warning/DelayWarningTest.java +++ b/hz-pm-api/src/test/java/com/hz/pm/api/warning/DelayWarningTest.java @@ -229,6 +229,9 @@ public class DelayWarningTest extends AppTests { @Test public void two(){ + log.info("=========== 预警项目状态校验任务开始 ==========="); + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); List projects = projectService.list(Wrappers.lambdaQuery(Project.class) .eq(Project::getNewest, Boolean.TRUE)); @@ -257,6 +260,8 @@ public class DelayWarningTest extends AppTests { return; } checkNormal(trueWarnings); + stopWatch.stop(); + log.info("=========== 预警项目状态校验任务结束 耗时{}s", stopWatch.getTotalTimeSeconds()); } private long getDurationTime(LocalDateTime touchTime, LocalDateTime now, ChronoUnit timeUnit) { @@ -265,20 +270,7 @@ public class DelayWarningTest extends AppTests { // 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); - - // 3.2 填报预警 如果正常了 要改会正常 - List declaredWarning = trueWarnings.stream().filter(w -> - Objects.nonNull(w.getDeclaredWarning()) - && w.getDeclaredWarning()) - .collect(Collectors.toList()); - checkDeclaredWarning(declaredWarning); - - // 3.3 滞后预警 如果正常了 要改会正常 + // 滞后预警 如果正常了 要改回正常 List delayWarning = trueWarnings.stream().filter(w -> Objects.nonNull(w.getDelayWarning()) && w.getDelayWarning()) @@ -313,9 +305,8 @@ public class DelayWarningTest extends AppTests { // 已经不是这个状态了 说明已经被提交了 if (!projectStatus.eq(project.getStatus())) { checkCommited(delay, flowTypeEnum, projectCode); - // 其它几种 都没有 说明已经正常了 - if (Boolean.FALSE.equals(delay.getProcessWarning()) && - Boolean.FALSE.equals(delay.getDeclaredWarning())) { + // 如果滞后预警正常了 改回正常 + if (Boolean.FALSE.equals(delay.getDelayWarning())){ delay.setNormal(Boolean.TRUE); delay.setStatus(ProjectEarlyWarningStatusEnum.NORMAL.name()); } @@ -371,7 +362,11 @@ public class DelayWarningTest extends AppTests { ProjectStatusChange projectStatusChange = projectStatusChangeService.getLastOne(projectCode, events); // 说明进行了采购&合同信息备案 if (Objects.nonNull(projectStatusChange)) { - warning.setDeclaredWarning(Boolean.FALSE); + if (WarningRuleTypeEnum.DECLARED_WARNING.getCode().equals(warning.getRuleType())) { + warning.setDeclaredWarning(Boolean.FALSE); + }else if (WarningRuleTypeEnum.DELAY_WARNING.getCode().equals(warning.getRuleType())){ + warning.setDelayWarning(Boolean.FALSE); + } } } break; @@ -382,7 +377,11 @@ public class DelayWarningTest extends AppTests { PurchaseStatusChange purchaseStatusChange = purchaseStatusChangeService.getLastOne(projectCode, events); // 说明进行了单位确认 if (Objects.nonNull(purchaseStatusChange)) { - warning.setDeclaredWarning(Boolean.FALSE); + if (WarningRuleTypeEnum.DECLARED_WARNING.getCode().equals(warning.getRuleType())) { + warning.setDeclaredWarning(Boolean.FALSE); + }else if (WarningRuleTypeEnum.DELAY_WARNING.getCode().equals(warning.getRuleType())){ + warning.setDelayWarning(Boolean.FALSE); + } } } @@ -394,7 +393,11 @@ public class DelayWarningTest extends AppTests { ProjectStatusChange projectStatusChange = projectStatusChangeService.getLastOne(projectCode, events); // 说明提交了终验申请 if (Objects.nonNull(projectStatusChange)) { - warning.setDeclaredWarning(Boolean.FALSE); + if (WarningRuleTypeEnum.DECLARED_WARNING.getCode().equals(warning.getRuleType())) { + warning.setDeclaredWarning(Boolean.FALSE); + }else if (WarningRuleTypeEnum.DELAY_WARNING.getCode().equals(warning.getRuleType())){ + warning.setDelayWarning(Boolean.FALSE); + } } } break;