diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java index 2936fa8914..b09875c24d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java @@ -26,6 +26,8 @@ public interface ExtTestCaseMapper { int moduleCount(@Param("request") QueryTestCaseRequest request); + List getPublicProjectIdByWorkSpaceId(@Param("request") QueryTestCaseRequest request); + List listByMethod(@Param("request") QueryTestCaseRequest request); List listByTestCaseIds(@Param("request") TestCaseBatchRequest request); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index ad69727010..e1b15bc4b4 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -261,68 +261,19 @@ project on test_case.project_id = project.id left join project_version on project.id = project_version.project_id and project_version.id = test_case.version_id - - - - - - - - - - - - and (test_case.status is null or test_case.status != #{request.statusIsNot}) - - - - and (test_case.status is null or test_case.status != #{request.notEqStatus}) - - - and (test_case.name like CONCAT('%', #{request.name},'%') - or test_case.num like CONCAT('%', #{request.name},'%') - or test_case.tags like CONCAT('%', #{request.name},'%') - or test_case.custom_num like CONCAT('%', #{request.name},'%')) - - - and test_case.id in - - #{id} - - - - and test_case.id in (select test_case_id from test_case_test where test_case_test.create_time >= - #{request.createTime}) - - - and test_case.create_time >= #{request.createTime} - - - and test_case.node_id in - - #{nodeId} - - - - AND test_case.project_id in (select id from project where workspace_id=#{request.workspaceId}) - - and test_case.case_public = TRUE - - - and test_case.id not in (select distinct test_case_test.test_case_id from test_case_test) - - - and test_case.id in (select distinct test_case_test.test_case_id from test_case_test) - - - - - - + + + + + + + + + + + + + + + + and (test_case.status is null or test_case.status != #{request.statusIsNot}) + + + + and (test_case.status is null or test_case.status != #{request.notEqStatus}) + + + and (test_case.name like CONCAT('%', #{request.name},'%') + or test_case.num like CONCAT('%', #{request.name},'%') + or test_case.tags like CONCAT('%', #{request.name},'%') + or test_case.custom_num like CONCAT('%', #{request.name},'%')) + + + and test_case.id in + + #{id} + + + + and test_case.id in (select test_case_id from test_case_test where test_case_test.create_time >= + #{request.createTime}) + + + and test_case.create_time >= #{request.createTime} + + + and test_case.node_id in + + #{nodeId} + + + + AND test_case.project_id in (select id from project where workspace_id=#{request.workspaceId}) + + and test_case.case_public = TRUE + + + and test_case.id not in (select distinct test_case_test.test_case_id from test_case_test) + + + and test_case.id in (select distinct test_case_test.test_case_id from test_case_test) + + + + + + + diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java index a5c34990fd..6b4d7301d4 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java @@ -309,23 +309,16 @@ public class TestCaseNodeService extends NodeTreeService { return getNodeTreeWithPruningTree(projectNodeMap); } - public List getNodeByTestCases(List testCaseDTOS) { - Map> projectNodeMap = new HashMap<>(); - for (TestCase testCase : testCaseDTOS) { - List nodeIds = Optional.ofNullable(projectNodeMap.get(testCase.getProjectId())).orElse(new ArrayList<>()); - nodeIds.add(testCase.getNodeId()); - projectNodeMap.put(testCase.getProjectId(), nodeIds); - } - List tree = getNodeTreeWithPruningTree(projectNodeMap); + public List getPublicNodeByProjectNode(List projectNodes) { QueryTestCaseRequest request = new QueryTestCaseRequest(); request.setCasePublic(true); - for (TestCaseNodeDTO dto : tree) { + for (TestCaseNodeDTO dto : projectNodes) { List children = this.getNodeTreeByProjectId(dto.getId(), request); dto.setChildren(children); int sum = children.stream().mapToInt(TestCaseNodeDTO::getCaseNum).sum(); dto.setCaseNum(sum); } - return tree; + return projectNodes; } public List getNodeByReviewId(String reviewId) { @@ -776,4 +769,4 @@ public class TestCaseNodeService extends NodeTreeService { List> moduleCountList = extTestCaseMapper.moduleExtraNodeCount(nodeIds); return this.parseModuleCountList(moduleCountList); } -} +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index de0b81b80d..86b75c13ac 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -2747,8 +2747,27 @@ public class TestCaseService { } public List getPublicCaseNode(QueryTestCaseRequest request) { - List testCaseDTOS = publicListTestCase(request); - return testCaseNodeService.getNodeByTestCases(testCaseDTOS); + List testCaseDTOS = publicProjectNode(request); + return testCaseNodeService.getPublicNodeByProjectNode(testCaseDTOS); + } + + public List publicProjectNode(QueryTestCaseRequest request) { + this.initRequest(request, true); + setDefaultOrder(request); + if (request.getFilters() != null && !request.getFilters().containsKey("status")) { + request.getFilters().put("status", new ArrayList<>(0)); + } + List testCaseNodeDTOList = new ArrayList<>(); + List publicProjectIds = extTestCaseMapper.getPublicProjectIdByWorkSpaceId(request); + publicProjectIds.forEach(projectId -> { + Project project = projectMapper.selectByPrimaryKey(projectId); + TestCaseNodeDTO testCaseNodeDTO = new TestCaseNodeDTO(); + testCaseNodeDTO.setName(project.getName()); + testCaseNodeDTO.setLabel(project.getName()); + testCaseNodeDTO.setId(projectId); + testCaseNodeDTOList.add(testCaseNodeDTO); + }); + return testCaseNodeDTOList; } public void saveRelationshipBatch(TestCaseRelationshipEdgeRequest request) { diff --git a/frontend/src/business/components/track/case/TestCase.vue b/frontend/src/business/components/track/case/TestCase.vue index 9275dbf0db..7aab482e9e 100644 --- a/frontend/src/business/components/track/case/TestCase.vue +++ b/frontend/src/business/components/track/case/TestCase.vue @@ -329,6 +329,9 @@ export default { this.activeName = 'public'; this.result = this.$post('/test/case/public/case/node', {workspaceId: getCurrentWorkspaceId()}, res => { this.publicTreeNodes = res.data; + this.publicTreeNodes.forEach(firstLevel => { + this.$refs.publicNodeTree.nodeExpand(firstLevel); + }) }) } else { this.activeName = 'default';