From 7ab276d3b90c6d63966e82867a83eb461211b06c Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 25 Jan 2024 17:41:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=A8=A1=E5=9D=97=E6=A0=91=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=A8=A1=E5=9D=97=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=95=B0=E6=8D=AE=E7=9A=84=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/service/ModuleTreeService.java | 21 ++++++++++--------- .../system/dto/sdk/BaseTreeNode.java | 11 ++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) 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 12122687a4..c399c29189 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 @@ -67,6 +67,7 @@ public abstract class ModuleTreeService { List baseTreeNodeList = new ArrayList<>(); if (haveVirtualRootNode) { BaseTreeNode defaultNode = this.getDefaultModule(virtualRootName); + defaultNode.genModulePath(null); baseTreeNodeList.add(defaultNode); } int lastSize = 0; @@ -75,18 +76,18 @@ public abstract class ModuleTreeService { lastSize = traverseList.size(); List notMatchedList = new ArrayList<>(); for (BaseTreeNode treeNode : traverseList) { + if (!baseTreeNodeMap.containsKey(treeNode.getParentId()) && !StringUtils.equals(treeNode.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) { + notMatchedList.add(treeNode); + continue; + } + BaseTreeNode node = new BaseTreeNode(treeNode.getId(), treeNode.getName(), treeNode.getType(), treeNode.getParentId()); + node.genModulePath(baseTreeNodeMap.get(treeNode.getParentId())); + baseTreeNodeMap.put(treeNode.getId(), node); + if (StringUtils.equalsIgnoreCase(treeNode.getParentId(), ModuleConstants.ROOT_NODE_PARENT_ID)) { - BaseTreeNode node = new BaseTreeNode(treeNode.getId(), treeNode.getName(), treeNode.getType(), treeNode.getParentId()); baseTreeNodeList.add(node); - baseTreeNodeMap.put(treeNode.getId(), node); - } else { - if (baseTreeNodeMap.containsKey(treeNode.getParentId())) { - BaseTreeNode node = new BaseTreeNode(treeNode.getId(), treeNode.getName(), treeNode.getType(), treeNode.getParentId()); - baseTreeNodeMap.get(treeNode.getParentId()).addChild(node); - baseTreeNodeMap.put(treeNode.getId(), node); - } else { - notMatchedList.add(treeNode); - } + } else if (baseTreeNodeMap.containsKey(treeNode.getParentId())) { + baseTreeNodeMap.get(treeNode.getParentId()).addChild(node); } } traverseList = notMatchedList; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseTreeNode.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseTreeNode.java index 2f12a93f71..1441dae791 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseTreeNode.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseTreeNode.java @@ -34,6 +34,17 @@ public class BaseTreeNode { @Schema(description = "节点资源数量(多数情况下不会随着节点信息返回,视接口而定)") private long count = 0; + @Schema(description = "节点路径(当前节点所在整棵树的路径)") + private String path = "/"; + + public void genModulePath(BaseTreeNode parentNode) { + if (parentNode != null) { + path = parentNode.getPath() + "/" + this.getName(); + } else { + path = "/" + this.getName(); + } + } + public BaseTreeNode(String id, String name, String type) { this.id = id; this.name = name;