diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ModuleTreeService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ModuleTreeService.java index 2fef605aef..73938dd369 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ModuleTreeService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ModuleTreeService.java @@ -59,6 +59,13 @@ public abstract class ModuleTreeService { } int lastSize = 0; Map baseTreeNodeMap = new HashMap<>(); + + // 根节点预先处理 + baseTreeNodeList.addAll(traverseList.stream().filter(treeNode -> StringUtils.equalsIgnoreCase(treeNode.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)).toList()); + baseTreeNodeList.forEach(item -> baseTreeNodeMap.put(item.getId(), item)); + traverseList = (List) CollectionUtils.removeAll(traverseList, baseTreeNodeList); + + // 循环处理子节点 while (CollectionUtils.isNotEmpty(traverseList) && traverseList.size() != lastSize) { lastSize = traverseList.size(); List notMatchedList = new ArrayList<>();