fix[project]: 汇总机台、工位的完成率,bugfix

This commit is contained in:
2026-03-31 16:46:17 +08:00
parent bef55800c2
commit ec225a33e5

View File

@@ -486,6 +486,37 @@ public class ProjectServiceImpl extends BaseService implements IProjectService {
}
}
/**
* 从 ProjectNodePo 中递归查找所有某种类型的节点
*/
public static List<NodeAllBase> findAllWorkspaceNodes(ProjectNodePo projectNodePo,String nodeType) {
List<NodeAllBase> result = new ArrayList<>();
if (projectNodePo == null || projectNodePo.children == null) {
return result;
}
// 递归遍历子节点
traverseNodes(projectNodePo.getChildren(), result,nodeType);
return result;
}
/**
* 递归遍历节点树
*/
private static void traverseNodes(List<NodeAllBase> nodes, List<NodeAllBase> 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<TaskNodeTag> 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<NodeAllBase> allWorkspaceNodes = findAllWorkspaceNodes(projectNodePo, NodeTypeEnum.WORKSPACE.getValue());
if (CollectionUtils.isEmpty(allWorkspaceNodes)) {
continue;
}
for (NodeAllBase allWorkspaceNode : allWorkspaceNodes) {
summaryNode((ProjectNodePo) allWorkspaceNode);
}
List<NodeAllBase> 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<NodeAllBase> children) {
if (!NodeTypeEnum.MACHINE.getValue().equals(projectNodePo.getNodeType())) {
List<NodeAllBase> 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<Long> pMemberIds = new HashSet<>();
Set<Long> eMemberIds = new HashSet<>();
Set<Long> attentionIds = new HashSet<>();
Set<Long> tMemberIds = new HashSet<>();
// 递归收集所有子节点的任务和人员
collectTaskAndMembers(projectNodePo, projectNodePo.getChildren(),
pMemberIds, eMemberIds, attentionIds, tMemberIds);
}
/**
* 递归遍历收集:任务数 + 人员
* @param targetNode 要汇总的目标节点(阶段/机台/工位)
* @param children 要遍历的子节点列表
*/
private void collectTaskAndMembers(ProjectNodePo targetNode,
List<NodeAllBase> children,
Set<Long> pMemberIds,
Set<Long> eMemberIds,
Set<Long> attentionIds,
Set<Long> tMemberIds) {
if (CollectionUtils.isEmpty(children)) {
return;
}
List<NodeAllBase> 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<NodeAllBase> 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<NodeAllBase> 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<NodeAllBase> children) {
if (!NodeTypeEnum.WORKSPACE.getValue().equals(projectNodePo.getNodeType())) {
List<NodeAllBase> 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<CIDUserResp> memberList, Set<Long> userIdSet, List<CIDUserResp> targetList) {
if (CollectionUtils.isEmpty(memberList)) {
return;
}
List<NodeAllBase> 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<CIDUserResp> pMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPMemberList())).flatMap(item -> item.getPMemberList().stream().filter(Objects::nonNull)).toList();
List<Long> pMemberIdList = new ArrayList<>();
List<CIDUserResp> 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<CIDUserResp> eMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getEMemberList())).flatMap(item -> item.getEMemberList().stream().filter(Objects::nonNull)).toList();
List<Long> eMemberIdList = new ArrayList<>();
List<CIDUserResp> 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<CIDUserResp> attionMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPayAttentionMemberList())).flatMap(item -> item.getPayAttentionMemberList().stream().filter(Objects::nonNull)).toList();
List<Long> attiionMemberIdList = new ArrayList<>();
List<CIDUserResp> 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<CIDUserResp> tMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getTMemberList())).flatMap(item -> item.getTMemberList().stream().filter(Objects::nonNull)).toList();
List<Long> tMemberIdList = new ArrayList<>();
List<CIDUserResp> 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<NodeAllBase> eachChildren = child.getChildren();
if (CollectionUtils.isEmpty(eachChildren)) {
for (CIDUserResp user : memberList) {
if (user == null || user.getUserId() == null) {
continue;
}
List<NodeAllBase> 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<NodeAllBase> children) {
// if (!NodeTypeEnum.WORKSPACE.getValue().equals(projectNodePo.getNodeType())) {
// List<NodeAllBase> 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<NodeAllBase> 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<CIDUserResp> pMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPMemberList())).flatMap(item -> item.getPMemberList().stream().filter(Objects::nonNull)).toList();
// List<Long> pMemberIdList = new ArrayList<>();
// List<CIDUserResp> 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<CIDUserResp> eMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getEMemberList())).flatMap(item -> item.getEMemberList().stream().filter(Objects::nonNull)).toList();
// List<Long> eMemberIdList = new ArrayList<>();
// List<CIDUserResp> 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<CIDUserResp> attionMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getPayAttentionMemberList())).flatMap(item -> item.getPayAttentionMemberList().stream().filter(Objects::nonNull)).toList();
// List<Long> attiionMemberIdList = new ArrayList<>();
// List<CIDUserResp> 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<CIDUserResp> tMemberList = taskChildren.stream().filter(node -> CollectionUtils.isNotEmpty(node.getTMemberList())).flatMap(item -> item.getTMemberList().stream().filter(Objects::nonNull)).toList();
// List<Long> tMemberIdList = new ArrayList<>();
// List<CIDUserResp> 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<NodeAllBase> eachChildren = child.getChildren();
// if (CollectionUtils.isEmpty(eachChildren)) {
// continue;
// }
// List<NodeAllBase> 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();