diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java index e91e883200..3037fb5a7e 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java @@ -17,14 +17,19 @@ import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.provider.BaseCaseProvider; +import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.constants.ProjectApplicationType; +import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.domain.UserRoleRelation; +import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.OptionDTO; +import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.utils.ServiceUtils; @@ -87,6 +92,8 @@ public class CaseReviewFunctionalCaseService { private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper; @Resource private CaseReviewUserMapper caseReviewUserMapper; + @Resource + private UserRoleRelationMapper userRoleRelationMapper; private static final String CASE_MODULE_COUNT_ALL = "all"; @@ -317,6 +324,9 @@ public class CaseReviewFunctionalCaseService { String reviewId = request.getReviewId(); List caseReviewFunctionalCaseList = doCaseReviewFunctionalCases(request); + if(CollectionUtils.isEmpty(caseReviewFunctionalCaseList)) { + return; + } List caseIds = caseReviewFunctionalCaseList.stream().map(CaseReviewFunctionalCase::getCaseId).toList(); CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample(); caseReviewHistoryExample.createCriteria().andCaseIdIn(caseIds).andReviewIdEqualTo(reviewId).andDeletedEqualTo(false); @@ -333,21 +343,26 @@ public class CaseReviewFunctionalCaseService { List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); Map caseProjectIdMap = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, FunctionalCase::getProjectId)); + UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); + userRoleRelationExample.createCriteria().andRoleIdEqualTo(InternalUserRole.ADMIN.getValue()).andSourceIdEqualTo(UserRoleScope.SYSTEM).andOrganizationIdEqualTo(UserRoleScope.SYSTEM); + List userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); + List systemUsers = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList(); + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); CaseReviewHistoryMapper caseReviewHistoryMapper = sqlSession.getMapper(CaseReviewHistoryMapper.class); CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class); Map statusMap = new HashMap<>(); for (CaseReviewFunctionalCase caseReviewFunctionalCase : caseReviewFunctionalCaseList) { - //校验当前操作人是否是该用例的评审人,是增加评审历史,不是过滤掉 + //校验当前操作人是否是该用例的评审人或者是系统管理员,是增加评审历史,不是过滤掉 String caseId = caseReviewFunctionalCase.getCaseId(); List userList = reviewerMap.get(caseId); - if (CollectionUtils.isEmpty(userList) || CollectionUtils.isEmpty(userList.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getUserId(), userId)).toList())) { + if (!systemUsers.contains(userId) && (CollectionUtils.isEmpty(userList) || CollectionUtils.isEmpty(userList.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getUserId(), userId)).toList()))) { LogUtils.error(caseId + ": no review user, please check"); continue; } - + boolean isAdmin = systemUsers.contains(userId) && (CollectionUtils.isEmpty(userList) || CollectionUtils.isEmpty(userList.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getUserId(), userId)).toList())); CaseReviewHistory caseReviewHistory = buildCaseReviewHistory(request, userId, caseId); caseReviewHistoryMapper.insert(caseReviewHistory); if (caseHistoryMap.get(caseId) == null) { @@ -358,7 +373,7 @@ public class CaseReviewFunctionalCaseService { caseHistoryMap.get(caseId).add(caseReviewHistory); } //根据评审规则更新用例评审和功能用例关系表中的状态 1.单人评审直接更新评审结果 2.多人评审需要计算 - setStatus(request, caseReviewFunctionalCase, caseHistoryMap, reviewerMap); + setStatus(request, caseReviewFunctionalCase, caseHistoryMap, reviewerMap, isAdmin); statusMap.put(caseReviewFunctionalCase.getCaseId(), caseReviewFunctionalCase.getStatus()); caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(caseReviewFunctionalCase); @@ -396,10 +411,15 @@ public class CaseReviewFunctionalCaseService { } - private static void setStatus(BatchReviewFunctionalCaseRequest request, CaseReviewFunctionalCase caseReviewFunctionalCase, Map> caseHistoryMap, Map> reviewerMap) { + private static void setStatus(BatchReviewFunctionalCaseRequest request, CaseReviewFunctionalCase caseReviewFunctionalCase, Map> caseHistoryMap, Map> reviewerMap, boolean isAdmin) { if (StringUtils.equals(request.getReviewPassRule(), CaseReviewPassRule.SINGLE.toString())) { - caseReviewFunctionalCase.setStatus(request.getStatus()); + if (!StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()) && !isAdmin) { + caseReviewFunctionalCase.setStatus(request.getStatus()); + } } else { + if (isAdmin) { + return; + } //根据用例ID 查询所有评审人 再查所有评审人最后一次的评审结果(只有通过/不通过算结果) List caseReviewHistoriesExp = caseHistoryMap.get(caseReviewFunctionalCase.getCaseId()); Map> hasReviewedUserMap = caseReviewHistoriesExp.stream().sorted(Comparator.comparingLong(CaseReviewHistory::getCreateTime).reversed()).collect(Collectors.groupingBy(CaseReviewHistory::getCreateUser, Collectors.toList())); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java index 6e1ec2d27d..574339e86a 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java @@ -6,14 +6,16 @@ import io.metersphere.functional.constants.CaseReviewPassRule; import io.metersphere.functional.constants.FunctionalCaseReviewStatus; import io.metersphere.functional.domain.*; import io.metersphere.functional.dto.CaseReviewHistoryDTO; -import io.metersphere.functional.mapper.CaseReviewFunctionalCaseUserMapper; -import io.metersphere.functional.mapper.CaseReviewHistoryMapper; -import io.metersphere.functional.mapper.ExtCaseReviewFunctionalCaseMapper; -import io.metersphere.functional.mapper.ExtCaseReviewHistoryMapper; +import io.metersphere.functional.mapper.*; import io.metersphere.functional.request.ReviewFunctionalCaseRequest; import io.metersphere.provider.BaseCaseProvider; +import io.metersphere.sdk.constants.InternalUserRole; +import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.domain.UserRoleRelation; +import io.metersphere.system.domain.UserRoleRelationExample; +import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; @@ -44,6 +46,11 @@ public class ReviewFunctionalCaseService { private BaseCaseProvider provider; @Resource private FunctionalCaseAttachmentService functionalCaseAttachmentService; + @Resource + private UserRoleRelationMapper userRoleRelationMapper; + @Resource + private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper; + /** * 评审功能用例 @@ -58,7 +65,14 @@ public class ReviewFunctionalCaseService { CaseReviewFunctionalCaseUserExample caseReviewFunctionalCaseUserExample = new CaseReviewFunctionalCaseUserExample(); caseReviewFunctionalCaseUserExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo(caseId); List caseReviewFunctionalCaseUsers = caseReviewFunctionalCaseUserMapper.selectByExample(caseReviewFunctionalCaseUserExample); - List users = caseReviewFunctionalCaseUsers.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList(); + List users = new ArrayList<>(caseReviewFunctionalCaseUsers.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList()); + //系统管理员可以随意评论,不受约束 + UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); + userRoleRelationExample.createCriteria().andRoleIdEqualTo(InternalUserRole.ADMIN.getValue()).andSourceIdEqualTo(UserRoleScope.SYSTEM).andOrganizationIdEqualTo(UserRoleScope.SYSTEM); + List userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); + List systemUsers = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList(); + boolean isAdmin = systemUsers.contains(userId) && !users.contains(userId); + users.addAll(systemUsers); if (!users.contains(userId)) { throw new MSException(Translator.get("case_review_user")); } @@ -67,18 +81,18 @@ public class ReviewFunctionalCaseService { caseReviewHistoryExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andReviewIdEqualTo(request.getReviewId()).andDeletedEqualTo(false); List caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample); Map> hasReviewedUserMap = caseReviewHistories.stream().sorted(Comparator.comparingLong(CaseReviewHistory::getCreateTime).reversed()).collect(Collectors.groupingBy(CaseReviewHistory::getCreateUser, Collectors.toList())); - if (hasReviewedUserMap.get(userId) ==null) { - ListcaseReviewHistoryList = new ArrayList<>(); + if (hasReviewedUserMap.get(userId) == null) { + List caseReviewHistoryList = new ArrayList<>(); caseReviewHistoryList.add(caseReviewHistory); - hasReviewedUserMap.put(userId,caseReviewHistoryList); + hasReviewedUserMap.put(userId, caseReviewHistoryList); } //根据评审规则更新用例评审和功能用例关系表中的状态 1.单人评审直接更新评审结果 2.多人评审需要计算 - String functionalCaseStatus = getFunctionalCaseStatus(request, hasReviewedUserMap); + String functionalCaseStatus = getFunctionalCaseStatus(request, hasReviewedUserMap, isAdmin); extCaseReviewFunctionalCaseMapper.updateStatus(caseId, reviewId, functionalCaseStatus); caseReviewHistoryMapper.insert(caseReviewHistory); //保存副文本评论附件 - functionalCaseAttachmentService.uploadMinioFile(caseId,request.getProjectId(),request.getReviewCommentFileIds(),userId, CaseFileSourceType.REVIEW_COMMENT.toString()); + functionalCaseAttachmentService.uploadMinioFile(caseId, request.getProjectId(), request.getReviewCommentFileIds(), userId, CaseFileSourceType.REVIEW_COMMENT.toString()); //检查是否有@,发送@通知 if (StringUtils.isNotBlank(request.getNotifier())) { @@ -94,14 +108,14 @@ public class ReviewFunctionalCaseService { } Map param = new HashMap<>(); Map countMap = new HashMap<>(); - countMap.put(functionalCaseStatus,1); + countMap.put(functionalCaseStatus, 1); Map statusMap = new HashMap<>(); - statusMap.put(caseId,functionalCaseStatus); + statusMap.put(caseId, functionalCaseStatus); param.put(CaseEvent.Param.CASE_IDS, List.of(caseId)); param.put(CaseEvent.Param.REVIEW_ID, reviewId); param.put(CaseEvent.Param.STATUS_MAP, statusMap); param.put(CaseEvent.Param.USER_ID, userId); - param.put(CaseEvent.Param.COUNT_MAP,countMap); + param.put(CaseEvent.Param.COUNT_MAP, countMap); param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.REVIEW_FUNCTIONAL_CASE); provider.updateCaseReview(param); @@ -113,11 +127,22 @@ public class ReviewFunctionalCaseService { * @param request 评审规则 * @return 功能用例的评审结果 */ - private String getFunctionalCaseStatus(ReviewFunctionalCaseRequest request, Map> hasReviewedUserMap) { + private String getFunctionalCaseStatus(ReviewFunctionalCaseRequest request, Map> hasReviewedUserMap, boolean isAdmin) { String functionalCaseStatus; + CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); + caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(request.getReviewId()).andCaseIdEqualTo(request.getCaseId()); + List caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); + String status = caseReviewFunctionalCases.get(0).getStatus(); if (StringUtils.equals(request.getReviewPassRule(), CaseReviewPassRule.SINGLE.toString())) { - functionalCaseStatus = request.getStatus(); + if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()) || isAdmin) { + functionalCaseStatus = status; + } else { + functionalCaseStatus = request.getStatus(); + } } else { + if (isAdmin) { + return status; + } //根据用例ID 查询所有评审人 再查所有评审人最后一次的评审结果(只有通过/不通过算结果) CaseReviewFunctionalCaseUserExample caseReviewFunctionalCaseUserExample = new CaseReviewFunctionalCaseUserExample(); caseReviewFunctionalCaseUserExample.createCriteria().andReviewIdEqualTo(request.getReviewId()).andCaseIdEqualTo(request.getCaseId()); @@ -132,7 +157,7 @@ public class ReviewFunctionalCaseService { unPassCount.set(unPassCount.get() + 1); } }); - if (unPassCount.get()>0) { + if (unPassCount.get() > 0) { functionalCaseStatus = FunctionalCaseReviewStatus.UN_PASS.toString(); } else if ((int) reviewerNum > hasReviewedUserMap.size()) { functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString(); diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java index e9f6824023..00987042bc 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java @@ -7,6 +7,7 @@ import io.metersphere.functional.domain.CaseReviewFunctionalCaseExample; import io.metersphere.functional.dto.ReviewFunctionalCaseDTO; import io.metersphere.functional.mapper.CaseReviewFunctionalCaseMapper; import io.metersphere.functional.request.*; +import io.metersphere.functional.service.CaseReviewFunctionalCaseService; import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; @@ -60,6 +61,8 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { @Resource private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper; + @Resource + private CaseReviewFunctionalCaseService caseReviewFunctionalCaseService; @Test @@ -285,6 +288,31 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_1"); + request.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); + request.setContent("hhh"); + request.setSelectAll(false); + ids = new ArrayList<>(); + ids.add("gyq_test_3"); + request.setSelectIds(ids); + caseReviewFunctionalCaseService.batchReview(request, "multiple_review_admin"); + caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_1"); + request.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()); + request.setSelectAll(false); + ids = new ArrayList<>(); + ids.add("gyq_test_3"); + request.setSelectIds(ids); + caseReviewFunctionalCaseService.batchReview(request, "admin"); + caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); + request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); @@ -294,6 +322,8 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { request.setContent("测试批量评审通过"); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); + + request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); @@ -304,6 +334,22 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { request.setSelectIds(ids); request.setContent("测试批量评审通过"); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); + caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_5"); + + + request = new BatchReviewFunctionalCaseRequest(); + request.setReviewId("wx_review_id_1"); + request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); + request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); + request.setContent("hhh"); + request.setSelectAll(false); + ids = new ArrayList<>(); + ids.add(" gyq_test_5"); + request.setSelectIds(ids); + request.setContent("测试批量评审通过"); + caseReviewFunctionalCaseService.batchReview(request, "multiple_review_admin"); + CaseReviewFunctionalCase caseReviewFunctionalCase1 = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_5"); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), caseReviewFunctionalCase1.getStatus())); } diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java index 40caf324e2..eb2b6197b6 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java @@ -12,6 +12,7 @@ import io.metersphere.functional.mapper.CaseReviewMapper; import io.metersphere.functional.mapper.FunctionalCaseAttachmentMapper; import io.metersphere.functional.request.*; import io.metersphere.functional.service.FunctionalCaseAttachmentService; +import io.metersphere.functional.service.ReviewFunctionalCaseService; import io.metersphere.functional.utils.FileBaseUtils; import io.metersphere.project.dto.filemanagement.request.FileUploadRequest; import io.metersphere.project.service.FileMetadataService; @@ -74,6 +75,8 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { private FunctionalCaseAttachmentService functionalCaseAttachmentService; @Resource private FunctionalCaseAttachmentMapper functionalCaseAttachmentMapper; + @Resource + private ReviewFunctionalCaseService reviewFunctionalCaseService; @Test @Order(0) @@ -86,7 +89,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { List reviewers = new ArrayList<>(); reviewers.add("admin"); reviewers.add("default-project-member-user-gyq"); - List caseReviews = addReview("创建用例评审1", caseIds, reviewers); + List caseReviews = addReview("创建用例评审1", caseIds, reviewers, CaseReviewPassRule.SINGLE.toString()); String reviewId = caseReviews.get(0).getId(); ReviewFunctionalCaseRequest reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -143,6 +146,31 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.RE_REVIEWED.toString())); + reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); + reviewFunctionalCaseRequest.setReviewId(reviewId); + reviewFunctionalCaseRequest.setCaseId("gyqReviewCaseTestOne"); + reviewFunctionalCaseRequest.setProjectId(projectId); + reviewFunctionalCaseRequest.setStatus(FunctionalCaseReviewStatus.PASS.toString()); + reviewFunctionalCaseRequest.setContent("不通过"); + reviewFunctionalCaseRequest.setNotifier("default-project-member-user-gyq-2;"); + reviewFunctionalCaseRequest.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + reviewFunctionalCaseService.saveReview(reviewFunctionalCaseRequest, "default-project-member-user-gyq-4"); + caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestOne"); + caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.RE_REVIEWED.toString())); + + reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); + reviewFunctionalCaseRequest.setReviewId(reviewId); + reviewFunctionalCaseRequest.setCaseId("gyqReviewCaseTestOne"); + reviewFunctionalCaseRequest.setProjectId(projectId); + reviewFunctionalCaseRequest.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()); + reviewFunctionalCaseRequest.setContent("不通过"); + reviewFunctionalCaseRequest.setNotifier("default-project-member-user-gyq-2;"); + reviewFunctionalCaseRequest.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + reviewFunctionalCaseService.saveReview(reviewFunctionalCaseRequest, "admin"); + caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestOne"); + caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.RE_REVIEWED.toString())); } @Test @@ -154,7 +182,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { List reviewers = new ArrayList<>(); reviewers.add("admin"); reviewers.add("default-project-member-user-gyq"); - List caseReviews = addReview("创建用例评审2", caseIds, reviewers); + List caseReviews = addReview("创建用例评审2", caseIds, reviewers, CaseReviewPassRule.MULTIPLE.toString()); String reviewId = caseReviews.get(0).getId(); ReviewFunctionalCaseRequest reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -165,6 +193,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { reviewFunctionalCaseRequest.setNotifier("default-project-member-user-gyq-2"); reviewFunctionalCaseRequest.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); this.requestPostWithOk(SAVE_REVIEW, reviewFunctionalCaseRequest); + CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample(); caseReviewHistoryExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestTwo"); List caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample); @@ -175,6 +204,23 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); List caseReviews1 = getCaseReviews("创建用例评审2"); Assertions.assertTrue(StringUtils.equals(caseReviews1.get(0).getStatus(), CaseReviewStatus.UNDERWAY.toString())); + + reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); + reviewFunctionalCaseRequest.setReviewId(reviewId); + reviewFunctionalCaseRequest.setCaseId("gyqReviewCaseTestTwo"); + reviewFunctionalCaseRequest.setProjectId(projectId); + reviewFunctionalCaseRequest.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); + reviewFunctionalCaseRequest.setContent("通过了"); + reviewFunctionalCaseRequest.setNotifier("default-project-member-user-gyq-2"); + reviewFunctionalCaseRequest.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); + reviewFunctionalCaseService.saveReview(reviewFunctionalCaseRequest, "default-project-member-user-gyq-4"); + + caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); + caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestTwo"); + caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); + + } @Test @@ -186,7 +232,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseIds.add("gyqReviewCaseTestFour"); List reviewers = new ArrayList<>(); reviewers.add("admin"); - List caseReviews = addReview("创建用例评审3", caseIds, reviewers); + List caseReviews = addReview("创建用例评审3", caseIds, reviewers, CaseReviewPassRule.MULTIPLE.toString()); String reviewId = caseReviews.get(0).getId(); ReviewFunctionalCaseRequest reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -223,6 +269,8 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId).andCaseIdEqualTo("gyqReviewCaseTestFour"); caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCases.get(0).getStatus(),FunctionalCaseReviewStatus.UN_PASS.toString())); + + } @Test @@ -234,7 +282,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { caseIds.add("gyqReviewCaseTestFour"); List reviewers = new ArrayList<>(); reviewers.add("admin"); - List caseReviews = addReview("创建用例评审4", caseIds, reviewers); + List caseReviews = addReview("创建用例评审4", caseIds, reviewers, CaseReviewPassRule.SINGLE.toString()); String reviewId = caseReviews.get(0).getId(); ReviewFunctionalCaseRequest reviewFunctionalCaseRequest = new ReviewFunctionalCaseRequest(); reviewFunctionalCaseRequest.setReviewId(reviewId); @@ -362,12 +410,12 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { } - private List addReview(String name, List caseIds, List reviewers) throws Exception { + private List addReview(String name, List caseIds, List reviewers, String reviewPassRule) throws Exception { CaseReviewRequest caseReviewRequest = new CaseReviewRequest(); caseReviewRequest.setProjectId(projectId); caseReviewRequest.setName(name); caseReviewRequest.setModuleId("CASE_REVIEW_REAL_MODULE_ID"); - caseReviewRequest.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); + caseReviewRequest.setReviewPassRule(reviewPassRule); caseReviewRequest.setReviewers(reviewers); BaseAssociateCaseRequest baseAssociateCaseRequest = new BaseAssociateCaseRequest(); baseAssociateCaseRequest.setSelectAll(false); diff --git a/backend/services/case-management/src/test/resources/dml/init_review_case.sql b/backend/services/case-management/src/test/resources/dml/init_review_case.sql index 862b6936dc..f2667368c9 100644 --- a/backend/services/case-management/src/test/resources/dml/init_review_case.sql +++ b/backend/services/case-management/src/test/resources/dml/init_review_case.sql @@ -170,6 +170,10 @@ VALUES ('default-project-member-user-gyq', 'default-project-member-user1', 'proj 'admin', 'admin', 0), ('default-project-member-user-gyq-3', 'default-project-member-user4', 'project-member-gyq4@metersphere.io', + MD5('metersphere'), true, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, + 'admin', + 'admin', 0), + ('default-project-member-user-gyq-4', 'default-project-member-user4', 'project-member-gyq5@metersphere.io', MD5('metersphere'), true, UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0); @@ -187,6 +191,9 @@ VALUES (UUID(), 'default-project-member-user-gyq', 'org_member', 'organization-r 'admin'), (UUID(), 'default-project-member-user-gyq-3', 'org_member', 'organization-review-case-test', 'organization-review-case-test', UNIX_TIMESTAMP() * 1000, + 'admin'), + (UUID(), 'default-project-member-user-gyq-4', 'admin', 'system', + 'system', UNIX_TIMESTAMP() * 1000, 'admin'); INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) diff --git a/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql b/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql index 412078c07a..87ff4a4abd 100644 --- a/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql +++ b/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql @@ -108,7 +108,13 @@ VALUES ('wx_test_project_review_one', null, 'organization-associate-case-test', INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user, deleted) VALUES ('gyq_case_review', 'gyq_case_review', 'gyq_case_review_case@fit2cloud.com', MD5('metersphere'),UNIX_TIMESTAMP() * 1000,UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false), - ('GGG', 'GGG', 'GGG_case_review_case@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false); + ('GGG', 'GGG', 'GGG_case_review_case@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false), + ('multiple_review_admin', 'multiple_review_admin', 'multiple_review_admin@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', false); + +INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) +VALUE (UUID(), 'multiple_review_admin', 'admin', 'system', + 'system', UNIX_TIMESTAMP() * 1000, + 'admin'); INSERT INTO case_review_history(id, review_id, case_id, content, status, deleted, notifier, create_user, create_time) VALUES ('wx_history', 'wx_review_id_3', 'wx_case_id_1', NULL, 'PASS', b'0', NULL, 'admin', 1669174143999),