From 5022f61ede1817dc803a63f175ed1f6ce9b7ba23 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 16 Mar 2023 15:12:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E8=AF=84=E5=AE=A1=E7=94=A8=E4=BE=8B=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=84=E5=AE=A1=E4=BA=BA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1024499 --user=陈建星 【测试跟踪】用例评审-批量操作-变更评审人,可以同时选择多人 https://www.tapd.cn/55049933/s/1351129 --bug=1024522 --user=陈建星 【测试跟踪】用例评审评审人显示异常 https://www.tapd.cn/55049933/s/1351479 --- .../TestReviewCaseBatchRequest.java | 3 +- .../service/TestReviewTestCaseService.java | 123 +++++++++++------- .../business/case/components/BatchEdit.vue | 2 +- .../components/TestReviewTestCaseList.vue | 2 +- 4 files changed, 81 insertions(+), 49 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/request/testplancase/TestReviewCaseBatchRequest.java b/test-track/backend/src/main/java/io/metersphere/request/testplancase/TestReviewCaseBatchRequest.java index 20499184af..a51a6a071b 100644 --- a/test-track/backend/src/main/java/io/metersphere/request/testplancase/TestReviewCaseBatchRequest.java +++ b/test-track/backend/src/main/java/io/metersphere/request/testplancase/TestReviewCaseBatchRequest.java @@ -11,8 +11,9 @@ import java.util.List; @Setter public class TestReviewCaseBatchRequest extends TestCaseReviewTestCase { private String reviewId; + private List reviewerIds; private List ids; private QueryCaseReviewCondition condition; - private Boolean appendTag; + private Boolean appendTag = false; private String description; } diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestReviewTestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestReviewTestCaseService.java index 684b710ff8..ea509eca7e 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestReviewTestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestReviewTestCaseService.java @@ -7,10 +7,7 @@ import io.metersphere.base.mapper.ext.ExtTestReviewCaseMapper; import io.metersphere.commons.constants.TestCaseReviewStatus; import io.metersphere.commons.constants.TestPlanStatus; import io.metersphere.commons.exception.MSException; -import io.metersphere.commons.utils.BeanUtils; -import io.metersphere.commons.utils.CommonBeanFactory; -import io.metersphere.commons.utils.JSON; -import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.commons.utils.*; import io.metersphere.constants.TestCaseCommentType; import io.metersphere.constants.TestCaseReviewCommentStatus; import io.metersphere.constants.TestCaseReviewPassRule; @@ -23,7 +20,6 @@ import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.StatusReference; import io.metersphere.request.OrderRequest; import io.metersphere.request.ResetOrderRequest; -import io.metersphere.request.member.QueryMemberRequest; import io.metersphere.request.testplancase.TestReviewCaseBatchRequest; import io.metersphere.request.testreview.DeleteRelevanceRequest; import io.metersphere.request.testreview.QueryCaseReviewRequest; @@ -33,6 +29,7 @@ import io.metersphere.xpack.version.service.ProjectVersionService; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.session.SqlSession; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -91,7 +88,15 @@ public class TestReviewTestCaseService { .collect(Collectors.toList()); // 查询评审人 - userIds.addAll(getReviewUserIds(request.getReviewId(), caseIds)); + List testCaseReviewTestCaseUsers = + getTestCaseReviewTestCaseUsers(request.getReviewId(), caseIds); + userIds.addAll(testCaseReviewTestCaseUsers.stream() + .map(TestCaseReviewTestCaseUsers::getUserId) + .collect(Collectors.toList()) + ); + + Map> caseReviewerMap = testCaseReviewTestCaseUsers.stream() + .collect(Collectors.groupingBy(TestCaseReviewTestCaseUsers::getCaseId)); Map userNameMap = ServiceUtils.getUserNameMap(userIds); @@ -107,20 +112,22 @@ public class TestReviewTestCaseService { list.forEach(item -> { // 设置责任人和评审人名称 - item.setReviewerName(getReviewName(userIds, userNameMap)); + List caseReviewers = caseReviewerMap.get(item.getCaseId()); + if (CollectionUtils.isNotEmpty(caseReviewers)) { + List reviewerIds = caseReviewerMap.get(item.getCaseId()).stream() + .map(TestCaseReviewTestCaseUsers::getUserId) + .collect(Collectors.toList()); + item.setReviewerName(getReviewName(reviewerIds, userNameMap)); + } item.setMaintainerName(userNameMap.get(item.getMaintainer())); }); return list; } - private List getReviewUserIds(String reviewId) { - TestCaseReviewUsersExample testCaseReviewUsersExample = new TestCaseReviewUsersExample(); - testCaseReviewUsersExample.createCriteria().andReviewIdEqualTo(reviewId); - List testCaseReviewUsers = testCaseReviewUsersMapper.selectByExample(testCaseReviewUsersExample); - return testCaseReviewUsers.stream().map(TestCaseReviewUsers::getUserId).collect(Collectors.toList()); - } - private String getReviewName(List userIds, Map userMap) { + if (CollectionUtils.isEmpty(userIds)) { + return StringUtils.EMPTY; + } List userNames = new ArrayList<>(); if (userIds.size() > 0) { for (String id : userIds) { @@ -473,37 +480,69 @@ public class TestReviewTestCaseService { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extTestReviewCaseMapper.selectTestCaseIds((QueryCaseReviewRequest) query)); List ids = request.getIds(); - if (CollectionUtils.isEmpty(ids)) { + if (CollectionUtils.isEmpty(ids) || CollectionUtils.isEmpty(request.getReviewerIds())) { return; } - if (StringUtils.isNotBlank(request.getReviewer())) { + + // 分批处理 + SubListUtil.dealForSubList(ids, 500, (subList) -> { + + SqlSession batchSqlSession = ServiceUtils.getBatchSqlSession(); + TestCaseReviewTestCaseUsersMapper batchMapper = batchSqlSession.getMapper(TestCaseReviewTestCaseUsersMapper.class); + + TestCaseReviewTestCaseUsersExample example = new TestCaseReviewTestCaseUsersExample(); + if (!request.getAppendTag()) { - TestCaseReviewTestCaseUsersExample example = new TestCaseReviewTestCaseUsersExample(); - example.createCriteria().andCaseIdIn(request.getIds()); + // 如果不是追加,则先删除,然后批量新增 + example.createCriteria().andCaseIdIn(subList); testCaseReviewTestCaseUsersMapper.deleteByExample(example); - } - for (int i = 0; i < ids.size(); i++) { - TestCaseReviewTestCaseUsersExample example = new TestCaseReviewTestCaseUsersExample(); - example.createCriteria().andReviewIdEqualTo(request.getReviewId()).andCaseIdEqualTo(ids.get(i)).andUserIdEqualTo(request.getReviewer()); + + subList.forEach(caseId -> + request.getReviewerIds().forEach(reviewerId -> { + addTestCaseReviewTestCaseUser(reviewerId, batchMapper, (String) caseId, request.getReviewId()); + })); + } else { + example.createCriteria() + .andReviewIdEqualTo(request.getReviewId()) + .andCaseIdIn(subList) + .andUserIdIn(request.getReviewerIds()); + // 查询用例已有的评审人 List testCaseReviewTestCaseUsers = testCaseReviewTestCaseUsersMapper.selectByExample(example); - if (CollectionUtils.isEmpty(testCaseReviewTestCaseUsers)) { - TestCaseReviewTestCaseUsers insertData = new TestCaseReviewTestCaseUsers(); - insertData.setCaseId(ids.get(i)); - insertData.setReviewId(request.getReviewId()); - insertData.setUserId(request.getReviewer()); - testCaseReviewTestCaseUsersMapper.insert(insertData); - } + + Set caseUserSet = testCaseReviewTestCaseUsers.stream() + .map(item -> item.getCaseId() + item.getUserId()) + .collect(Collectors.toSet()); + + subList.forEach(caseId -> + request.getReviewerIds().forEach(reviewerId -> { + // 如果该用例没有当前的评审人就添加评审人 + if (!caseUserSet.contains(caseId + reviewerId)) { + addTestCaseReviewTestCaseUser(reviewerId, batchMapper, (String) caseId, request.getReviewId()); + } + })); } + batchSqlSession.flushStatements(); + batchSqlSession.close(); + }); - // 修改评审人后重新计算用例的评审状态 - TestCaseReview testReview = testCaseReviewService.getTestReview(request.getReviewId()); - List testCaseReviewTestCases = selectForReviewChange(request.getReviewId()); - for (TestCaseReviewTestCase reviewTestCase : testCaseReviewTestCases) { - // 重新计算评审状态 - reCalcReviewCaseStatus(testReview.getReviewPassRule(), reviewTestCase); - } + // 修改评审人后重新计算用例的评审状态 + TestCaseReview testReview = testCaseReviewService.getTestReview(request.getReviewId()); + List testCaseReviewTestCases = selectForReviewChange(request.getReviewId()); + for (TestCaseReviewTestCase reviewTestCase : testCaseReviewTestCases) { + // 重新计算评审状态 + reCalcReviewCaseStatus(testReview.getReviewPassRule(), reviewTestCase); } + + } + + private void addTestCaseReviewTestCaseUser(String reviewer, TestCaseReviewTestCaseUsersMapper batchMapper, + String caseId, String reviewerId) { + TestCaseReviewTestCaseUsers insertData = new TestCaseReviewTestCaseUsers(); + insertData.setCaseId(caseId); + insertData.setReviewId(reviewerId); + insertData.setUserId(reviewer); + batchMapper.insert(insertData); } private void checkReviewCase(String reviewId) { @@ -679,21 +718,13 @@ public class TestReviewTestCaseService { return updateIsDel(ids, false); } - private List getReviewUserIds(String reviewId, String caseId) { - TestCaseReviewTestCaseUsersExample testCaseReviewTestCaseUsersExample = new TestCaseReviewTestCaseUsersExample(); - testCaseReviewTestCaseUsersExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo(caseId); - List testCaseReviewUsers = testCaseReviewTestCaseUsersMapper.selectByExample(testCaseReviewTestCaseUsersExample); - return testCaseReviewUsers.stream().map(TestCaseReviewTestCaseUsers::getUserId).collect(Collectors.toList()); - } - - private List getReviewUserIds(String reviewId, List caseIds) { + private List getTestCaseReviewTestCaseUsers(String reviewId, List caseIds) { if (CollectionUtils.isEmpty(caseIds)) { return new ArrayList<>(); } TestCaseReviewTestCaseUsersExample testCaseReviewTestCaseUsersExample = new TestCaseReviewTestCaseUsersExample(); testCaseReviewTestCaseUsersExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdIn(caseIds); - List testCaseReviewUsers = testCaseReviewTestCaseUsersMapper.selectByExample(testCaseReviewTestCaseUsersExample); - return testCaseReviewUsers.stream().map(TestCaseReviewTestCaseUsers::getUserId).collect(Collectors.toList()); + return testCaseReviewTestCaseUsersMapper.selectByExample(testCaseReviewTestCaseUsersExample); } public List getCaseStatusByReviewIds(List reviewIds) { diff --git a/test-track/frontend/src/business/case/components/BatchEdit.vue b/test-track/frontend/src/business/case/components/BatchEdit.vue index f1b901adbd..a70762011e 100644 --- a/test-track/frontend/src/business/case/components/BatchEdit.vue +++ b/test-track/frontend/src/business/case/components/BatchEdit.vue @@ -44,7 +44,7 @@ - +
{{ option.id }}({{ option.name }}) diff --git a/test-track/frontend/src/business/review/view/components/TestReviewTestCaseList.vue b/test-track/frontend/src/business/review/view/components/TestReviewTestCaseList.vue index fff6278bbd..db19366cc2 100644 --- a/test-track/frontend/src/business/review/view/components/TestReviewTestCaseList.vue +++ b/test-track/frontend/src/business/review/view/components/TestReviewTestCaseList.vue @@ -553,7 +553,7 @@ export default { param.reviewId = reviewId; param.description = form.description; if (form.type === 'reviewers') { - param.reviewer = form.value; + param.reviewerIds = form.value; param.appendTag = form.appendTag; batchEditTestReviewCaseReviewer(param) .then(() => {