From e83985a2f547d4622341052c8837e762b8bf39b4 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Thu, 5 Dec 2024 15:34:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9F=BA=E7=A1=80=E7=BB=84=E4=BB=B6):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=81=8D=E5=8E=86=E6=9E=84=E9=80=A0=E6=A0=91?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes 34521 --- .../io/metersphere/project/service/ModuleTreeService.java | 7 +++++++ 1 file changed, 7 insertions(+) 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<>();