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;