fix(功能用例): 修复多人评审为意见时修改评审结果问题

--bug=1044075 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001044075
This commit is contained in:
guoyuqi 2024-07-17 17:08:38 +08:00 committed by Craftsman
parent 03b13de4dc
commit 61e7e37530
2 changed files with 28 additions and 25 deletions

View File

@ -522,15 +522,17 @@ public class CaseReviewFunctionalCaseService {
} }
//根据用例ID 查询所有评审人 再查所有评审人最后一次的评审结果只有通过/不通过算结果 //根据用例ID 查询所有评审人 再查所有评审人最后一次的评审结果只有通过/不通过算结果
List<CaseReviewHistory> caseReviewHistoriesExp = caseHistoryMap.get(caseReviewFunctionalCase.getCaseId()); List<CaseReviewHistory> caseReviewHistoriesExp = caseHistoryMap.get(caseReviewFunctionalCase.getCaseId());
Map<String, List<CaseReviewHistory>> hasReviewedUserMap = caseReviewHistoriesExp.stream().sorted(Comparator.comparingLong(CaseReviewHistory::getCreateTime).reversed()).collect(Collectors.groupingBy(CaseReviewHistory::getCreateUser, Collectors.toList())); Map<String, List<CaseReviewHistory>> hasReviewedUserMap = caseReviewHistoriesExp.stream().collect(Collectors.groupingBy(CaseReviewHistory::getCreateUser, Collectors.toList()));
List<CaseReviewFunctionalCaseUser> caseReviewFunctionalCaseUsersExp = reviewerMap.get(caseReviewFunctionalCase.getCaseId()); List<CaseReviewFunctionalCaseUser> caseReviewFunctionalCaseUsersExp = reviewerMap.get(caseReviewFunctionalCase.getCaseId());
AtomicInteger passCount = new AtomicInteger(); AtomicInteger passCount = new AtomicInteger();
AtomicInteger unPassCount = new AtomicInteger(); AtomicInteger unPassCount = new AtomicInteger();
hasReviewedUserMap.forEach((k, v) -> { hasReviewedUserMap.forEach((k, v) -> {
if (StringUtils.equalsIgnoreCase(v.getFirst().getStatus(), FunctionalCaseReviewStatus.PASS.toString())) { //过滤掉每个人的评审中状态每个人的评审中为建议建议不做评审结果这里排除
List<CaseReviewHistory> list = v.stream().filter(t -> !StringUtils.equalsIgnoreCase(t.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())).sorted(Comparator.comparing(CaseReviewHistory::getCreateTime).reversed()).toList();
if (CollectionUtils.isNotEmpty(list) && StringUtils.equalsIgnoreCase(list.getFirst().getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
passCount.set(passCount.get() + 1); passCount.set(passCount.get() + 1);
} }
if (StringUtils.equalsIgnoreCase(v.getFirst().getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) { if (CollectionUtils.isNotEmpty(list) && StringUtils.equalsIgnoreCase(list.getFirst().getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
unPassCount.set(unPassCount.get() + 1); unPassCount.set(unPassCount.get() + 1);
} }
}); });
@ -540,15 +542,14 @@ public class CaseReviewFunctionalCaseService {
} }
if (unPassCount.get() > 0) { if (unPassCount.get() > 0) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString()); caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_PASS.toString());
} else if (caseReviewFunctionalCaseUsersExp != null && caseReviewFunctionalCaseUsersExp.size() > hasReviewedUserMap.size()) { } else if (caseReviewFunctionalCaseUsersExp != null && (caseReviewFunctionalCaseUsersExp.size() > passCount.get()) && passCount.get() > 0) {
//通过> 0 但不是全部通过 为评审中
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()); caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString());
} else if (caseReviewFunctionalCaseUsersExp != null && passCount.get() == caseReviewFunctionalCaseUsersExp.size()) {
//检查是否全部是通过全是才是PASS
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.PASS.toString());
} else { } else {
//检查是否全部是通过全是才是PASS,否则是评审中 caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_REVIEWED.toString());
if (passCount.get() == hasReviewedUserMap.size()) {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.PASS.toString());
} else {
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString());
}
} }
} }
} }
@ -564,7 +565,7 @@ public class CaseReviewFunctionalCaseService {
if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) { if (StringUtils.equalsIgnoreCase(request.getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
if (StringUtils.isBlank(request.getContent())) { if (StringUtils.isBlank(request.getContent())) {
throw new MSException(Translator.get("case_review_content.not.exist")); throw new MSException(Translator.get("case_review_content.not.exist"));
}else { } else {
caseReviewHistory.setContent(request.getContent().getBytes()); caseReviewHistory.setContent(request.getContent().getBytes());
} }
} else { } else {
@ -820,7 +821,7 @@ public class CaseReviewFunctionalCaseService {
optionDTOS.add(optionDTO); optionDTOS.add(optionDTO);
}); });
if (CollectionUtils.isNotEmpty(users)) { if (CollectionUtils.isNotEmpty(users)) {
users.forEach(t->{ users.forEach(t -> {
OptionDTO optionDTO = new OptionDTO(); OptionDTO optionDTO = new OptionDTO();
optionDTO.setId(t.getName()); optionDTO.setId(t.getName());
optionDTO.setName(FunctionalCaseReviewStatus.UN_REVIEWED.toString()); optionDTO.setName(FunctionalCaseReviewStatus.UN_REVIEWED.toString());

View File

@ -19,6 +19,7 @@ import io.metersphere.system.mapper.UserRoleRelationMapper;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -59,7 +60,7 @@ public class ReviewFunctionalCaseService {
* @param userId 当前操作人 * @param userId 当前操作人
*/ */
public void saveReview(ReviewFunctionalCaseRequest request, String userId) { public void saveReview(ReviewFunctionalCaseRequest request, String userId) {
//保存评审历史 //获取用例所有评审人
String reviewId = request.getReviewId(); String reviewId = request.getReviewId();
String caseId = request.getCaseId(); String caseId = request.getCaseId();
CaseReviewFunctionalCaseUserExample caseReviewFunctionalCaseUserExample = new CaseReviewFunctionalCaseUserExample(); CaseReviewFunctionalCaseUserExample caseReviewFunctionalCaseUserExample = new CaseReviewFunctionalCaseUserExample();
@ -76,7 +77,7 @@ public class ReviewFunctionalCaseService {
if (!users.contains(userId)) { if (!users.contains(userId)) {
throw new MSException(Translator.get("case_review_user")); throw new MSException(Translator.get("case_review_user"));
} }
//保存评审历史
CaseReviewHistory caseReviewHistory = buildReviewHistory(request, userId); CaseReviewHistory caseReviewHistory = buildReviewHistory(request, userId);
CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample(); CaseReviewHistoryExample caseReviewHistoryExample = new CaseReviewHistoryExample();
caseReviewHistoryExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andReviewIdEqualTo(request.getReviewId()).andDeletedEqualTo(false).andAbandonedEqualTo(false); caseReviewHistoryExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andReviewIdEqualTo(request.getReviewId()).andDeletedEqualTo(false).andAbandonedEqualTo(false);
@ -150,28 +151,29 @@ public class ReviewFunctionalCaseService {
AtomicInteger passCount = new AtomicInteger(); AtomicInteger passCount = new AtomicInteger();
AtomicInteger unPassCount = new AtomicInteger(); AtomicInteger unPassCount = new AtomicInteger();
hasReviewedUserMap.forEach((k, v) -> { hasReviewedUserMap.forEach((k, v) -> {
List<CaseReviewHistory> list = v.stream().sorted(Comparator.comparing(CaseReviewHistory::getCreateTime).reversed()).toList(); //过滤掉每个人的评审中状态每个人的评审中为建议建议不做评审结果这里排除
if (StringUtils.equalsIgnoreCase(list.getFirst().getStatus(), FunctionalCaseReviewStatus.PASS.toString())) { List<CaseReviewHistory> list = v.stream().filter(t -> !StringUtils.equalsIgnoreCase(t.getStatus(), FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())).sorted(Comparator.comparing(CaseReviewHistory::getCreateTime).reversed()).toList();
if (CollectionUtils.isNotEmpty(list) && StringUtils.equalsIgnoreCase(list.getFirst().getStatus(), FunctionalCaseReviewStatus.PASS.toString())) {
passCount.set(passCount.get() + 1); passCount.set(passCount.get() + 1);
} }
if (StringUtils.equalsIgnoreCase(list.getFirst().getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) { if (CollectionUtils.isNotEmpty(list) && StringUtils.equalsIgnoreCase(list.getFirst().getStatus(), FunctionalCaseReviewStatus.UN_PASS.toString())) {
unPassCount.set(unPassCount.get() + 1); unPassCount.set(unPassCount.get() + 1);
} }
}); });
//检查是否全部是通过全是才是PASS,否则是评审中(如果时自动重新提审会有个system用户这里需要排出一下) //检查是否全部是通过全是才是PASS,否则是评审中(如果时自动重新提审会有个system用户这里需要排出一下) 建议不是评审中
if (hasReviewedUserMap.get(UserRoleScope.SYSTEM) !=null) { if (hasReviewedUserMap.get(UserRoleScope.SYSTEM) != null) {
hasReviewedUserMap.remove(UserRoleScope.SYSTEM); hasReviewedUserMap.remove(UserRoleScope.SYSTEM);
} }
if (unPassCount.get() > 0) { if (unPassCount.get() > 0) {
functionalCaseStatus = FunctionalCaseReviewStatus.UN_PASS.toString(); functionalCaseStatus = FunctionalCaseReviewStatus.UN_PASS.toString();
} else if (reviewerNum > hasReviewedUserMap.size()) { } else if (passCount.get() > 0 && passCount.get() < reviewerNum) {
//通过> 0 但不是全部通过 为评审中
functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString(); functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString();
} else if (passCount.get() == reviewerNum) {
//检查是否全部是通过全是才是PASS
functionalCaseStatus = FunctionalCaseReviewStatus.PASS.toString();
} else { } else {
if (passCount.get() == hasReviewedUserMap.size()) { functionalCaseStatus = FunctionalCaseReviewStatus.UN_REVIEWED.toString();
functionalCaseStatus = FunctionalCaseReviewStatus.PASS.toString();
} else {
functionalCaseStatus = FunctionalCaseReviewStatus.UNDER_REVIEWED.toString();
}
} }
} }
return functionalCaseStatus; return functionalCaseStatus;