fix(用例管理): 修复用例评审修改评审人后评审结果不正确问题

--bug=1035917 --user=王旭 【用例评审】多人通过的评审,批量修改评审人,保留有评审结果为通过的评审人,修改后,用例的评审结果错误 https://www.tapd.cn/55049933/s/1463962
This commit is contained in:
WangXu10 2024-02-22 16:27:23 +08:00 committed by 刘瑞斌
parent 5a67c18bda
commit deb0a5fc4e
4 changed files with 76 additions and 37 deletions

View File

@ -94,6 +94,7 @@
<foreach collection="caseIds" item="caseId" separator="," open="(" close=")"> <foreach collection="caseIds" item="caseId" separator="," open="(" close=")">
#{caseId} #{caseId}
</foreach> </foreach>
AND deleted = FALSE
AND abandoned = FALSE AND abandoned = FALSE
AND status != 'UNDER_REVIEWED' AND status != 'UNDER_REVIEWED'
order by create_time desc order by create_time desc

View File

@ -555,16 +555,14 @@ public class CaseReviewFunctionalCaseService {
List<CaseReviewFunctionalCaseUser> newReviewers = caseReviewFunctionalCaseUserMapper.selectByExample(example); List<CaseReviewFunctionalCaseUser> newReviewers = caseReviewFunctionalCaseUserMapper.selectByExample(example);
Map<String, List<CaseReviewFunctionalCaseUser>> newReviewersMap = newReviewers.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCaseUser::getCaseId)); Map<String, List<CaseReviewFunctionalCaseUser>> newReviewersMap = newReviewers.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCaseUser::getCaseId));
CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample(); List<CaseReviewHistory> caseReviewHistories = extCaseReviewHistoryMapper.getReviewHistoryStatus(caseIds, request.getReviewId());
caseReviewHistoryExample.createCriteria().andCaseIdIn(caseIds).andReviewIdEqualTo(request.getReviewId()).andDeletedEqualTo(false).andAbandonedEqualTo(false);
List<CaseReviewHistory> caseReviewHistories = caseReviewHistoryMapper.selectByExample(caseReviewHistoryExample);
Map<String, List<CaseReviewHistory>> caseHistoryMap = caseReviewHistories.stream().collect(Collectors.groupingBy(CaseReviewHistory::getCaseId, Collectors.toList())); Map<String, List<CaseReviewHistory>> caseHistoryMap = caseReviewHistories.stream().collect(Collectors.groupingBy(CaseReviewHistory::getCaseId, Collectors.toList()));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
Map<String, String> statusMap = new HashMap<>(); Map<String, String> statusMap = new HashMap<>();
CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class); CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class);
cases.forEach(caseReview -> { cases.forEach(caseReview -> {
String status = multipleReview(caseReview, caseHistoryMap.get(caseReview.getCaseId()), newReviewersMap.get(caseReview.getCaseId()), oldReviewUserMap.get(caseReview.getCaseId())); String status = multipleReview(caseHistoryMap.get(caseReview.getCaseId()), newReviewersMap.get(caseReview.getCaseId()));
caseReview.setStatus(status); caseReview.setStatus(status);
caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(caseReview); caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(caseReview);
statusMap.put(caseReview.getCaseId(), caseReview.getStatus()); statusMap.put(caseReview.getCaseId(), caseReview.getStatus());
@ -588,38 +586,50 @@ public class CaseReviewFunctionalCaseService {
} }
private String multipleReview(CaseReviewFunctionalCase caseReviewFunctionalCase, List<CaseReviewHistory> reviewHistories, List<CaseReviewFunctionalCaseUser> newReviewers, List<CaseReviewFunctionalCaseUser> oldReviewers) { private String multipleReview(List<CaseReviewHistory> reviewHistories, List<CaseReviewFunctionalCaseUser> newReviewers) {
if (CollectionUtils.isNotEmpty(reviewHistories)) { if (CollectionUtils.isNotEmpty(reviewHistories)) {
List<String> historyUsers = reviewHistories.stream().map(CaseReviewHistory::getCreateUser).toList(); //历史的评审人
List<String> newUsers = newReviewers.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList(); List<String> historyUsers = reviewHistories.stream().map(CaseReviewHistory::getCreateUser).collect(Collectors.toList());
if (CollectionUtils.isEmpty(oldReviewers)) { //最新的评审人
oldReviewers = new ArrayList<>(); List<String> newUsers = newReviewers.stream().map(CaseReviewFunctionalCaseUser::getUserId).collect(Collectors.toList());
return newReviewStatus(historyUsers, newUsers, reviewHistories, newReviewers);
} else {
return FunctionalCaseReviewStatus.UN_REVIEWED.name();
} }
List<String> oldUsers = oldReviewers.stream().map(CaseReviewFunctionalCaseUser::getUserId).toList();
if (CollectionUtils.isEqualCollection(newUsers, oldUsers)) {
return caseReviewFunctionalCase.getStatus();
} }
Collection intersection = CollectionUtils.intersection(historyUsers, newUsers); private String newReviewStatus(List<String> historyUsers, List<String> newUsers, List<CaseReviewHistory> reviewHistories, List<CaseReviewFunctionalCaseUser> newReviewers) {
if (CollectionUtils.isNotEmpty(intersection)) { CaseReviewHistory caseReviewHistory = reviewHistories.get(0);
//存在已经评审的人 状态列表 if (newUsers.contains(caseReviewHistory.getCreateUser()) && FunctionalCaseReviewStatus.RE_REVIEWED.name().equals(caseReviewHistory.getStatus())) {
List<String> statusList = reviewHistories.stream().filter(item -> intersection.contains(item.getCreateUser())).map(CaseReviewHistory::getStatus).toList(); return FunctionalCaseReviewStatus.RE_REVIEWED.name();
if (statusList.contains(FunctionalCaseReviewStatus.UN_PASS.name())) { }
if (historyUsers.containsAll(newUsers)) {
//新的评审人都存在过评审记录
return getReviewStatus(newUsers, reviewHistories, FunctionalCaseReviewStatus.PASS.name());
} else {
//新的评审人有评审历史中不存在的用户
newUsers.retainAll(historyUsers);
return getReviewStatus(newUsers, reviewHistories, FunctionalCaseReviewStatus.UNDER_REVIEWED.name());
}
}
private String getReviewStatus(List<String> newUsers, List<CaseReviewHistory> reviewHistories, String reviewStatus) {
List<String> statusList = new ArrayList<>();
//拿到这个人评审的最后一条状态
newUsers.forEach(item -> {
String status = reviewHistories.stream().filter(history -> StringUtils.equalsIgnoreCase(item, history.getCreateUser())).findFirst().get().getStatus();
statusList.add(status);
});
if (CollectionUtils.isEmpty(statusList)) {
return FunctionalCaseReviewStatus.UN_REVIEWED.name();
}
if (statusList.stream().anyMatch(item -> FunctionalCaseReviewStatus.UN_PASS.name().equals(item))) {
return 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 reviewStatus;
return FunctionalCaseReviewStatus.PASS.name();
} else {
return FunctionalCaseReviewStatus.UNDER_REVIEWED.name();
}
} else {
return FunctionalCaseReviewStatus.UN_REVIEWED.name();
}
} else {
return FunctionalCaseReviewStatus.UN_REVIEWED.name();
}
} }

View File

@ -506,6 +506,21 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
request.setSelectIds(List.of("wx_test_8", "wx_test_9", "wx_test_10")); request.setSelectIds(List.of("wx_test_8", "wx_test_9", "wx_test_10"));
this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request); this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request);
request.setReviewId("wx_review_id_6");
request.setReviewerId(List.of("wx11"));
request.setSelectIds(List.of("wx_test_12"));
this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request);
request.setReviewId("wx_review_id_8");
request.setReviewerId(List.of("admin"));
request.setSelectIds(List.of("wx_test_13"));
this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request);
request.setReviewId("wx_review_id_9");
request.setReviewerId(List.of("admin"));
request.setSelectIds(List.of("wx_test_14"));
this.requestPostWithOkAndReturn(BATCH_EDIT_REVIEWERS, request);
//追加评审人 //追加评审人
request.setAppend(true); request.setAppend(true);
request.setReviewId("wx_review_id_4"); request.setReviewId("wx_review_id_4");

