From 8e575df95f2f67246ebda66e235cd171bba4b898 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 20 Jul 2022 11:34:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E7=94=A8=E4=BE=8B=E5=BA=93=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BA=86=E5=85=A8=E9=83=A8=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1015070 --user=陈建星 【测试跟踪】功能用例页面-查看公共用例库-左侧模块树显示所有工作空间的的公共用例数 https://www.tapd.cn/55049933/s/1205022 --- .../base/mapper/ext/ExtTestCaseMapper.java | 2 ++ .../base/mapper/ext/ExtTestCaseMapper.xml | 9 ++++++ .../metersphere/service/NodeTreeService.java | 9 +++++- .../track/controller/TestCaseController.java | 7 ----- .../controller/TestCaseNodeController.java | 5 +++ .../track/service/TestCaseNodeService.java | 31 ++++++------------- .../track/service/TestCaseService.java | 25 --------------- frontend/src/network/testCase.js | 3 +- 8 files changed, 36 insertions(+), 55 deletions(-) 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 cfa7bf6a99..0bf4521b2a 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 @@ -162,4 +162,6 @@ public interface ExtTestCaseMapper { List> moduleExtraNodeCount(@Param("nodeIds") List nodeIds); int bathUpdateByCondition(@Param("request") QueryTestCaseRequest condition, @Param("record") TestCaseWithBLOBs testCaseWithBLOBs); + + List getWorkspaceCountNodes(@Param("request") QueryTestCaseRequest 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 229487c701..8c44f7b5e0 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 @@ -1255,4 +1255,13 @@ GROUP BY parent_id + diff --git a/backend/src/main/java/io/metersphere/service/NodeTreeService.java b/backend/src/main/java/io/metersphere/service/NodeTreeService.java index d9ea693571..37d7db135c 100644 --- a/backend/src/main/java/io/metersphere/service/NodeTreeService.java +++ b/backend/src/main/java/io/metersphere/service/NodeTreeService.java @@ -112,6 +112,12 @@ public class NodeTreeService { } } + /** + * 用户测试计划评审或者公共用例库查询多个项目的模块 + * @param countModules 带有用例的节点的信息 + * @param getProjectModulesFunc 根据 projectIds 获取多个项目下的模块 + * @return + */ public List getNodeTreeWithPruningTree(List countModules, Function, List> getProjectModulesFunc) { if (org.springframework.util.CollectionUtils.isEmpty(countModules)) { @@ -127,11 +133,12 @@ public class NodeTreeService { ProjectService projectService = CommonBeanFactory.getBean(ProjectService.class); List projects = projectService.getProjectByIds(new ArrayList<>(projectIds)); + // 项目->对应项目下的模块 Map> projectModuleMap = getProjectModulesFunc.apply(projectIds) .stream() .collect(Collectors.groupingBy(TreeNodeDTO::getProjectId)); - // 模块与用例数的映射 + // 模块->用例数 Map countMap = countModules.stream() .collect(Collectors.toMap(TreeNodeDTO::getId, TreeNodeDTO::getCaseNum)); diff --git a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java index 13ffe0361f..7b08ebc4a9 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java @@ -28,7 +28,6 @@ import io.metersphere.notice.annotation.SendNotice; import io.metersphere.service.CheckPermissionService; import io.metersphere.service.FileService; import io.metersphere.track.dto.TestCaseDTO; -import io.metersphere.track.dto.TestCaseNodeDTO; import io.metersphere.track.request.testcase.*; import io.metersphere.track.request.testplan.FileOperationRequest; import io.metersphere.track.request.testplan.LoadCaseRequest; @@ -74,12 +73,6 @@ public class TestCaseController { return PageUtils.setPageInfo(page, testCaseService.publicListTestCase(request)); } - - @PostMapping("/public/case/node") - public List getPublicCaseNode(@RequestBody QueryTestCaseRequest request) { - return testCaseService.getPublicCaseNode(request); - } - @GetMapping("/list/{projectId}") @RequiresPermissions("PROJECT_TRACK_CASE:READ") public List list(@PathVariable String projectId) { diff --git a/backend/src/main/java/io/metersphere/track/controller/TestCaseNodeController.java b/backend/src/main/java/io/metersphere/track/controller/TestCaseNodeController.java index a6af9a834f..0a2e2da65f 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestCaseNodeController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseNodeController.java @@ -74,6 +74,11 @@ public class TestCaseNodeController { return testCaseNodeService.getNodeByPlanId(planId, Optional.ofNullable(request).orElse(new QueryTestPlanCaseRequest())); } + @PostMapping("/list/public/{workspaceId}") + public List getPublicCaseNode(@PathVariable String workspaceId, @RequestBody QueryTestCaseRequest request) { + return testCaseNodeService.getPublicCaseNode(workspaceId, request); + } + @PostMapping("/list/plan/relate") public List getRelatePlanNodes(@RequestBody QueryTestCaseRequest request) { checkPermissionService.checkTestPlanOwner(request.getPlanId()); 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 3f5162a9a8..b73eed0466 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java @@ -4,7 +4,9 @@ package io.metersphere.track.service; import com.alibaba.fastjson.JSON; import com.google.common.util.concurrent.AtomicDouble; import io.metersphere.base.domain.*; -import io.metersphere.base.mapper.*; +import io.metersphere.base.mapper.ProjectMapper; +import io.metersphere.base.mapper.TestCaseMapper; +import io.metersphere.base.mapper.TestCaseNodeMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseNodeMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; @@ -22,7 +24,6 @@ import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.api.ModuleReference; import io.metersphere.service.NodeTreeService; -import io.metersphere.service.ProjectService; import io.metersphere.track.dto.TestCaseDTO; import io.metersphere.track.dto.TestCaseNodeDTO; import io.metersphere.track.dto.TestPlanCaseDTO; @@ -34,7 +35,6 @@ import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -54,8 +54,6 @@ public class TestCaseNodeService extends NodeTreeService { @Resource TestCaseMapper testCaseMapper; @Resource - TestPlanMapper testPlanMapper; - @Resource ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; @Resource ExtTestCaseMapper extTestCaseMapper; @@ -66,12 +64,7 @@ public class TestCaseNodeService extends NodeTreeService { @Resource ProjectMapper projectMapper; @Resource - TestCaseReviewMapper testCaseReviewMapper; - @Resource ExtTestReviewCaseMapper extTestReviewCaseMapper; - @Lazy - @Resource - ProjectService projectService; public TestCaseNodeService() { super(TestCaseNodeDTO.class); @@ -276,19 +269,15 @@ public class TestCaseNodeService extends NodeTreeService { return getNodeTreeWithPruningTree(countModules); } - public List getNodeByPlanId(String planId) { - return this.getNodeByPlanId(planId, new QueryTestPlanCaseRequest()); + public List getPublicCaseNode(String workspaceId, QueryTestCaseRequest request) { + request.setWorkspaceId(workspaceId); + request.setProjectId(null); + List countModules = extTestCaseMapper.getWorkspaceCountNodes(request); + return getNodeTreeWithPruningTree(countModules); } - public List getPublicNodeByProjectNode(List projectNodes, QueryTestCaseRequest request) { - request.setCasePublic(true); - 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 projectNodes; + public List getNodeByPlanId(String planId) { + return this.getNodeByPlanId(planId, new QueryTestPlanCaseRequest()); } public List getNodeByReviewId(String reviewId) { 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 ce3db637ff..4030ff6815 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -46,7 +46,6 @@ import io.metersphere.performance.service.PerformanceTestService; import io.metersphere.service.*; import io.metersphere.track.dto.TestCaseCommentDTO; import io.metersphere.track.dto.TestCaseDTO; -import io.metersphere.track.dto.TestCaseNodeDTO; import io.metersphere.track.issue.AbstractIssuePlatform; import io.metersphere.track.issue.IssueFactory; import io.metersphere.track.issue.service.XpackIssueService; @@ -2898,30 +2897,6 @@ public class TestCaseService { return false; } - public List getPublicCaseNode(QueryTestCaseRequest request) { - List testCaseDTOS = publicProjectNode(request); - return testCaseNodeService.getPublicNodeByProjectNode(testCaseDTOS, request); - } - - 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) { List relationshipIds = relationshipEdgeService.getRelationshipIds(request.getId()); request.getCondition().setNotInIds(relationshipIds); diff --git a/frontend/src/network/testCase.js b/frontend/src/network/testCase.js index 0f2f7ffad7..e234293cb9 100644 --- a/frontend/src/network/testCase.js +++ b/frontend/src/network/testCase.js @@ -3,6 +3,7 @@ import {success} from "@/common/js/message"; import i18n from "@/i18n/i18n"; import {basePost} from "@/network/base-network"; import {baseGet} from "./base-network"; +import {getCurrentWorkspaceId} from "@/common/js/utils"; export const minderPageInfoMap = new Map(); @@ -97,7 +98,7 @@ export function getTestReviewCaseNodesByCaseFilter(reviewId, param, callback) { } export function getTestCasePublicNodes(param, callback) { - return basePost('/test/case/public/case/node', param, callback); + return basePost('/case/node/list/public/' + getCurrentWorkspaceId(), param, callback); } export function getRelationshipCase(id, relationshipType, callback) {