From 1e431295b848bfe80dbcf4b1b1c4caf8958df396 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Fri, 15 Nov 2024 18:40:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=8E=AF=E5=A2=83=E7=9A=84=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=A0=91=E8=BF=94=E5=9B=9E=E5=A4=9A=E4=B8=AA=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiDefinitionModuleService.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java index ef3fb0612a..735da42a72 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionModuleService.java @@ -328,43 +328,50 @@ public class ApiDefinitionModuleService extends ModuleTreeService { //根据选择的模块id 来补充选中的id List selectedModules = request.getSelectedModules(); List currentModules = new ArrayList<>(); + // 选中的模块id + List moduleIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(selectedModules)) { //将选中的模块id转换为Map 方便后面的查询 key为id Map selectedModuleMap = selectedModules.stream().collect(Collectors.toMap(ApiModuleDTO::getModuleId, apiModuleDTO -> apiModuleDTO)); - getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap); + getAllModuleIds(baseTreeNodes, currentModules, selectedModuleMap, moduleIds); } envApiTreeDTO.setSelectedModules(currentModules); return envApiTreeDTO; } - public void getAllModuleIds(List baseTreeNodes, List currentModules, Map selectedModuleMap) { + public void getAllModuleIds(List baseTreeNodes, List currentModules, Map selectedModuleMap, List moduleIds) { baseTreeNodes.forEach(baseTreeNode -> { if (selectedModuleMap.containsKey(baseTreeNode.getId())) { ApiModuleDTO apiModuleDTO = selectedModuleMap.get(baseTreeNode.getId()); - if (BooleanUtils.isTrue(apiModuleDTO.getContainChildModule())) { - currentModules.add(apiModuleDTO); - if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) { - setChildren(baseTreeNode.getChildren(), currentModules); + if (!moduleIds.contains(baseTreeNode.getId())) { + moduleIds.add(baseTreeNode.getId()); + if (BooleanUtils.isTrue(apiModuleDTO.getContainChildModule())) { + moduleIds.add(baseTreeNode.getId()); + currentModules.add(apiModuleDTO); + if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) { + setChildren(baseTreeNode.getChildren(), currentModules, moduleIds); + } + } else { + currentModules.add(apiModuleDTO); } - } else { - currentModules.add(apiModuleDTO); } } if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) { - getAllModuleIds(baseTreeNode.getChildren(), currentModules, selectedModuleMap); + getAllModuleIds(baseTreeNode.getChildren(), currentModules, selectedModuleMap, moduleIds); } }); } - public void setChildren(List baseTreeNodes, List currentModules) { + public void setChildren(List baseTreeNodes, List currentModules, List moduleIds) { baseTreeNodes.forEach(baseTreeNode -> { ApiModuleDTO children = new ApiModuleDTO(); children.setModuleId(baseTreeNode.getId()); children.setContainChildModule(true); children.setDisabled(true); + moduleIds.add(baseTreeNode.getId()); currentModules.add(children); if (CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) { - setChildren(baseTreeNode.getChildren(), currentModules); + setChildren(baseTreeNode.getChildren(), currentModules, moduleIds); } }); }