From e52cc072fd46a926252b8c924bfcae7f538a0601 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 7 Jun 2024 10:47:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):?= =?UTF-8?q?=20=E6=A8=A1=E5=9D=97=E5=92=8C=E7=A9=BA=E7=99=BD=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=BB=84=E5=90=88=E6=A0=91=E5=A2=9E=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FunctionalCaseMinderController.java | 6 ++-- .../service/FunctionalCaseMinderService.java | 36 +++++++++++++++---- .../FunctionalCaseMinderControllerTest.java | 13 +++++-- 3 files changed, 43 insertions(+), 12 deletions(-) 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