diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/constants/CaseEvent.java b/backend/services/case-management/src/main/java/io/metersphere/functional/constants/CaseEvent.java index bcab0886e3..c452183c88 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/constants/CaseEvent.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/constants/CaseEvent.java @@ -10,6 +10,7 @@ public interface CaseEvent { String DELETE_TRASH_FUNCTIONAL_CASE = "deleteTrashFunctionalCase"; String RECOVER_FUNCTIONAL_CASE = "recoverFunctionalCase"; String REVIEW_FUNCTIONAL_CASE = "reviewFunctionalCase"; + String BATCH_UPDATE_REVIEWER = "batchUpdateReviewer"; } interface Param { diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java index 2d9da1135a..e0f1064c5f 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseController.java @@ -5,10 +5,7 @@ import com.alibaba.excel.util.StringUtils; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.functional.dto.ReviewFunctionalCaseDTO; -import io.metersphere.functional.request.BaseReviewCaseBatchRequest; -import io.metersphere.functional.request.CaseReviewFunctionalCasePosRequest; -import io.metersphere.functional.request.BatchReviewFunctionalCaseRequest; -import io.metersphere.functional.request.ReviewFunctionalCasePageRequest; +import io.metersphere.functional.request.*; import io.metersphere.functional.service.CaseReviewFunctionalCaseService; import io.metersphere.functional.service.CaseReviewLogService; import io.metersphere.sdk.constants.PermissionConstants; @@ -83,4 +80,11 @@ public class CaseReviewFunctionalCaseController { caseReviewFunctionalCaseService.batchReview(request, SessionUtils.getUserId()); } + @PostMapping("/batch/edit/reviewers") + @Operation(summary = "用例管理-功能用例-评审列表-评审详情-列表-批量修改评审人") + @CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review") + public void batchEditReviewUser(@Validated @RequestBody BatchEditReviewerRequest request) { + caseReviewFunctionalCaseService.batchEditReviewUser(request, SessionUtils.getUserId()); + } + } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.java index a180f52a8d..48fa34abb5 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.java @@ -39,5 +39,5 @@ public interface ExtCaseReviewFunctionalCaseMapper { List getListExcludes(@Param("reviewIds")List reviewIds, @Param("caseIds") List caseIds, @Param("deleted") boolean deleted); - + List getCaseIdsByIds(@Param("ids") List ids); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.xml index 84bbb8c6a7..bf6ac75e5e 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseMapper.xml @@ -379,4 +379,10 @@ order by `pos` desc limit 1; + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.java index 0700dbddd8..edec27c502 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.java @@ -10,4 +10,6 @@ import java.util.List; */ public interface ExtCaseReviewFunctionalCaseUserMapper { List selectReviewers(@Param("ids") List ids, @Param("reviewId") String reviewId); + + void deleteByCaseIds(@Param("ids") List ids, @Param("reviewId") String reviewId); } \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.xml index 80c8607aff..c88ca52002 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewFunctionalCaseUserMapper.xml @@ -20,4 +20,12 @@ crfcu.case_id + + DELETE FROM case_review_functional_case_user WHERE + review_id = #{reviewId} AND case_id IN + + #{id} + + + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.java index a21c9e2d74..831ac65397 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.java @@ -33,4 +33,5 @@ public interface ExtCaseReviewMapper { long caseCount(@Param("request") CaseReviewPageRequest request); + String getReviewPassRule(@Param("id") String id); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml index 79b74528b7..bf21c042d7 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewMapper.xml @@ -439,4 +439,7 @@ 1 = 1 + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/provider/CaseReviewCaseProvider.java b/backend/services/case-management/src/main/java/io/metersphere/functional/provider/CaseReviewCaseProvider.java index 66edc6b276..2d2bed3e0e 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/provider/CaseReviewCaseProvider.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/provider/CaseReviewCaseProvider.java @@ -51,11 +51,31 @@ public class CaseReviewCaseProvider implements BaseCaseProvider { case CaseEvent.Event.DELETE_TRASH_FUNCTIONAL_CASE -> updateCaseReviewByDeleteTrashFunctionalCase(paramMap); case CaseEvent.Event.RECOVER_FUNCTIONAL_CASE -> updateCaseReviewByRecoverFunctionalCase(paramMap); case CaseEvent.Event.REVIEW_FUNCTIONAL_CASE -> updateCaseReviewByReviewFunctionalCase(paramMap); + case CaseEvent.Event.BATCH_UPDATE_REVIEWER -> updateCaseReviewByBatchUpdateReviewer(paramMap); default -> LogUtils.info("CaseProvider: " + event); } } + + /** + * 批量修改评审人 重新计算通过率和用例数 + * + * @param paramMap paramMap + */ + private void updateCaseReviewByBatchUpdateReviewer(Map paramMap) { + try { + String reviewId = paramMap.get(CaseEvent.Param.REVIEW_ID).toString(); + int caseCount = Integer.parseInt(paramMap.get(CaseEvent.Param.CASE_COUNT).toString()); + int passCount = Integer.parseInt(paramMap.get(CaseEvent.Param.PASS_COUNT).toString()); + int unCompletedCaseCount = Integer.parseInt(paramMap.get(CaseEvent.Param.UN_COMPLETED_COUNT).toString()); + updateCaseReview(reviewId, caseCount, passCount, unCompletedCaseCount, paramMap.get(CaseEvent.Param.USER_ID).toString()); + } catch (Exception e) { + LogUtils.error(CaseEvent.Event.BATCH_UPDATE_REVIEWER + "事件更新失败", e.getMessage()); + } + + } + /** * 1.关联用例(单独/批量)重新计算用例评审的通过率和用例数 */ diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/request/BatchEditReviewerRequest.java b/backend/services/case-management/src/main/java/io/metersphere/functional/request/BatchEditReviewerRequest.java new file mode 100644 index 0000000000..76988e15ba --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/request/BatchEditReviewerRequest.java @@ -0,0 +1,20 @@ +package io.metersphere.functional.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +/** + * @author wx + */ +@Data +public class BatchEditReviewerRequest extends BaseReviewCaseBatchRequest { + + @Schema(description = "评审人id列表", requiredMode = Schema.RequiredMode.REQUIRED) + private List reviewerId; + + @Schema(description = "是否追加", requiredMode = Schema.RequiredMode.REQUIRED) + private boolean append; + +} 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 1346b1124d..914732c6ad 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 @@ -387,4 +387,142 @@ public class CaseReviewFunctionalCaseService { caseReviewHistory.setCreateTime(System.currentTimeMillis()); return caseReviewHistory; } + + + public void batchEditReviewUser(BatchEditReviewerRequest request, String userId) { + List ids = doSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + String reviewPassRule = caseReviewService.getReviewPassRule(request.getReviewId()); + //评审人处理 + List cases = extCaseReviewFunctionalCaseMapper.getCaseIdsByIds(ids); + handleReviewers(request, cases, reviewPassRule, userId); + + } + } + + private void handleReviewers(BatchEditReviewerRequest request, List cases, String reviewPassRule, String userId) { + List caseIds = cases.stream().map(CaseReviewFunctionalCase::getCaseId).toList(); + CaseReviewFunctionalCaseUserExample example = new CaseReviewFunctionalCaseUserExample(); + example.createCriteria().andCaseIdIn(caseIds).andReviewIdEqualTo(request.getReviewId()); + List oldReviewUsers = caseReviewFunctionalCaseUserMapper.selectByExample(example); + Map> oldReviewUserMap = oldReviewUsers.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCaseUser::getCaseId)); + + //处理评审人数据 + handleReviewCaseUsers(request, caseIds, oldReviewUserMap); + + if (CaseReviewPassRule.MULTIPLE.name().equals(reviewPassRule)) { + //如果是多人评审 需要重新评估用例评审状态 + List newReviewers = caseReviewFunctionalCaseUserMapper.selectByExample(example); + Map> newReviewersMap = newReviewers.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCaseUser::getCaseId)); + + CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample(); + caseReviewHistoryExample.createCriteria().andCaseIdIn(caseIds).andReviewIdEqualTo(request.getReviewId()).andDeletedEqualTo(false); + List caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample); + Map> caseHistoryMap = caseReviewHistories.stream().collect(Collectors.groupingBy(CaseReviewHistory::getCaseId, Collectors.toList())); + + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + FunctionalCaseMapper functionalCaseMapper = sqlSession.getMapper(FunctionalCaseMapper.class); + CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class); + cases.forEach(caseReview -> { + String status = multipleReview(caseReview, caseHistoryMap.get(caseReview.getCaseId()), newReviewersMap.get(caseReview.getCaseId()), oldReviewUserMap.get(caseReview.getCaseId())); + caseReview.setStatus(status); + caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(caseReview); + FunctionalCase functionalCase = new FunctionalCase(); + functionalCase.setId(caseReview.getCaseId()); + functionalCase.setReviewStatus(caseReview.getStatus()); + functionalCaseMapper.updateByPrimaryKeySelective(functionalCase); + }); + sqlSession.flushStatements(); + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + + Map param = new HashMap<>(); + List list = extCaseReviewFunctionalCaseMapper.getList(request.getReviewId(), null, false); + List passList = list.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getStatus(), FunctionalCaseReviewStatus.PASS.toString())).toList(); + List unCompletedCaseList = list.stream().filter(t -> StringUtils.equalsAnyIgnoreCase(t.getStatus(), FunctionalCaseReviewStatus.UN_REVIEWED.toString(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString(), FunctionalCaseReviewStatus.RE_REVIEWED.toString())).toList(); + param.put(CaseEvent.Param.REVIEW_ID, request.getReviewId()); + param.put(CaseEvent.Param.USER_ID, userId); + param.put(CaseEvent.Param.CASE_COUNT, list.size()); + param.put(CaseEvent.Param.PASS_COUNT, passList.size()); + param.put(CaseEvent.Param.UN_COMPLETED_COUNT, unCompletedCaseList.size()); + param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.BATCH_UPDATE_REVIEWER); + provider.updateCaseReview(param); + } + + } + + private String multipleReview(CaseReviewFunctionalCase caseReviewFunctionalCase, List reviewHistories, List newReviewers, List oldReviewers) { + if (CollectionUtils.isNotEmpty(reviewHistories)) { + List historyUsers = reviewHistories.stream().map(CaseReviewHistory::getCreateUser).toList(); + List newUsers = newReviewers.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList(); + if (CollectionUtils.isEmpty(oldReviewers)) { + oldReviewers = new ArrayList<>(); + } + List oldUsers = oldReviewers.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList(); + + if (CollectionUtils.isEqualCollection(newUsers, oldUsers)) { + return caseReviewFunctionalCase.getStatus(); + } + + Collection intersection = CollectionUtils.intersection(historyUsers, newUsers); + if (CollectionUtils.isNotEmpty(intersection)) { + //存在已经评审的人 状态列表 + List statusList = reviewHistories.stream().filter(item -> intersection.contains(item.getCreateUser())).map(CaseReviewHistory::getStatus).toList(); + if (statusList.contains(FunctionalCaseReviewStatus.UN_PASS.name())) { + return FunctionalCaseReviewStatus.UN_PASS.name(); + } + long count = statusList.stream().filter(item -> StringUtils.equalsIgnoreCase(FunctionalCaseReviewStatus.PASS.name(), item)).count(); + if (count == statusList.size() && newUsers.size() <= oldUsers.size()) { + return FunctionalCaseReviewStatus.PASS.name(); + } else { + return FunctionalCaseReviewStatus.UNDER_REVIEWED.name(); + } + } else { + return FunctionalCaseReviewStatus.UN_REVIEWED.name(); + } + } else { + return FunctionalCaseReviewStatus.UN_REVIEWED.name(); + } + } + + + private void handleReviewCaseUsers(BatchEditReviewerRequest request, List caseIds, Map> listMap) { + if (request.isAppend()) { + //追加评审人 + List list = new ArrayList<>(); + caseIds.forEach(caseId -> { + //原评审人 + List users = listMap.get(caseId); + + //新评审人 + List reviewerIds = request.getReviewerId(); + if (CollectionUtils.isNotEmpty(users)) { + List userIds = users.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList(); + reviewerIds.removeAll(userIds); + } + reviewerIds.forEach(reviewer -> { + CaseReviewFunctionalCaseUser caseUser = new CaseReviewFunctionalCaseUser(); + caseUser.setReviewId(request.getReviewId()); + caseUser.setCaseId(caseId); + caseUser.setUserId(reviewer); + list.add(caseUser); + }); + }); + caseReviewFunctionalCaseUserMapper.batchInsert(list); + } else { + //更新评审人 + extCaseReviewFunctionalCaseUserMapper.deleteByCaseIds(caseIds, request.getReviewId()); + List reviewerIds = request.getReviewerId(); + List list = new ArrayList<>(); + caseIds.forEach(caseId -> { + reviewerIds.forEach(reviewer -> { + CaseReviewFunctionalCaseUser caseUser = new CaseReviewFunctionalCaseUser(); + caseUser.setReviewId(request.getReviewId()); + caseUser.setCaseId(caseId); + caseUser.setUserId(reviewer); + list.add(caseUser); + }); + }); + caseReviewFunctionalCaseUserMapper.batchInsert(list); + } + } } \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java index f4dd92c3e9..7d27655862 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java @@ -579,4 +579,8 @@ public class CaseReviewService { moduleCountMap.put(CASE_MODULE_COUNT_ALL, allCount); return moduleCountMap; } + + public String getReviewPassRule(String id) { + return extCaseReviewMapper.getReviewPassRule(id); + } } \ No newline at end of file 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 e0aa0eab8b..0c029b140e 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 @@ -41,6 +41,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { public static final String FUNCTIONAL_CASE_ADD_URL = "/functional/case/add"; public static final String REVIEW_FUNCTIONAL_CASE_POS = "/case/review/detail/edit/pos"; + public static final String BATCH_EDIT_REVIEWERS = "/case/review/detail/batch/edit/reviewers"; public static final String REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW = "/case/review/detail/batch/review"; @@ -205,25 +206,25 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { request.setReviewPassRule(CaseReviewPassRule.MULTIPLE.toString()); request.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); request.setSelectAll(true); - ListexcludeIds = new ArrayList<>(); + List excludeIds = new ArrayList<>(); excludeIds.add("gyq_test_4"); request.setExcludeIds(excludeIds); request.setContent("测试批量评审不通过"); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); CaseReviewFunctionalCase caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_4"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(),FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())); request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); request.setReviewPassRule(CaseReviewPassRule.SINGLE.toString()); request.setStatus(FunctionalCaseReviewStatus.PASS.toString()); request.setSelectAll(false); - Listids = new ArrayList<>(); + List ids = new ArrayList<>(); ids.add("gyq_test_3"); request.setSelectIds(ids); this.requestPostWithOk(REVIEW_FUNCTIONAL_CASE_BATCH_REVIEW, request); caseReviewFunctionalCase = caseReviewFunctionalCaseMapper.selectByPrimaryKey("gyq_test_3"); - Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(),FunctionalCaseReviewStatus.PASS.toString())); + Assertions.assertTrue(StringUtils.equalsIgnoreCase(caseReviewFunctionalCase.getStatus(), FunctionalCaseReviewStatus.PASS.toString())); request = new BatchReviewFunctionalCaseRequest(); request.setReviewId("wx_review_id_1"); @@ -266,4 +267,36 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { return functionalCaseAddRequest; } + + @Test + @Order(9) + public void testBatchEditReviewers() throws Exception { + BatchEditReviewerRequest request = new BatchEditReviewerRequest(); + //更新评审人 + request.setAppend(false); + request.setReviewerId(List.of("wx1")); + request.setReviewId("wx_review_id_1"); + //增加覆盖率 + this.requestPost(BATCH_EDIT_REVIEWERS, request); + + //测试选中id进行更新 单人评审情况下 + request.setSelectIds(List.of("wx_test_3", "wx_test_4")); + this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request); + //多人评审情况下 + request.setReviewId("wx_review_id_3"); + request.setSelectIds(List.of("wx_test_5", "wx_test_6")); + this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request); + //多人 更新不变 + request.setReviewId("wx_review_id_4"); + request.setReviewerId(List.of("admin")); + request.setSelectIds(List.of("wx_test_8", "wx_test_9", "wx_test_10")); + this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request); + + //追加评审人 + request.setAppend(true); + request.setReviewId("wx_review_id_4"); + request.setReviewerId(List.of("wx11")); + request.setSelectIds(List.of("wx_test_10")); + this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request); + } } 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 0fc1153bcc..48edfc3e4c 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 @@ -10,10 +10,19 @@ VALUES ('gyq_case_id_3', 102, 'TEST_MODULE_ID', 'wx_test_project', '100001', ' INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) VALUES ('gyq_case_id_4', 102, 'TEST_MODULE_ID', 'wx_test_project', '100001', '测试多版本', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_4', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('wx_case_id_3', 104, 'TEST_MODULE_ID', 'wx_test_project', '100001', '测试多版本', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'TEST_REF_ID', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); + +INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) +VALUES ('wx_case_id_4', 104, 'TEST_MODULE_ID', 'wx_test_project', '100001', '测试多版本', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'TEST_REF_ID', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); + + INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('wx_case_id_1', 'STEP', '1111', '', '', 'TEST'); INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('wx_case_id_2', 'STEP', '1111', '', '', '1111'); INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('gyq_case_id_3', 'STEP', '1111', '', '', '1111'); INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('gyq_case_id_4', 'STEP', '1111', '', '', '1111'); +INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('wx_case_id_3', 'STEP', '1111', '', '', '1111'); +INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('wx_case_id_4', 'STEP', '1111', '', '', '1111'); @@ -25,20 +34,46 @@ INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('wx_c INSERT INTO case_review(id, num, name, module_id, project_id, status, review_pass_rule, pos, start_time, end_time, case_count, pass_rate, tags, description, create_time, create_user, update_time, update_user) VALUES ('wx_review_id_1',10001,'wx1', 'wx_module_1', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'), - ('wx_review_id_2',10002,'wx2', 'wx_module_2', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'); + ('wx_review_id_2',10002,'wx2', 'wx_module_2', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'), + ('wx_review_id_3',10003,'wx3', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'), + ('wx_review_id_4',10004,'wx3', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'); INSERT INTO case_review_functional_case(id, review_id, case_id, status, create_time, create_user, update_time, pos) VALUES ('wx_test_1', 'wx_review_id_1', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 1000), ('gyq_test_3', 'wx_review_id_1', 'gyq_case_id_3', 'PASS', 1698058347559,'admin',1698058347559, 1500), ('gyq_test_4', 'wx_review_id_1', 'gyq_case_id_4', 'PASS', 1698058347559,'admin',1698058347559, 2000), - ('wx_test_2', 'wx_review_id_2', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000); + ('wx_test_2', 'wx_review_id_2', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_3', 'wx_review_id_2', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_4', 'wx_review_id_2', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_5', 'wx_review_id_3', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_6', 'wx_review_id_3', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_7', 'wx_review_id_3', 'wx_case_id_3', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_8', 'wx_review_id_4', 'wx_case_id_4', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_9', 'wx_review_id_4', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 3000), + ('wx_test_10', 'wx_review_id_4', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000); INSERT INTO case_review_functional_case_user(case_id, review_id, user_id) VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'), ('wx_case_id_1', 'wx_review_id_1', 'gyq'), ('gyq_case_id_3', 'wx_review_id_1', 'gyq2'), - ('gyq_case_id_4', 'wx_review_id_1', 'gyq'); + ('gyq_case_id_4', 'wx_review_id_1', 'gyq'), + ('wx_case_id_3', 'wx_review_id_3', 'admin'), + ('wx_case_id_4', 'wx_review_id_4', 'admin'), + ('wx_case_id_1', 'wx_review_id_4', '123'), + ('wx_case_id_1', 'wx_review_id_4', 'admin'), + ('wx_case_id_2', 'wx_review_id_4', '123'), + ('wx_case_id_2', 'wx_review_id_4', 'admin'); INSERT INTO functional_case_module(id, project_id, name, parent_id, pos, create_time, update_time, create_user, update_user) VALUES ('wx_module_1', 'wx_test_project', '测试所属模块', 'NONE', 0, 1669174143999, 1669174143999, 'admin', '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), + ('wx_histor_1', 'wx_review_id_3', 'wx_case_id_1', NULL, 'PASS', b'0', NULL, 'admin', 1669174143999), + ('wx_history_2', 'wx_review_id_3', 'wx_case_id_3', NULL, 'PASS', b'0', NULL, 'admin', 1669174143999), + ('wx_history_3', 'wx_review_id_4', 'wx_case_id_4', NULL, 'PASS', b'0', NULL, 'A', 1669174143999), + ('wx_history_4', 'wx_review_id_4', 'wx_case_id_1', NULL, 'PASS', b'0', NULL, 'admin', 1669174143999), + ('wx_history_5', 'wx_review_id_4', 'wx_case_id_2', NULL, 'UN_PASS', b'0', NULL, 'admin', 1669174143999); + diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java index 877dc48ad6..81b02a775a 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java @@ -8,10 +8,10 @@ import io.metersphere.project.service.ProjectService; import io.metersphere.sdk.constants.ApplicationScope; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.ProjectApplicationType; -import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.User; +import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.utils.SessionUtils; @@ -40,6 +40,8 @@ public class ProjectApplicationController { @Resource private ProjectService projectService; + private static final String UNDERLINE = "_"; + /** * ==========测试计划========== */ @@ -165,7 +167,7 @@ public class ProjectApplicationController { @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateCaseLog(#application)", msClass = ProjectApplicationService.class) public void updateCase(@Validated({Updated.class}) @RequestBody ProjectApplication application) { - if (ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name().equals(application.getType())) { + if ((ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + UNDERLINE + ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name()).equals(application.getType())) { String projectDemandThirdPartConfig = projectApplicationService.getProjectDemandThirdPartConfig(application.getProjectId()); if (StringUtils.isBlank(projectDemandThirdPartConfig)) { throw new MSException(Translator.get("third_part_config_is_null")); @@ -247,7 +249,7 @@ public class ProjectApplicationController { @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateBugLog(#application)", msClass = ProjectApplicationService.class) public void updateBug(@Validated({Updated.class}) @RequestBody ProjectApplication application) { - if (ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name().equals(application.getType())) { + if ((ProjectApplicationType.BUG.BUG_SYNC.name() + UNDERLINE + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name()).equals(application.getType())) { String projectBugThirdPartConfig = projectApplicationService.getProjectBugThirdPartConfig(application.getProjectId()); if (StringUtils.isBlank(projectBugThirdPartConfig)) { throw new MSException(Translator.get("third_part_config_is_null")); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java index d06bc203f9..84ae29f3e9 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java @@ -496,7 +496,7 @@ public class ProjectApplicationControllerTests extends BaseTest { @Test @Order(34) public void testBugConfig() throws Exception { - ProjectApplication request = creatRequest(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name(), "true"); + ProjectApplication request = creatRequest(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name(), "true"); this.requestPost(BUG_UPDATE_URL, request); Map congifs = mockTestData(); @@ -516,7 +516,7 @@ public class ProjectApplicationControllerTests extends BaseTest { congifs.remove("CRON_EXPRESSION"); this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); - ProjectApplication afterRequest = creatRequest(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name(), "true"); + ProjectApplication afterRequest = creatRequest(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name(), "true"); this.requestPost(BUG_UPDATE_URL, afterRequest); } @@ -575,7 +575,7 @@ public class ProjectApplicationControllerTests extends BaseTest { @Test @Order(37) public void testCaseRelatedConfig() throws Exception { - ProjectApplication request = creatRequest(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name(), "true"); + ProjectApplication request = creatRequest(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + "_" + ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name(), "true"); this.requestPost(CASE_UPDATE_URL, request); Map configs = mockRelatedTestData(); MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_CASE_RELATED_CONFIG_URL + "/project_application_test_id", configs); @@ -593,7 +593,7 @@ public class ProjectApplicationControllerTests extends BaseTest { ResultHolder updateResultHolder = JSON.parseObject(updateData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(updateResultHolder); - ProjectApplication afterRequest = creatRequest(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name(), "true"); + ProjectApplication afterRequest = creatRequest(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + "_" + ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name(), "true"); this.requestPost(CASE_UPDATE_URL, afterRequest); }