View File

@ -18,7 +18,10 @@ VALUES ('gyq_case_id_5', 102, 'TEST_MODULE_ID', 'wx_test_project', '100001', '
('gyq_case_id_a', 105, 'TEST_MODULE_ID_COUNT_five', 'wx_test_project_review_two', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), ('gyq_case_id_a', 105, 'TEST_MODULE_ID_COUNT_five', 'wx_test_project_review_two', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_b', 105, 'TEST_MODULE_ID_COUNT_six', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), ('gyq_case_id_b', 105, 'TEST_MODULE_ID_COUNT_six', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_c', 105, 'TEST_MODULE_ID_COUNT_seven', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), ('gyq_case_id_c', 105, 'TEST_MODULE_ID_COUNT_seven', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_d', 105, 'root', 'wx_test_project_review_one', '100001', '测试默认模块', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_d', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); ('gyq_case_id_d', 105, 'root', 'wx_test_project_review_one', '100001', '测试默认模块', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_d', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('wx_test_id_7', 105, 'root', 'wx_test_project', '100001', '测试默认模块', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'wx_test_id_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('wx_test_id_8', 105, 'root', 'wx_test_project', '100001', '测试默认模块', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'wx_test_id_7', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('wx_test_id_9', 105, 'root', 'wx_test_project', '100001', '测试默认模块', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'wx_test_id_7', '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) 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)
@ -49,7 +52,10 @@ VALUES ('wx_review_id_1',10001,'wx1', 'wx_module_1', 'wx_test_project', 'COMPLET
('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_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'), ('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'),
('wx_review_id_5',10004,'gyq5', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'); ('wx_review_id_5',10004,'gyq5', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_6',10005,'wx6', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_8',10007,'wx8', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_9',10007,'wx8', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin');
; ;
@ -73,7 +79,10 @@ VALUES ('wx_test_1', 'wx_review_id_1', 'wx_case_id_1', 'PASS', 1698058347559,'ad
('wx_test_8', 'wx_review_id_4', 'wx_case_id_4', '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_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), ('wx_test_10', 'wx_review_id_4', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_11', 'wx_review_id_5', 'gyq_case_id_d', 'PASS', 1698058347559,'admin',1698058347559, 3000); ('wx_test_11', 'wx_review_id_5', 'gyq_case_id_d', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_12', 'wx_review_id_6', 'wx_test_id_7', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_13', 'wx_review_id_8', 'wx_test_id_8', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_14', 'wx_review_id_9', 'wx_test_id_9', 'PASS', 1698058347559,'admin',1698058347559, 3000);
INSERT INTO case_review_functional_case_user(case_id, review_id, user_id) INSERT INTO case_review_functional_case_user(case_id, review_id, user_id)
VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'), VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'),
@ -89,7 +98,9 @@ VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'),
('wx_case_id_1', 'wx_review_id_4', 'admin'), ('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', '123'),
('wx_case_id_2', 'wx_review_id_4', 'admin'), ('wx_case_id_2', 'wx_review_id_4', 'admin'),
('gyq_case_id_d', 'wx_review_id_5', 'admin'); ('gyq_case_id_d', 'wx_review_id_5', 'admin'),
('wx_test_id_8', 'wx_review_id_8', 'admin'),
('wx_test_id_9', 'wx_review_id_9', 'admin');
@ -134,7 +145,9 @@ VALUES ('wx_history', 'wx_review_id_3', 'wx_case_id_1', NULL, 'PASS', b'0', b'0'
('wx_history_6', 'wx_review_id_1', 'gyq_case_id_5', NULL, 'PASS', b'0', b'0', NULL, 'gyq_case_review', 1669174143999), ('wx_history_6', 'wx_review_id_1', 'gyq_case_id_5', NULL, 'PASS', b'0', b'0', NULL, 'gyq_case_review', 1669174143999),
('wx_history_7', 'wx_review_id_1', 'gyq_case_id_5', NULL, 'UN_PASS', b'0', b'0', NULL, 'GGG', 1669174143999), ('wx_history_7', 'wx_review_id_1', 'gyq_case_id_5', NULL, 'UN_PASS', b'0', b'0', NULL, 'GGG', 1669174143999),
('wx_history_8', 'wx_review_id_1', 'wx_case_id_1', NULL, 'UN_PASS', b'0', b'0', NULL, 'admin', 1669174143999), ('wx_history_8', 'wx_review_id_1', 'wx_case_id_1', NULL, 'UN_PASS', b'0', b'0', NULL, 'admin', 1669174143999),
('wx_history_9', 'wx_review_id_5', 'gyq_case_id_d', NULL, 'RE_REVIEWED', b'0', b'0', NULL, 'GGG', 1669174143999); ('wx_history_9', 'wx_review_id_5', 'gyq_case_id_d', NULL, 'RE_REVIEWED', b'0', b'0', NULL, 'GGG', 1669174143999),
('wx_history_19', 'wx_review_id_8', 'wx_test_id_8', NULL, 'RE_REVIEWED', b'0', b'0', NULL, 'admin', 1669174143999),
('wx_history_20', 'wx_review_id_9', 'wx_test_id_9', NULL, 'UN_PASS', b'0', b'0', NULL, 'admin', 1669174143999);
INSERT INTO case_review_user(review_id, user_id) INSERT INTO case_review_user(review_id, user_id)
VALUES ('wx_review_id_4', 'admin') VALUES ('wx_review_id_4', 'admin')