diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java index b6e6a84959..e0c3254e80 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java @@ -32,12 +32,12 @@ public class FunctionalCaseMinderController { @Resource private FunctionalCaseMinderService functionalCaseMinderService; - @GetMapping("/tree/{projectId}") + @PostMapping("/tree") @Operation(summary = "用例管理-功能用例-脑图-获取空白节点和模块的组合树") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) @CheckOwner(resourceId = "#projectId", resourceType = "project") - public List getTree(@PathVariable String projectId) { - return functionalCaseMinderService.getTree(projectId); + public List getTree(@Validated @RequestBody FunctionalCaseMindRequest request) { + return functionalCaseMinderService.getTree(request); } @PostMapping("/list") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index 0770ffc62b..9adf973b50 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -292,6 +292,7 @@ public class FunctionalCaseMinderService { List updateNoticeList = new ArrayList<>(); List updateLogDTOS = new ArrayList<>(); Map newModuleMap = new HashMap<>(); + //处理模块 dealModule(request, userId, moduleMapper, newModuleMap); @@ -371,6 +372,11 @@ public class FunctionalCaseMinderService { //处理空白节点 dealAdditionalNode(request, userId, additionalNodeMapper, newModuleMap); + //TODO:删除转换的空白节点 + + + + sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); @@ -1060,14 +1066,14 @@ public class FunctionalCaseMinderService { } - public List getTree(String projectId) { - List functionalModuleList = extFunctionalCaseModuleMapper.selectBaseByProjectId(projectId); - List baseTreeNodes = extFunctionalCaseMapper.selectBaseMindNodeByProjectId(projectId); + public List getTree(FunctionalCaseMindRequest request) { + List functionalModuleList = extFunctionalCaseModuleMapper.selectBaseByProjectId(request.getProjectId()); + List baseTreeNodes = extFunctionalCaseMapper.selectBaseMindNodeByProjectId(request.getProjectId()); functionalModuleList.addAll(baseTreeNodes); - return buildTreeAndCountResource(functionalModuleList, true, Translator.get("functional_case.module.default.name")); + return buildTreeAndCountResource(functionalModuleList, true, Translator.get("functional_case.module.default.name"), request.getModuleId()); } - public List buildTreeAndCountResource(List traverseList, boolean haveVirtualRootNode, String virtualRootName) { + public List buildTreeAndCountResource(List traverseList, boolean haveVirtualRootNode, String virtualRootName, String moduleId) { List baseTreeNodeList = new ArrayList<>(); if (haveVirtualRootNode) { @@ -1097,7 +1103,25 @@ public class FunctionalCaseMinderService { } traverseList = notMatchedList; } - return baseTreeNodeList; + + if (StringUtils.isNotBlank(moduleId)) { + List filterList = new ArrayList<>(); + getFilterList(moduleId, baseTreeNodeList, filterList); + return filterList; + } else { + return baseTreeNodeList; + } + } + + private static void getFilterList(String moduleId, List baseTreeNodeList, List filterList) { + for (BaseTreeNode baseTreeNode : baseTreeNodeList) { + if (StringUtils.equalsIgnoreCase(baseTreeNode.getId(), moduleId)) { + filterList.add(baseTreeNode); + break; + } else { + getFilterList(moduleId, baseTreeNode.getChildren(), filterList); + } + } } public BaseTreeNode getDefaultModule(String name) { diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java index 28a86e2d2c..e7d095dc75 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java @@ -39,7 +39,7 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { public static final String FUNCTIONAL_CASE_EDIT_URL = "/functional/mind/case/edit"; - public static final String FUNCTIONAL_CASE_NODE_MODULE_URL = "/functional/mind/case/tree/"; + public static final String FUNCTIONAL_CASE_NODE_MODULE_URL = "/functional/mind/case/tree"; @@ -265,12 +265,19 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { @Test @Order(3) public void testGetCaseModuleNodeList() throws Exception { - MvcResult mvcResultPage = this.requestGetWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL+"project-case-minder-test"); + FunctionalCaseMindRequest request = new FunctionalCaseMindRequest(); + request.setProjectId("project-case-minder-test"); + MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL, request); String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); List baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class); Assertions.assertNotNull(baseTreeNodes); - System.out.println(baseTreeNodes); + request.setModuleId("TEST_MINDER_MODULE_ID_GYQ"); + mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_NODE_MODULE_URL, request); + contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); + resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BaseTreeNode.class); + Assertions.assertNotNull(baseTreeNodes); } @Test