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 cf50c5b73d..eb77e38da4 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 @@ -84,7 +84,8 @@ public class CaseReviewFunctionalCaseService { private FunctionalCaseModuleService functionalCaseModuleService; @Resource private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper; - + @Resource + private CaseReviewUserMapper caseReviewUserMapper; private static final String CASE_MODULE_COUNT_ALL = "all"; @@ -157,7 +158,6 @@ public class CaseReviewFunctionalCaseService { } - public List doSelectIds(BaseReviewCaseBatchRequest request) { if (request.isSelectAll()) { List ids = extCaseReviewFunctionalCaseMapper.getIds(request, request.getUserId(), false); @@ -200,13 +200,41 @@ public class CaseReviewFunctionalCaseService { reviewFunctionalCase.setPos(caseReviewService.getCaseFunctionalCaseNextPos(reviewId)); caseReviewFunctionalCaseMapper.insertSelective(reviewFunctionalCase); + //评审人 + CaseReviewUserExample caseReviewUserExample = new CaseReviewUserExample(); + caseReviewUserExample.createCriteria().andReviewIdEqualTo(reviewId); + List caseReviewUsers = caseReviewUserMapper.selectByExample(caseReviewUserExample); + if (CollectionUtils.isNotEmpty(caseReviewUsers)) { + List list = new ArrayList<>(); + caseReviewUsers.forEach(item -> { + CaseReviewFunctionalCaseUser caseUser = new CaseReviewFunctionalCaseUser(); + caseUser.setCaseId(caseId); + caseUser.setReviewId(reviewId); + caseUser.setUserId(item.getUserId()); + list.add(caseUser); + }); + caseReviewFunctionalCaseUserMapper.batchInsert(list); + //更新评审的整体状态 + Map countMap = new HashMap<>(); + countMap.put(reviewFunctionalCase.getStatus(), 1); + Map statusMap = new HashMap<>(); + statusMap.put(caseId, reviewFunctionalCase.getStatus()); + Map param = new HashMap<>(); + param.put(CaseEvent.Param.REVIEW_ID, reviewId); + param.put(CaseEvent.Param.USER_ID, userId); + param.put(CaseEvent.Param.CASE_IDS, List.of(caseId)); + param.put(CaseEvent.Param.COUNT_MAP, countMap); + param.put(CaseEvent.Param.STATUS_MAP, statusMap); + param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.REVIEW_FUNCTIONAL_CASE); + provider.updateCaseReview(param); + } } /** * 用例更新 更新状态为重新评审 */ - public void reReviewedCase(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name) { + public void reReviewedCase(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name, String userId) { ProjectApplicationExample example = new ProjectApplicationExample(); example.createCriteria().andProjectIdEqualTo(request.getProjectId()).andTypeEqualTo(ProjectApplicationType.CASE.CASE_RE_REVIEW.name()); List projectApplications = projectApplicationMapper.selectByExample(example); @@ -215,12 +243,12 @@ public class CaseReviewFunctionalCaseService { || !StringUtils.equals(new String(blob.getSteps(), StandardCharsets.UTF_8), request.getSteps()) || !StringUtils.equals(new String(blob.getTextDescription(), StandardCharsets.UTF_8), request.getTextDescription()) || !StringUtils.equals(new String(blob.getExpectedResult(), StandardCharsets.UTF_8), request.getExpectedResult())) { - doHandleStatusAndHistory(request, blob, name); + doHandleStatusAndHistory(blob, userId); } } } - private void doHandleStatusAndHistory(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name) { + private void doHandleStatusAndHistory(FunctionalCaseBlob blob, String userId) { CaseReviewFunctionalCaseExample reviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); reviewFunctionalCaseExample.createCriteria().andCaseIdEqualTo(blob.getId()); List caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(reviewFunctionalCaseExample); @@ -228,6 +256,20 @@ public class CaseReviewFunctionalCaseService { caseReviewFunctionalCases.forEach(item -> { updateReviewCaseAndCaseStatus(item); insertHistory(item); + //更新用例触发重新提审-需要重新计算评审的整体状态 + Map countMap = new HashMap<>(); + countMap.put(item.getStatus(), 1); + Map statusMap = new HashMap<>(); + statusMap.put(item.getCaseId(), item.getStatus()); + Map param = new HashMap<>(); + param.put(CaseEvent.Param.REVIEW_ID, item.getReviewId()); + param.put(CaseEvent.Param.USER_ID, userId); + param.put(CaseEvent.Param.CASE_IDS, List.of(item.getCaseId())); + param.put(CaseEvent.Param.COUNT_MAP, countMap); + param.put(CaseEvent.Param.STATUS_MAP, statusMap); + param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.REVIEW_FUNCTIONAL_CASE); + provider.updateCaseReview(param); + }); } } @@ -294,14 +336,14 @@ public class CaseReviewFunctionalCaseService { CaseReviewHistoryMapper caseReviewHistoryMapper = sqlSession.getMapper(CaseReviewHistoryMapper.class); CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class); - MapstatusMap = new HashMap<>(); + 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())){ - LogUtils.error(caseId+": no review user, please check"); + if (CollectionUtils.isEmpty(userList) || CollectionUtils.isEmpty(userList.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getUserId(), userId)).toList())) { + LogUtils.error(caseId + ": no review user, please check"); continue; } @@ -316,7 +358,7 @@ public class CaseReviewFunctionalCaseService { } //根据评审规则更新用例评审和功能用例关系表中的状态 1.单人评审直接更新评审结果 2.多人评审需要计算 setStatus(request, caseReviewFunctionalCase, caseHistoryMap, reviewerMap); - statusMap.put(caseReviewFunctionalCase.getCaseId(),caseReviewFunctionalCase.getStatus()); + statusMap.put(caseReviewFunctionalCase.getCaseId(), caseReviewFunctionalCase.getStatus()); caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(caseReviewFunctionalCase); //检查是否有@,发送@通知 @@ -332,7 +374,7 @@ public class CaseReviewFunctionalCaseService { reviewSendNoticeService.sendNoticeCase(new ArrayList<>(), userId, caseId, NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.REVIEW_PASSED, reviewId); } - functionalCaseAttachmentService.uploadMinioFile(caseId,caseProjectIdMap.get(caseId),request.getReviewCommentFileIds(),userId, CaseFileSourceType.REVIEW_COMMENT.toString()); + functionalCaseAttachmentService.uploadMinioFile(caseId, caseProjectIdMap.get(caseId), request.getReviewCommentFileIds(), userId, CaseFileSourceType.REVIEW_COMMENT.toString()); } sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); @@ -340,8 +382,8 @@ public class CaseReviewFunctionalCaseService { Map param = new HashMap<>(); Map> collect = caseReviewFunctionalCaseList.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getStatus)); Map countMap = new HashMap<>(); - collect.forEach((k,v)->{ - countMap.put(k,v.size()); + collect.forEach((k, v) -> { + countMap.put(k, v.size()); }); param.put(CaseEvent.Param.CASE_IDS, CollectionUtils.isNotEmpty(caseIds) ? caseIds : new ArrayList<>()); param.put(CaseEvent.Param.REVIEW_ID, reviewId); @@ -441,7 +483,7 @@ public class CaseReviewFunctionalCaseService { Map> caseHistoryMap = caseReviewHistories.stream().collect(Collectors.groupingBy(CaseReviewHistory::getCaseId, Collectors.toList())); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - MapstatusMap = new HashMap<>(); + Map statusMap = new HashMap<>(); 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())); @@ -453,8 +495,8 @@ public class CaseReviewFunctionalCaseService { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); Map> collect = cases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getStatus)); Map countMap = new HashMap<>(); - collect.forEach((k,v)->{ - countMap.put(k,v.size()); + collect.forEach((k, v) -> { + countMap.put(k, v.size()); }); Map param = new HashMap<>(); param.put(CaseEvent.Param.REVIEW_ID, request.getReviewId()); @@ -563,11 +605,10 @@ public class CaseReviewFunctionalCaseService { /** * 查找当前项目下模块每个节点对应的资源统计 - * */ public Map getModuleCountMap(String projectId, String reviewId, List moduleCountDTOList) { //构建模块树,并计算每个节点下的所有数量(包含子节点) - List treeNodeList = this.getTreeOnlyIdsAndResourceCount(projectId,reviewId, moduleCountDTOList); + List treeNodeList = this.getTreeOnlyIdsAndResourceCount(projectId, reviewId, moduleCountDTOList); //通过广度遍历的方式构建返回值 return functionalCaseModuleService.getIdCountMapByBreadth(treeNodeList); } @@ -582,8 +623,8 @@ public class CaseReviewFunctionalCaseService { public List getUserStatus(String reviewId, String caseId) { List list = extCaseReviewHistoryMapper.list(caseId, reviewId); Map> collect = list.stream().sorted(Comparator.comparingLong(CaseReviewHistoryDTO::getCreateTime).reversed()).collect(Collectors.groupingBy(CaseReviewHistoryDTO::getCreateUser, Collectors.toList())); - ListoptionDTOS = new ArrayList<>(); - collect.forEach((k,v)->{ + List optionDTOS = new ArrayList<>(); + collect.forEach((k, v) -> { OptionDTO optionDTO = new OptionDTO(); optionDTO.setId(v.get(0).getUserName()); optionDTO.setName(v.get(0).getStatus()); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 2808606f67..cf4339a139 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -395,14 +395,14 @@ public class FunctionalCaseService { } //处理评审状态 - handleReviewStatus(request, functionalCaseBlob, checked.getName()); + handleReviewStatus(request, functionalCaseBlob, checked.getName(), userId); return functionalCase; } - private void handleReviewStatus(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name) { - caseReviewFunctionalCaseService.reReviewedCase(request, blob, name); + private void handleReviewStatus(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name, String userId) { + caseReviewFunctionalCaseService.reReviewedCase(request, blob, name, userId); } 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 46428d9af8..85bc6752c5 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 @@ -198,6 +198,12 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(resultHolder); + + request.setReviewId("wx_review_id_4"); + paramMap = new LinkedMultiValueMap<>(); + paramMap.add("request", JSON.toJSONString(request)); + paramMap.add("files", files); + this.requestMultipartWithOkAndReturn(FUNCTIONAL_CASE_ADD_URL, paramMap); } @Test 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 eceb7095a9..c9ba8a1e36 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 @@ -102,3 +102,5 @@ VALUES ('wx_history', 'wx_review_id_3', 'wx_case_id_1', NULL, 'PASS', b'0', NULL ('wx_history_6', 'wx_review_id_1', 'gyq_case_id_5', NULL, 'PASS', b'0', NULL, 'gyq_case_review', 1669174143999), ('wx_history_7', 'wx_review_id_1', 'gyq_case_id_5', NULL, 'UN_PASS', b'0', NULL, 'GGG', 1669174143999); +INSERT INTO case_review_user(review_id, user_id) +VALUES ('wx_review_id_4', 'admin') \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java index b553f7c6a7..e36b465550 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/TemplateCustomFieldDTO.java @@ -41,4 +41,7 @@ public class TemplateCustomFieldDTO { @Schema(title = "搜索调用方法") private String optionMethod; + + @Schema(description = "是否内置字段") + private Boolean internal; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java index 6fd6b730d9..c3230b3d82 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTemplateService.java @@ -122,6 +122,7 @@ public class BaseTemplateService { BeanUtils.copyBean(templateCustomFieldDTO, i); templateCustomFieldDTO.setFieldName(customField.getName()); templateCustomFieldDTO.setType(customField.getType()); + templateCustomFieldDTO.setInternal(customField.getInternal()); AbstractCustomFieldResolver customFieldResolver = CustomFieldResolverFactory.getResolver(customField.getType()); Object defaultValue = null; try {