From 23541bd27e50513897c3ec6756ed9f5286055020 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 15 Oct 2024 16:12:29 +0800 Subject: [PATCH] =?UTF-8?q?modify:=201.=20=E5=A4=84=E7=90=86=E6=80=BB?= =?UTF-8?q?=E8=A7=88=E8=B7=B3=E8=BD=AC=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/UserTaskCreateOrFinishListener.java | 17 +++++- .../pm/api/workbench/manage/WorkbenchManage.java | 69 ++++++++++++++-------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java index e54f5ba..63d657f 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java @@ -74,12 +74,25 @@ public class UserTaskCreateOrFinishListener { @EventListener(classes = NodeCreateEvent.class) public void onEvent(NodeCreateEvent event) { - SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); + SCHEDULER.schedule(() -> { + try { + handleEvent(event); + } catch (Exception e) { + log.error("任务节点创建监听异常:{}", event, e); + } + }, instantDelay10s()); } @EventListener(classes = NodeCompleteEvent.class) public void onEvent(NodeCompleteEvent event) { - SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); + SCHEDULER.schedule(() -> { + try { + handleEvent(event); + + } catch (Exception e) { + log.error("任务节点完成监听异常:{}", event, e); + } + }, instantDelay10s()); } public void handleEvent(NodeCreateEvent event) { diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java index 9d72d38..c7da6da 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/workbench/manage/WorkbenchManage.java @@ -15,7 +15,10 @@ import com.google.common.collect.Sets; import com.hz.pm.api.common.helper.UserInfoHelper; import com.hz.pm.api.common.model.constant.BizConst; import com.hz.pm.api.common.model.constant.ExistsSqlConst; -import com.hz.pm.api.common.statemachine.event.*; +import com.hz.pm.api.common.statemachine.event.AbstractStateChangeEvent; +import com.hz.pm.api.common.statemachine.event.ProjectStateChangeEvent; +import com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent; +import com.hz.pm.api.common.statemachine.event.XcfhxStateChangeEvent; import com.hz.pm.api.common.util.DecimalUtil; import com.hz.pm.api.projectdeclared.model.entity.Contract; import com.hz.pm.api.projectdeclared.model.entity.Purchase; @@ -86,6 +89,10 @@ import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.stream.Collectors; +import static com.hz.pm.api.common.statemachine.event.AdaptStateChangeEvent.ADAPT_INFO_PASSED; +import static com.hz.pm.api.common.statemachine.event.SelfTestStateChangeEvent.SELF_TEST_PASSED; +import static com.hz.pm.api.common.statemachine.event.TenderStateChangeEvent.SUBMIT_PURCHASE_ORG_CONFIRM; +import static com.hz.pm.api.common.statemachine.event.TestValidStateChangeEvent.TEST_VALID_INFO_PASSED; import static com.hz.pm.api.projectlib.helper.ProjectManageUtil.projectQueryByProjectStatusChange; import static com.hz.pm.api.workbench.model.vo.ProjectProcessStatVO.TenderAdaptFinishStatVO; @@ -443,13 +450,13 @@ public class WorkbenchManage { .select(PurchaseStatusChange::getEvent, PurchaseStatusChange::getProjectId) .in(PurchaseStatusChange::getProjectId, projectIds) .in(PurchaseStatusChange::getEvent, - AdaptStateChangeEvent.ADAPT_INFO_PASSED, - SelfTestStateChangeEvent.SELF_TEST_PASSED, - TestValidStateChangeEvent.TEST_VALID_INFO_PASSED, + ADAPT_INFO_PASSED, + SELF_TEST_PASSED, + TEST_VALID_INFO_PASSED, TenderStateChangeEvent.SUBMIT_FIRST_INSPECTED_FILES, XcfhxStateChangeEvent.XCFHX_APPLY_PASSED, TenderStateChangeEvent.FINALLY_INSPECTED_PASSED, - TenderStateChangeEvent.SUBMIT_PURCHASE_ORG_CONFIRM, + SUBMIT_PURCHASE_ORG_CONFIRM, TenderStateChangeEvent.SUBMIT_PURCHASE_CONSTRUCTION_INFO); List purchaseChanges = purchaseStatusChangeService.list(pQuery); Map> purchaseEventMapTmp = purchaseChanges.stream() @@ -461,7 +468,7 @@ public class WorkbenchManage { } break; case PROJECT_ADAPTION: { - List projectIds = computeProjectIds.apply(TenderStateChangeEvent.SUBMIT_PURCHASE_ORG_CONFIRM, node); + List projectIds = computeProjectIds.apply(SUBMIT_PURCHASE_ORG_CONFIRM, node); currStat.setProjectCount(projectIds.size()); Pair replaceSystemCount = countReplaceSystemByProjectIds(projectIds); currStat.setSourceCount(replaceSystemCount.getKey()); @@ -475,7 +482,7 @@ public class WorkbenchManage { .map(Map.Entry::getKey) .collect(Collectors.toList()); if (!tmpProjectIds.isEmpty()) { - currStat.setAdaptFinishStat(tenderAdaptStatistics(tmpProjectIds)); + currStat.setAdaptFinishStat(tenderAdaptStatistics(tmpProjectIds, projectPurchaseCountMap)); } } long finishPurchaseByWithoutApp = CollUtil.count(projectPurchaseCountMap.entrySet(), w -> { @@ -521,26 +528,42 @@ public class WorkbenchManage { return retData; } - private TenderAdaptFinishStatVO tenderAdaptStatistics(List projectIds) { + private TenderAdaptFinishStatVO tenderAdaptStatistics(List projectIds, Map> projectPurchaseCountMap) { Wrapper purchaseQuery = Wrappers.lambdaQuery(PurchaseStatusChange.class) - .select(PurchaseStatusChange::getEvent, PurchaseStatusChange::getBidId) + .select(PurchaseStatusChange::getEvent, PurchaseStatusChange::getBidId, PurchaseStatusChange::getProjectId) .in(PurchaseStatusChange::getProjectId, projectIds) - .in(PurchaseStatusChange::getEvent, AdaptStateChangeEvent.SUBMIT_ADAPT_INFO, - SelfTestStateChangeEvent.SUBMIT_SELF_TEST_INFO, - TestValidStateChangeEvent.SUBMIT_TEST_VALID_INFO, - TenderStateChangeEvent.SUBMIT_PURCHASE_ORG_CONFIRM); + .in(PurchaseStatusChange::getEvent, ADAPT_INFO_PASSED, + SELF_TEST_PASSED, + TEST_VALID_INFO_PASSED, + SUBMIT_PURCHASE_ORG_CONFIRM); List statusChanges = purchaseStatusChangeService.list(purchaseQuery); - Map eventMap = statusChanges.stream() - .collect(Collectors.groupingBy(PurchaseStatusChange::getEvent, - Collectors.collectingAndThen(Collectors.mapping(PurchaseStatusChange::getBidId, Collectors.toSet()), Set::size))); + + Map> projectPurchaseStatusChangeMap = CollUtils.group(statusChanges, PurchaseStatusChange::getProjectId); + TenderAdaptFinishStatVO stat = new TenderAdaptFinishStatVO(); - stat.setFinishTestValidCount(eventMap.getOrDefault(TestValidStateChangeEvent.SUBMIT_TEST_VALID_INFO.name(), 0)); - stat.setFinishAdaptionInfo(eventMap.getOrDefault(AdaptStateChangeEvent.SUBMIT_ADAPT_INFO.name(), 0)); - stat.setFinishOrgConfirmCount(eventMap.getOrDefault(TenderStateChangeEvent.SUBMIT_PURCHASE_ORG_CONFIRM.name(), 0)); - stat.setFinishSelfTestCount(eventMap.getOrDefault(SelfTestStateChangeEvent.SUBMIT_SELF_TEST_INFO.name(), 0)); + stat.setFinishTestValidCount(countAdaptBranchStatus(TEST_VALID_INFO_PASSED, projectIds, projectPurchaseCountMap, projectPurchaseStatusChangeMap)); + stat.setFinishAdaptionInfo(countAdaptBranchStatus(ADAPT_INFO_PASSED, projectIds, projectPurchaseCountMap, projectPurchaseStatusChangeMap)); + stat.setFinishOrgConfirmCount(countAdaptBranchStatus(SUBMIT_PURCHASE_ORG_CONFIRM, projectIds, projectPurchaseCountMap, projectPurchaseStatusChangeMap)); + stat.setFinishSelfTestCount(countAdaptBranchStatus(SELF_TEST_PASSED, projectIds, projectPurchaseCountMap, projectPurchaseStatusChangeMap)); return stat; } + private static int countAdaptBranchStatus(T event, + List projectIds, + Map> projectPurchaseCountMap, + Map> projectPurchaseChangeMap) { + return (int) projectIds.stream().filter(w -> { + int bidCount = CollUtil.count(projectPurchaseCountMap.getOrDefault(w, Collections.emptyList()), + w1 -> BidTypeEnum.BUILD_APP.eq(w1.getBidType())); + List purchaseStatusChanges = projectPurchaseChangeMap.getOrDefault(w, Collections.emptyList()); + int finishedBidCount = purchaseStatusChanges.stream() + .filter(w1 -> w1.getProjectId().equals(w) && event.eq(w1.getEvent())) + .map(PurchaseStatusChange::getBidId) + .collect(Collectors.toSet()).size(); + return finishedBidCount != 0 && finishedBidCount == bidCount; + }).count(); + } + private static int stoppedProjectCount(Map> projectStatusChangeMap, List projectCodes) { return CollUtil.count(projectStatusChangeMap.entrySet(), w -> projectCodes.contains(w.getKey()) @@ -597,17 +620,17 @@ public class WorkbenchManage { case TEST_VALID: query.apply("(select count(1) from nd_purchase np where np.project_id = nd_project.id and bid_type = {0}) " + "= (select count(distinct bid_id) from nd_purchase_status_change npsc where npsc.project_code = nd_project.project_code " + - "and event = {1})", BidTypeEnum.BUILD_APP.getCode(), TestValidStateChangeEvent.TEST_VALID_INFO_PASSED); + "and event = {1})", BidTypeEnum.BUILD_APP.getCode(), TEST_VALID_INFO_PASSED); break; case SELF_TEST: query.apply("(select count(1) from nd_purchase np where np.project_id = nd_project.id and bid_type = {0}) " + "= (select count(distinct bid_id) from nd_purchase_status_change npsc where npsc.project_code = nd_project.project_code " + - "and event = {1})", BidTypeEnum.BUILD_APP.getCode(), SelfTestStateChangeEvent.SELF_TEST_PASSED); + "and event = {1})", BidTypeEnum.BUILD_APP.getCode(), SELF_TEST_PASSED); break; case SUBMIT_START_FILE: query.apply("(select count(1) from nd_purchase np where np.project_id = nd_project.id and bid_type = {0}) " + "= (select count(distinct bid_id) from nd_purchase_status_change npsc where npsc.project_code = nd_project.project_code " + - "and event = {1})", BidTypeEnum.BUILD_APP.getCode(), AdaptStateChangeEvent.ADAPT_INFO_PASSED); + "and event = {1})", BidTypeEnum.BUILD_APP.getCode(), ADAPT_INFO_PASSED); break; default: return PageVo.empty();