From ec225a33e5087c0ee06224c84cf7679596088a45 Mon Sep 17 00:00:00 2001 From: lidongyang <506508008@qq.com> Date: Tue, 31 Mar 2026 16:46:17 +0800 Subject: [PATCH] =?UTF-8?q?fix[project]:=20=E6=B1=87=E6=80=BB=E6=9C=BA?= =?UTF-8?q?=E5=8F=B0=E3=80=81=E5=B7=A5=E4=BD=8D=E7=9A=84=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E7=8E=87=EF=BC=8Cbugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ProjectServiceImpl.java | 320 +++++++++++------- 1 file changed, 206 insertions(+), 114 deletions(-) diff --git a/project/src/main/java/com/sdm/project/service/impl/ProjectServiceImpl.java b/project/src/main/java/com/sdm/project/service/impl/ProjectServiceImpl.java index 195f5cc6..e6f3d1ea 100644 --- a/project/src/main/java/com/sdm/project/service/impl/ProjectServiceImpl.java +++ b/project/src/main/java/com/sdm/project/service/impl/ProjectServiceImpl.java @@ -486,6 +486,37 @@ public class ProjectServiceImpl extends BaseService implements IProjectService { } } + /** + * 从 ProjectNodePo 中递归查找所有某种类型的节点 + */ + public static List findAllWorkspaceNodes(ProjectNodePo projectNodePo,String nodeType) { + List result = new ArrayList<>(); + if (projectNodePo == null || projectNodePo.children == null) { + return result; + } + // 递归遍历子节点 + traverseNodes(projectNodePo.getChildren(), result,nodeType); + return result; + } + + /** + * 递归遍历节点树 + */ + private static void traverseNodes(List nodes, List result,String nodeType) { + if (nodes == null || nodes.isEmpty()) { + return; + } + + for (NodeAllBase node : nodes) { + // 判断当前节点是否是nodeType类型的节点 + if (nodeType.equals(node.getNodeType())) { + result.add(node); + } + // 递归遍历子节点 + traverseNodes(node.getChildren(), result,nodeType); + } + } + @Override public SdmResponse getTaskTree(ProjectTreeTagReq req) { List idMapList = req.getIdMap(); @@ -677,10 +708,22 @@ public class ProjectServiceImpl extends BaseService implements IProjectService { dataMap,taskExtraMap,performanceExtraList,nodeExtraList,flowTemplateRespMap,reportTemplateRespMap); addedIdList.clear(); } - // 汇总任务进度、仿真负责人、执行人 + // 汇总机台和工位的任务进度、仿真负责人、执行人 for (ProjectNodePo projectNodePo : realTopProjectNodeList) { - summaryWorkspaceNode(projectNodePo,projectNodePo.getChildren()); - summaryMachineNode(projectNodePo,projectNodePo.getChildren()); + List allWorkspaceNodes = findAllWorkspaceNodes(projectNodePo, NodeTypeEnum.WORKSPACE.getValue()); + if (CollectionUtils.isEmpty(allWorkspaceNodes)) { + continue; + } + for (NodeAllBase allWorkspaceNode : allWorkspaceNodes) { + summaryNode((ProjectNodePo) allWorkspaceNode); + } + List allMachineNodes = findAllWorkspaceNodes(projectNodePo, NodeTypeEnum.MACHINE.getValue()); + if (CollectionUtils.isEmpty(allMachineNodes)) { + continue; + } + for (NodeAllBase allMachineNode : allMachineNodes) { + summaryNode((ProjectNodePo) allMachineNode); + } } // 对工位进行排序,-M工位顺序排第一个 if (lyricFlag == 1) { @@ -769,134 +812,183 @@ public class ProjectServiceImpl extends BaseService implements IProjectService { } } - private void summaryMachineNode(ProjectNodePo projectNodePo,List children) { - if (!NodeTypeEnum.MACHINE.getValue().equals(projectNodePo.getNodeType())) { - List fChildren = projectNodePo.getChildren(); - if (CollectionUtils.isEmpty(fChildren)) { - return; - } - for (NodeAllBase fChild : fChildren) { - if (!NodeTypeEnum.WORKSPACE.getValue().equals(fChild.getNodeType()) && !NodeTypeEnum.TASK.getValue().equals(fChild.getNodeType()) && !NodeTypeEnum.PERFORMANCE.getValue().equals(fChild.getNodeType())) { - summaryMachineNode((ProjectNodePo) fChild,fChild.getChildren()); - } - } - } + + private void summaryNode(ProjectNodePo projectNodePo) { + // 初始化当前节点统计数据 + projectNodePo.setTotalTaskNum(0); + projectNodePo.setFinishTaskNum(0); + projectNodePo.setPMemberList(new ArrayList<>()); + projectNodePo.setEMemberList(new ArrayList<>()); + projectNodePo.setPayAttentionMemberList(new ArrayList<>()); + projectNodePo.setTMemberList(new ArrayList<>()); + + // 全局去重ID集合 + Set pMemberIds = new HashSet<>(); + Set eMemberIds = new HashSet<>(); + Set attentionIds = new HashSet<>(); + Set tMemberIds = new HashSet<>(); + + // 递归收集所有子节点的任务和人员 + collectTaskAndMembers(projectNodePo, projectNodePo.getChildren(), + pMemberIds, eMemberIds, attentionIds, tMemberIds); + } + + /** + * 递归遍历收集:任务数 + 人员 + * @param targetNode 要汇总的目标节点(阶段/机台/工位) + * @param children 要遍历的子节点列表 + */ + private void collectTaskAndMembers(ProjectNodePo targetNode, + List children, + Set pMemberIds, + Set eMemberIds, + Set attentionIds, + Set tMemberIds) { + if (CollectionUtils.isEmpty(children)) { return; } - List workspaceChildren = children.stream().filter(node -> NodeTypeEnum.WORKSPACE.getValue().equals(node.getNodeType())).toList(); - if (CollectionUtils.isEmpty(workspaceChildren)) { - return; - } - projectNodePo.setFinishTaskNum(projectNodePo.getFinishTaskNum() + workspaceChildren.stream().filter(node -> ObjectUtils.isNotEmpty(node.getFinishTaskNum())).mapToLong(NodeAllBase::getFinishTaskNum).sum()); - projectNodePo.setTotalTaskNum(projectNodePo.getTotalTaskNum() + workspaceChildren.stream().filter(node -> ObjectUtils.isNotEmpty(node.getTotalTaskNum())).mapToLong(NodeAllBase::getTotalTaskNum).sum()); - for (NodeAllBase child : children) { - List eachChildren = child.getChildren(); - if (CollectionUtils.isEmpty(eachChildren)) { + + for (NodeAllBase node : children) { + // ====================== 1. 遇到任务节点:直接统计 ====================== + if (NodeTypeEnum.TASK.getValue().equals(node.getNodeType())) { + // 总任务数 +1 + targetNode.setTotalTaskNum(targetNode.getTotalTaskNum() + 1); + // 完成任务数判断 + if (TaskExeStatusEnum.COMPLETED.getCode().equals(node.getExeStatus())) { + targetNode.setFinishTaskNum(targetNode.getFinishTaskNum() + 1); + } + + // 收集人员信息 + addDistinctMembers(node.getPMemberList(), pMemberIds, targetNode.getPMemberList()); + addDistinctMembers(node.getEMemberList(), eMemberIds, targetNode.getEMemberList()); + addDistinctMembers(node.getPayAttentionMemberList(), attentionIds, targetNode.getPayAttentionMemberList()); + addDistinctMembers(node.getTMemberList(), tMemberIds, targetNode.getTMemberList()); + continue; } - List eachWorkspaceChildren = eachChildren.stream().filter(node -> NodeTypeEnum.WORKSPACE.getValue().equals(node.getNodeType())).toList(); - if (CollectionUtils.isEmpty(eachWorkspaceChildren)) { - continue; + + // ====================== 2. 非任务、非指标节点:继续递归下级 ====================== + if (!NodeTypeEnum.PERFORMANCE.getValue().equals(node.getNodeType())) { + collectTaskAndMembers(targetNode, node.getChildren(), + pMemberIds, eMemberIds, attentionIds, tMemberIds); } - summaryMachineNode(projectNodePo,eachWorkspaceChildren); } } - private void summaryWorkspaceNode(ProjectNodePo projectNodePo,List children) { - if (!NodeTypeEnum.WORKSPACE.getValue().equals(projectNodePo.getNodeType())) { - List fChildren = projectNodePo.getChildren(); - if (CollectionUtils.isEmpty(fChildren)) { - return; - } - for (NodeAllBase fChild : fChildren) { - if (!NodeTypeEnum.TASK.getValue().equals(fChild.getNodeType()) && !NodeTypeEnum.PERFORMANCE.getValue().equals(fChild.getNodeType())) { - summaryWorkspaceNode((ProjectNodePo) fChild,fChild.getChildren()); - } - } - } - if (CollectionUtils.isEmpty(children)) { + /** + * 人员去重工具方法:根据userId全局去重,只添加一次 + */ + private void addDistinctMembers(List memberList, Set userIdSet, List targetList) { + if (CollectionUtils.isEmpty(memberList)) { return; } - List taskChildren = children.stream().filter(node -> NodeTypeEnum.TASK.getValue().equals(node.getNodeType())).toList(); - if (CollectionUtils.isEmpty(taskChildren)) { - return; - } - projectNodePo.setFinishTaskNum(projectNodePo.getFinishTaskNum() + taskChildren.stream() - .filter(node -> TaskExeStatusEnum.COMPLETED.getCode().equals(node.getExeStatus())).count()); - projectNodePo.setTotalTaskNum(projectNodePo.getTotalTaskNum() + taskChildren.size()); - List pMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPMemberList())).flatMap(item -> item.getPMemberList().stream().filter(Objects::nonNull)).toList(); - List pMemberIdList = new ArrayList<>(); - List distinctPMemberList = projectNodePo.getPMemberList(); - if (CollectionUtils.isNotEmpty(pMemberList)) { - for (CIDUserResp cidUserResp : pMemberList) { - if (pMemberIdList.contains(cidUserResp.getUserId())) { - continue; - } - distinctPMemberList.add(cidUserResp); - pMemberIdList.add(cidUserResp.getUserId()); - } - } - List eMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getEMemberList())).flatMap(item -> item.getEMemberList().stream().filter(Objects::nonNull)).toList(); - List eMemberIdList = new ArrayList<>(); - List distinctEMemberList = projectNodePo.getEMemberList(); - if (CollectionUtils.isNotEmpty(eMemberList)) { - for (CIDUserResp cidUserResp : eMemberList) { - if (eMemberIdList.contains(cidUserResp.getUserId())) { - continue; - } - distinctEMemberList.add(cidUserResp); - eMemberIdList.add(cidUserResp.getUserId()); - } - } - // 仿真关注人 - List attionMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPayAttentionMemberList())).flatMap(item -> item.getPayAttentionMemberList().stream().filter(Objects::nonNull)).toList(); - List attiionMemberIdList = new ArrayList<>(); - List distinctAttionMemberList = projectNodePo.getPayAttentionMemberList(); - if (CollectionUtils.isNotEmpty(attiionMemberIdList)) { - for (CIDUserResp cidUserResp : attionMemberList) { - if (attiionMemberIdList.contains(cidUserResp.getUserId())) { - continue; - } - distinctAttionMemberList.add(cidUserResp); - attiionMemberIdList.add(cidUserResp.getUserId()); - } - } - - // 3D负责人 - List tMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getTMemberList())).flatMap(item -> item.getTMemberList().stream().filter(Objects::nonNull)).toList(); - List tMemberIdList = new ArrayList<>(); - List distinctTMemberList = projectNodePo.getPayAttentionMemberList(); - if (CollectionUtils.isNotEmpty(tMemberIdList)) { - for (CIDUserResp cidUserResp : tMemberList) { - if (tMemberIdList.contains(cidUserResp.getUserId())) { - continue; - } - distinctTMemberList.add(cidUserResp); - tMemberIdList.add(cidUserResp.getUserId()); - } - } - - projectNodePo.setPMemberList(distinctPMemberList); - projectNodePo.setEMemberList(distinctEMemberList); - // 仿真关注人 - projectNodePo.setPayAttentionMemberList(distinctAttionMemberList); - // 3D负责人 - projectNodePo.setTMemberList(distinctTMemberList); - - for (NodeAllBase child : children) { - List eachChildren = child.getChildren(); - if (CollectionUtils.isEmpty(eachChildren)) { + for (CIDUserResp user : memberList) { + if (user == null || user.getUserId() == null) { continue; } - List eachTaskChildren = eachChildren.stream().filter(node -> NodeTypeEnum.TASK.getValue().equals(node.getNodeType())).toList(); - if (CollectionUtils.isEmpty(eachTaskChildren)) { - continue; + // 不存在则添加,保证去重 + if (!userIdSet.contains(user.getUserId())) { + userIdSet.add(user.getUserId()); + targetList.add(user); } - summaryWorkspaceNode(projectNodePo,eachTaskChildren); } } +// private void summaryWorkspaceNode(ProjectNodePo projectNodePo,List children) { +// if (!NodeTypeEnum.WORKSPACE.getValue().equals(projectNodePo.getNodeType())) { +// List fChildren = projectNodePo.getChildren(); +// if (CollectionUtils.isEmpty(fChildren)) { +// return; +// } +// for (NodeAllBase fChild : fChildren) { +// if (!NodeTypeEnum.TASK.getValue().equals(fChild.getNodeType()) && !NodeTypeEnum.PERFORMANCE.getValue().equals(fChild.getNodeType())) { +// summaryWorkspaceNode((ProjectNodePo) fChild,fChild.getChildren()); +// } +// } +// } +// if (CollectionUtils.isEmpty(children)) { +// return; +// } +// List taskChildren = children.stream().filter(node -> NodeTypeEnum.TASK.getValue().equals(node.getNodeType())).toList(); +// if (CollectionUtils.isEmpty(taskChildren)) { +// return; +// } +// projectNodePo.setFinishTaskNum(projectNodePo.getFinishTaskNum() + taskChildren.stream() +// .filter(node -> TaskExeStatusEnum.COMPLETED.getCode().equals(node.getExeStatus())).count()); +// projectNodePo.setTotalTaskNum(projectNodePo.getTotalTaskNum() + taskChildren.size()); +// List pMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPMemberList())).flatMap(item -> item.getPMemberList().stream().filter(Objects::nonNull)).toList(); +// List pMemberIdList = new ArrayList<>(); +// List distinctPMemberList = projectNodePo.getPMemberList(); +// if (CollectionUtils.isNotEmpty(pMemberList)) { +// for (CIDUserResp cidUserResp : pMemberList) { +// if (pMemberIdList.contains(cidUserResp.getUserId())) { +// continue; +// } +// distinctPMemberList.add(cidUserResp); +// pMemberIdList.add(cidUserResp.getUserId()); +// } +// } +// List eMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getEMemberList())).flatMap(item -> item.getEMemberList().stream().filter(Objects::nonNull)).toList(); +// List eMemberIdList = new ArrayList<>(); +// List distinctEMemberList = projectNodePo.getEMemberList(); +// if (CollectionUtils.isNotEmpty(eMemberList)) { +// for (CIDUserResp cidUserResp : eMemberList) { +// if (eMemberIdList.contains(cidUserResp.getUserId())) { +// continue; +// } +// distinctEMemberList.add(cidUserResp); +// eMemberIdList.add(cidUserResp.getUserId()); +// } +// } +// // 仿真关注人 +// List attionMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPayAttentionMemberList())).flatMap(item -> item.getPayAttentionMemberList().stream().filter(Objects::nonNull)).toList(); +// List attiionMemberIdList = new ArrayList<>(); +// List distinctAttionMemberList = projectNodePo.getPayAttentionMemberList(); +// if (CollectionUtils.isNotEmpty(attiionMemberIdList)) { +// for (CIDUserResp cidUserResp : attionMemberList) { +// if (attiionMemberIdList.contains(cidUserResp.getUserId())) { +// continue; +// } +// distinctAttionMemberList.add(cidUserResp); +// attiionMemberIdList.add(cidUserResp.getUserId()); +// } +// } +// +// // 3D负责人 +// List tMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getTMemberList())).flatMap(item -> item.getTMemberList().stream().filter(Objects::nonNull)).toList(); +// List tMemberIdList = new ArrayList<>(); +// List distinctTMemberList = projectNodePo.getPayAttentionMemberList(); +// if (CollectionUtils.isNotEmpty(tMemberIdList)) { +// for (CIDUserResp cidUserResp : tMemberList) { +// if (tMemberIdList.contains(cidUserResp.getUserId())) { +// continue; +// } +// distinctTMemberList.add(cidUserResp); +// tMemberIdList.add(cidUserResp.getUserId()); +// } +// } +// +// projectNodePo.setPMemberList(distinctPMemberList); +// projectNodePo.setEMemberList(distinctEMemberList); +// // 仿真关注人 +// projectNodePo.setPayAttentionMemberList(distinctAttionMemberList); +// // 3D负责人 +// projectNodePo.setTMemberList(distinctTMemberList); +// +// for (NodeAllBase child : children) { +// List eachChildren = child.getChildren(); +// if (CollectionUtils.isEmpty(eachChildren)) { +// continue; +// } +// List eachTaskChildren = eachChildren.stream().filter(node -> NodeTypeEnum.TASK.getValue().equals(node.getNodeType())).toList(); +// if (CollectionUtils.isEmpty(eachTaskChildren)) { +// continue; +// } +// summaryWorkspaceNode(projectNodePo,eachTaskChildren); +// } +// } + private int getCurrentNodeDepth(NodeAllBase eachNode) { String tag1 = eachNode.getTag1(); String tag2 = eachNode.getTag2();