From 9492b4df703e1af1affb7a17f0092f90666af2b3 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 26 Jan 2022 17:51:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E4=B8=8E=E8=AF=84=E5=AE=A1=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20--bug=3D1010009=20--user=3D=E9=99=88=E5=BB=BA=E6=98=9F=20?= =?UTF-8?q?=E3=80=90=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA=E3=80=91github#99?= =?UTF-8?q?85=EF=BC=8C=E7=94=A8=E4=BE=8B=E8=AF=84=E5=AE=A1=E5=B7=A6?= =?UTF-8?q?=E4=BE=A7=E6=A8=A1=E5=9D=97=E5=8A=A0=E8=BD=BD=E6=85=A2=20https:?= =?UTF-8?q?//www.tapd.cn/55049933/s/10994900?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/TestCaseReviewTestCaseMapper.java | 2 +- .../base/mapper/ext/ExtTestCaseMapper.java | 4 + .../base/mapper/ext/ExtTestCaseMapper.xml | 7 + .../ext/ExtTestCaseReviewTestCaseMapper.java | 10 ++ .../ext/ExtTestCaseReviewTestCaseMapper.xml | 10 ++ .../mapper/ext/ExtTestPlanTestCaseMapper.java | 3 + .../mapper/ext/ExtTestPlanTestCaseMapper.xml | 7 + .../track/service/TestCaseNodeService.java | 154 +++++------------- .../track/service/TestPlanService.java | 64 +++++--- 9 files changed, 125 insertions(+), 136 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.xml diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewTestCaseMapper.java index 1edffb5ea7..e361475b26 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewTestCaseMapper.java @@ -27,4 +27,4 @@ public interface TestCaseReviewTestCaseMapper { int updateByPrimaryKeySelective(TestCaseReviewTestCase record); int updateByPrimaryKey(TestCaseReviewTestCase record); -} \ No newline at end of file +} 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 a8fb3a0bd9..99daed5eef 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 @@ -8,6 +8,7 @@ import io.metersphere.track.dto.TestCaseDTO; import io.metersphere.track.request.testcase.QueryTestCaseRequest; import io.metersphere.track.request.testcase.TestCaseBatchRequest; import io.metersphere.track.response.TrackCountResult; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -145,4 +146,7 @@ public interface ExtTestCaseMapper { List selectRefIdsForVersionChange(@Param("versionId") String versionId, @Param("projectId") String projectId); int addLatestVersion(@Param("refId") String refId); + + @MapKey("id") + Map getMaintainerMap(@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 fdd3bcfe36..a5b2ab0917 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 @@ -993,6 +993,13 @@ ) AND project_id = #{projectId} + UPDATE test_case diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.java new file mode 100644 index 0000000000..4d070310b0 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.java @@ -0,0 +1,10 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.base.domain.TestCase; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtTestCaseReviewTestCaseMapper { + List getTestCaseWithNodeInfo(@Param("reviewId") String reviewId); +} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.xml new file mode 100644 index 0000000000..a8636effa3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewTestCaseMapper.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java index 5d5656de06..f1c63303eb 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.java @@ -1,5 +1,6 @@ package io.metersphere.base.mapper.ext; +import io.metersphere.base.domain.TestCase; import io.metersphere.controller.request.BaseQueryRequest; import io.metersphere.track.dto.PlanReportCaseDTO; import io.metersphere.track.dto.TestCaseReportStatusResultDTO; @@ -68,4 +69,6 @@ public interface ExtTestPlanTestCaseMapper { Long getPreOrder(@Param("planId")String planId, @Param("baseOrder") Long baseOrder); Long getLastOrder(@Param("planId")String planId, @Param("baseOrder") Long baseOrder); + + List getTestCaseWithNodeInfo(@Param("planId") String planId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 7ea49fac8a..37fba56af6 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -556,6 +556,13 @@ order by `order` desc limit 1; + + and ${versionTable}.version_id = #{request.versionId} 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 44e4195a9e..8eb2ee94b6 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseNodeService.java @@ -7,6 +7,7 @@ import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseNodeMapper; +import io.metersphere.base.mapper.ext.ExtTestCaseReviewTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; @@ -52,8 +53,6 @@ public class TestCaseNodeService extends NodeTreeService { @Resource TestPlanMapper testPlanMapper; @Resource - TestPlanTestCaseMapper testPlanTestCaseMapper; - @Resource ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; @Resource ExtTestCaseMapper extTestCaseMapper; @@ -66,6 +65,8 @@ public class TestCaseNodeService extends NodeTreeService { @Resource TestCaseReviewTestCaseMapper testCaseReviewTestCaseMapper; @Resource + ExtTestCaseReviewTestCaseMapper extTestCaseReviewTestCaseMapper; + @Resource TestCaseReviewMapper testCaseReviewMapper; public TestCaseNodeService() { @@ -307,55 +308,64 @@ public class TestCaseNodeService extends NodeTreeService { * @return List */ public List getNodeByPlanId(String planId) { + List testCases = extTestPlanTestCaseMapper.getTestCaseWithNodeInfo(planId); + Map> projectNodeMap = getProjectNodeMap(testCases); + return getNodeTreeWithPruningTree(projectNodeMap); + } + public List getNodeByReviewId(String reviewId) { + List testCases = extTestCaseReviewTestCaseMapper.getTestCaseWithNodeInfo(reviewId); + Map> projectNodeMap = getProjectNodeMap(testCases); + return getNodeTreeWithPruningTree(projectNodeMap); + } + + public List getNodeTreeWithPruningTree(Map> projectNodeMap) { List list = new ArrayList<>(); - List projectIds = testPlanProjectService.getProjectIdsByPlanId(planId); - projectIds.forEach(id -> { - Project project = projectMapper.selectByPrimaryKey(id); + projectNodeMap.forEach((k, v) -> { + Project project = projectMapper.selectByPrimaryKey(k); if (project != null) { String name = project.getName(); - List nodeList = getNodeDTO(id, planId); + List testCaseNodes = getNodeTreeWithPruningTree(k, v); TestCaseNodeDTO testCaseNodeDTO = new TestCaseNodeDTO(); testCaseNodeDTO.setId(project.getId()); testCaseNodeDTO.setName(name); testCaseNodeDTO.setLabel(name); - testCaseNodeDTO.setChildren(nodeList); - if (!CollectionUtils.isEmpty(nodeList)) { + testCaseNodeDTO.setChildren(testCaseNodes); + if (!CollectionUtils.isEmpty(testCaseNodes)) { list.add(testCaseNodeDTO); } } }); - return list; } - public List getNodeByReviewId(String reviewId) { - List list = new ArrayList<>(); - ProjectExample example = new ProjectExample(); - example.createCriteria().andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId()); - List projects = projectMapper.selectByExample(example); - List projectIds = projects.stream().map(Project::getId).collect(Collectors.toList()); - - projectIds.forEach(id -> { - String name = projectMapper.selectByPrimaryKey(id).getName(); - - TestCaseReviewTestCaseExample testCaseReviewTestCaseExample = new TestCaseReviewTestCaseExample(); - testCaseReviewTestCaseExample.createCriteria().andReviewIdEqualTo(reviewId); - List testCaseReviewTestCases = testCaseReviewTestCaseMapper.selectByExample(testCaseReviewTestCaseExample); - List caseIds = testCaseReviewTestCases.stream().map(TestCaseReviewTestCase::getCaseId).collect(Collectors.toList()); - - List nodeList = getReviewNodeDTO(id, caseIds); - if (!CollectionUtils.isEmpty(nodeList)) { - TestCaseNodeDTO testCaseNodeDTO = new TestCaseNodeDTO(); - testCaseNodeDTO.setName(name); - testCaseNodeDTO.setLabel(name); - testCaseNodeDTO.setChildren(nodeList); - testCaseNodeDTO.setProjectId(id); - list.add(testCaseNodeDTO); + /** + * 获取当前项目下的 + * @param projectId + * @param pruningTreeIds + * @return + */ + public List getNodeTreeWithPruningTree(String projectId, List pruningTreeIds) { + List testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId); + List nodeTrees = getNodeTrees(testCaseNodes); + Iterator iterator = nodeTrees.iterator(); + while (iterator.hasNext()) { + TestCaseNodeDTO rootNode = iterator.next(); + if (pruningTree(rootNode, pruningTreeIds)) { + iterator.remove(); } - }); - return list; + } + return nodeTrees; + } + private Map> getProjectNodeMap(List testCases) { + Map> projectNodeMap = new HashMap<>(); + for (TestCase testCase : testCases) { + List nodeIds = Optional.ofNullable(projectNodeMap.get(testCase.getProjectId())).orElse(new ArrayList<>()); + nodeIds.add(testCase.getNodeId()); + projectNodeMap.put(testCase.getProjectId(), nodeIds); + } + return projectNodeMap; } private List getNodeDTO(String projectId, QueryTestPlanCaseRequest request) { @@ -364,8 +374,6 @@ public class TestCaseNodeService extends NodeTreeService { return null; } - List testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId); - List caseIds = testPlanTestCases.stream() .map(TestPlanCaseDTO::getCaseId) .collect(Collectors.toList()); @@ -376,79 +384,7 @@ public class TestCaseNodeService extends NodeTreeService { .map(TestCase::getNodeId) .collect(Collectors.toList()); - List nodeTrees = getNodeTrees(testCaseNodes); - - Iterator iterator = nodeTrees.iterator(); - while (iterator.hasNext()) { - TestCaseNodeDTO rootNode = iterator.next(); - if (pruningTree(rootNode, dataNodeIds)) { - iterator.remove(); - } - } - - return nodeTrees; - } - - private List getNodeDTO(String projectId, String planId) { - TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); - testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(planId); - List testPlanTestCases = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample); - - if (testPlanTestCases.isEmpty()) { - return null; - } - - List testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId); - - List caseIds = testPlanTestCases.stream() - .map(TestPlanTestCase::getCaseId) - .collect(Collectors.toList()); - - TestCaseExample testCaseExample = new TestCaseExample(); - testCaseExample.createCriteria().andIdIn(caseIds); - List dataNodeIds = testCaseMapper.selectByExample(testCaseExample).stream() - .map(TestCase::getNodeId) - .collect(Collectors.toList()); - - List nodeTrees = getNodeTrees(testCaseNodes); - - Iterator iterator = nodeTrees.iterator(); - while (iterator.hasNext()) { - TestCaseNodeDTO rootNode = iterator.next(); - if (pruningTree(rootNode, dataNodeIds)) { - iterator.remove(); - } - } - - return nodeTrees; - } - - private List getReviewNodeDTO(String projectId, List caseIds) { - - if (CollectionUtils.isEmpty(caseIds)) { - return null; - } - - List testCaseNodes = extTestCaseNodeMapper.getNodeTreeByProjectId(projectId); - - - TestCaseExample testCaseExample = new TestCaseExample(); - testCaseExample.createCriteria().andIdIn(caseIds); - List dataNodeIds = testCaseMapper.selectByExample(testCaseExample).stream() - .map(TestCase::getNodeId) - .collect(Collectors.toList()); - - List nodeTrees = getNodeTrees(testCaseNodes); - - Iterator iterator = nodeTrees.iterator(); - while (iterator.hasNext()) { - TestCaseNodeDTO rootNode = iterator.next(); - if (pruningTree(rootNode, dataNodeIds)) { - iterator.remove(); - } - } - - return nodeTrees; + return getNodeTreeWithPruningTree(projectId, dataNodeIds); } public List getAllNodeByPlanId(QueryNodeRequest request) { diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 90690813b5..4a0bf5eb3b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -522,11 +522,25 @@ public class TestPlanService { } public void testPlanRelevance(PlanCaseRelevanceRequest request) { + Map userMap = new HashMap<>(); + boolean isSelectAll = request.getRequest() != null && request.getRequest().isSelectAll(); + if (isSelectAll) { + Map maintainerMap = extTestCaseMapper.getMaintainerMap(request.getRequest()); + for (String k : maintainerMap.keySet()) { + userMap.put(k, maintainerMap.get(k).getMaintainer()); + } + } else { + TestCaseExample testCaseExample = new TestCaseExample(); + testCaseExample.createCriteria().andIdIn(request.getIds()); + List testCaseList = testCaseMapper.selectByExample(testCaseExample); + userMap = testCaseList.stream() + .collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getMaintainer()), HashMap::putAll); + } - ServiceUtils.getSelectAllIds(request, request.getRequest(), - (query) -> extTestCaseMapper.selectRelateIdsByQuery(query)); + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class); - List testCaseIds = request.getIds(); + List testCaseIds = new ArrayList<>(userMap.keySet()); if (testCaseIds.isEmpty()) { return; @@ -535,32 +549,42 @@ public class TestPlanService { // 尽量保持与用例顺序一致 Collections.reverse(testCaseIds); - TestCaseExample testCaseExample = new TestCaseExample(); - testCaseExample.createCriteria().andIdIn(testCaseIds); - List testCaseList = testCaseMapper.selectByExample(testCaseExample); - Map userMap = testCaseList.stream() - .collect(HashMap::new, (m, v) -> m.put(v.getId(), v.getMaintainer()), HashMap::putAll); - - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - TestPlanTestCaseMapper batchMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class); - Long nextOrder = ServiceUtils.getNextOrder(request.getPlanId(), extTestPlanTestCaseMapper::getLastOrder); for (String caseId : testCaseIds) { TestPlanTestCaseWithBLOBs testPlanTestCase = new TestPlanTestCaseWithBLOBs(); testPlanTestCase.setId(UUID.randomUUID().toString()); testPlanTestCase.setCreateUser(SessionUtils.getUserId()); - testPlanTestCase.setExecutor(userMap.get(caseId) == null ? SessionUtils.getUserId() : userMap.get(caseId)); + String maintainer = Optional.ofNullable(userMap.get(caseId)).orElse(SessionUtils.getUserId()); + testPlanTestCase.setExecutor(maintainer); testPlanTestCase.setCaseId(caseId); testPlanTestCase.setCreateTime(System.currentTimeMillis()); testPlanTestCase.setUpdateTime(System.currentTimeMillis()); testPlanTestCase.setPlanId(request.getPlanId()); testPlanTestCase.setStatus(TestPlanStatus.Prepare.name()); testPlanTestCase.setOrder(nextOrder); - nextOrder += 5000; + nextOrder += ServiceUtils.ORDER_STEP; batchMapper.insert(testPlanTestCase); } sqlSession.flushStatements(); + + caseTestRelevance(request, testCaseIds); + + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId()); + if (StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Prepare.name()) + || StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) { + testPlan.setStatus(TestPlanStatus.Underway.name()); + testPlan.setActualStartTime(System.currentTimeMillis()); // 将状态更新为进行中时,开始时间也要更新 + testPlan.setActualEndTime(null); + testPlanMapper.updateByPrimaryKey(testPlan); + } + sqlSession.flushStatements(); + if (sqlSession != null && sqlSessionFactory != null) { + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } + } + + public void caseTestRelevance(PlanCaseRelevanceRequest request, List testCaseIds) { //同步添加关联的接口和测试用例 if (request.getChecked()) { if (!testCaseIds.isEmpty()) { @@ -652,18 +676,6 @@ public class TestPlanService { }); } } - TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId()); - if (StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Prepare.name()) - || StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) { - testPlan.setStatus(TestPlanStatus.Underway.name()); - testPlan.setActualStartTime(System.currentTimeMillis()); // 将状态更新为进行中时,开始时间也要更新 - testPlan.setActualEndTime(null); - testPlanMapper.updateByPrimaryKey(testPlan); - } - sqlSession.flushStatements(); - if (sqlSession != null && sqlSessionFactory != null) { - SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - } } public List recentTestPlans(String projectId) {