fix(用例管理): 修复评审批量取消关联用例有一个用例关联多个评审导致用例最后结果计算错误问题

--bug=1036899 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036899
This commit is contained in:
guoyuqi 2024-03-07 20:23:26 +08:00 committed by 刘瑞斌
parent ab678d48c9
commit cad05038c3
1 changed files with 27 additions and 20 deletions

View File

@ -83,7 +83,7 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
Map<String, Integer> mapCount = getCaseCountMap(beforeCaseReviewFunctionalCases); Map<String, Integer> mapCount = getCaseCountMap(beforeCaseReviewFunctionalCases);
//新关联的都是未评审的这里加上 //新关联的都是未评审的这里加上
Integer i = mapCount.get(UN_REVIEWED_COUNT); Integer i = mapCount.get(UN_REVIEWED_COUNT);
mapCount.put(UN_REVIEWED_COUNT,i+caseIdList.size()); mapCount.put(UN_REVIEWED_COUNT, i + caseIdList.size());
updateCaseReview(reviewId, caseCount, mapCount, paramMap.get(CaseEvent.Param.USER_ID).toString()); updateCaseReview(reviewId, caseCount, mapCount, paramMap.get(CaseEvent.Param.USER_ID).toString());
} catch (Exception e) { } catch (Exception e) {
LogUtils.error(CaseEvent.Event.ASSOCIATE + "事件更新失败:{}", e.getMessage()); LogUtils.error(CaseEvent.Event.ASSOCIATE + "事件更新失败:{}", e.getMessage());
@ -136,11 +136,18 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
} }
} else { } else {
Map<String, List<CaseReviewFunctionalCase>> collect = otherReviewFunctionalCases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getCaseId)); Map<String, List<CaseReviewFunctionalCase>> collect = otherReviewFunctionalCases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getCaseId));
collect.forEach((caseId,caseList)->{ collect.forEach((caseId, caseList) -> {
if (!caseIdList.contains(caseId)) {
FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setId(caseId);
functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.toString());
mapper.updateByPrimaryKeySelective(functionalCase);
} else {
FunctionalCase functionalCase = new FunctionalCase(); FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setId(caseId); functionalCase.setId(caseId);
functionalCase.setReviewStatus(caseList.get(0).getStatus()); functionalCase.setReviewStatus(caseList.get(0).getStatus());
mapper.updateByPrimaryKeySelective(functionalCase); mapper.updateByPrimaryKeySelective(functionalCase);
}
}); });
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
@ -195,7 +202,7 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
try { try {
Object caseIds = paramMap.get(CaseEvent.Param.CASE_IDS); Object caseIds = paramMap.get(CaseEvent.Param.CASE_IDS);
List<String> caseIdList = JSON.parseArray(JSON.toJSONString(caseIds), String.class); List<String> caseIdList = JSON.parseArray(JSON.toJSONString(caseIds), String.class);
if(CollectionUtils.isEmpty(caseIdList)){ if (CollectionUtils.isEmpty(caseIdList)) {
return; return;
} }
CaseReviewFunctionalCaseExample functionalCaseExample = new CaseReviewFunctionalCaseExample(); CaseReviewFunctionalCaseExample functionalCaseExample = new CaseReviewFunctionalCaseExample();
@ -242,28 +249,28 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
} }
Object caseIds = paramMap.get(CaseEvent.Param.CASE_IDS); Object caseIds = paramMap.get(CaseEvent.Param.CASE_IDS);
List<String> caseIdList = JSON.parseArray(JSON.toJSONString(caseIds), String.class); List<String> caseIdList = JSON.parseArray(JSON.toJSONString(caseIds), String.class);
if(CollectionUtils.isEmpty(caseIdList)){ if (CollectionUtils.isEmpty(caseIdList)) {
return; return;
} }
Object statusObjMap = paramMap.get(CaseEvent.Param.STATUS_MAP); Object statusObjMap = paramMap.get(CaseEvent.Param.STATUS_MAP);
Map<String,String> statusMap = JSON.parseMap(JSON.toJSONString(statusObjMap)); Map<String, String> statusMap = JSON.parseMap(JSON.toJSONString(statusObjMap));
updateFunctionalCase(statusMap); updateFunctionalCase(statusMap);
List<CaseReviewFunctionalCase> caseReviewFunctionalCases = extCaseReviewFunctionalCaseMapper.getListExcludes(List.of(reviewId), caseIdList, false); List<CaseReviewFunctionalCase> caseReviewFunctionalCases = extCaseReviewFunctionalCaseMapper.getListExcludes(List.of(reviewId), caseIdList, false);
Map<String, Integer> caseCountMap = getCaseCountMap(caseReviewFunctionalCases); Map<String, Integer> caseCountMap = getCaseCountMap(caseReviewFunctionalCases);
Object mapCount = paramMap.get(CaseEvent.Param.COUNT_MAP); Object mapCount = paramMap.get(CaseEvent.Param.COUNT_MAP);
Map<String,Integer> map = JSON.parseMap(JSON.toJSONString(mapCount)); Map<String, Integer> map = JSON.parseMap(JSON.toJSONString(mapCount));
updateMapCount(map, caseCountMap); updateMapCount(map, caseCountMap);
updateCaseReview(reviewId, caseReviewFunctionalCases.size()+caseIdList.size(), caseCountMap, paramMap.get(CaseEvent.Param.USER_ID).toString()); updateCaseReview(reviewId, caseReviewFunctionalCases.size() + caseIdList.size(), caseCountMap, paramMap.get(CaseEvent.Param.USER_ID).toString());
} catch (Exception e) { } catch (Exception e) {
LogUtils.error(CaseEvent.Event.REVIEW_FUNCTIONAL_CASE + "事件更新失败:{}", e.getMessage()); LogUtils.error(CaseEvent.Event.REVIEW_FUNCTIONAL_CASE + "事件更新失败:{}", e.getMessage());
} }
} }
private void updateFunctionalCase(Map<String,String> statusMap) { private void updateFunctionalCase(Map<String, String> statusMap) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
FunctionalCaseMapper mapper = sqlSession.getMapper(FunctionalCaseMapper.class); FunctionalCaseMapper mapper = sqlSession.getMapper(FunctionalCaseMapper.class);
statusMap.forEach((castId,status)->{ statusMap.forEach((castId, status) -> {
FunctionalCase functionalCase = new FunctionalCase(); FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setId(castId); functionalCase.setId(castId);
functionalCase.setReviewStatus(status); functionalCase.setReviewStatus(status);
@ -277,23 +284,23 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
private static void updateMapCount(Map<String, Integer> map, Map<String, Integer> caseCountMap) { private static void updateMapCount(Map<String, Integer> map, Map<String, Integer> caseCountMap) {
if (map.get(FunctionalCaseReviewStatus.UN_REVIEWED.toString()) != null) { if (map.get(FunctionalCaseReviewStatus.UN_REVIEWED.toString()) != null) {
Integer i = caseCountMap.get(UN_REVIEWED_COUNT); Integer i = caseCountMap.get(UN_REVIEWED_COUNT);
caseCountMap.put(UN_REVIEWED_COUNT, map.get(FunctionalCaseReviewStatus.UN_REVIEWED.toString())+i); caseCountMap.put(UN_REVIEWED_COUNT, map.get(FunctionalCaseReviewStatus.UN_REVIEWED.toString()) + i);
} }
if (map.get(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()) != null) { if (map.get(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()) != null) {
Integer i = caseCountMap.get(UNDER_REVIEWED_COUNT); Integer i = caseCountMap.get(UNDER_REVIEWED_COUNT);
caseCountMap.put(UNDER_REVIEWED_COUNT, map.get(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString())+i); caseCountMap.put(UNDER_REVIEWED_COUNT, map.get(FunctionalCaseReviewStatus.UNDER_REVIEWED.toString()) + i);
} }
if (map.get(FunctionalCaseReviewStatus.PASS.toString()) != null) { if (map.get(FunctionalCaseReviewStatus.PASS.toString()) != null) {
Integer i = caseCountMap.get(PASS_COUNT); Integer i = caseCountMap.get(PASS_COUNT);
caseCountMap.put(PASS_COUNT, map.get(FunctionalCaseReviewStatus.PASS.toString())+i); caseCountMap.put(PASS_COUNT, map.get(FunctionalCaseReviewStatus.PASS.toString()) + i);
} }
if (map.get(FunctionalCaseReviewStatus.UN_PASS.toString()) != null) { if (map.get(FunctionalCaseReviewStatus.UN_PASS.toString()) != null) {
Integer i = caseCountMap.get(UN_PASS_COUNT); Integer i = caseCountMap.get(UN_PASS_COUNT);
caseCountMap.put(UN_PASS_COUNT, map.get(FunctionalCaseReviewStatus.UN_PASS.toString())+i); caseCountMap.put(UN_PASS_COUNT, map.get(FunctionalCaseReviewStatus.UN_PASS.toString()) + i);
} }
if (map.get(FunctionalCaseReviewStatus.RE_REVIEWED.toString()) != null) { if (map.get(FunctionalCaseReviewStatus.RE_REVIEWED.toString()) != null) {
Integer i = caseCountMap.get(RE_REVIEWED_COUNT); Integer i = caseCountMap.get(RE_REVIEWED_COUNT);
caseCountMap.put(RE_REVIEWED_COUNT, map.get(FunctionalCaseReviewStatus.RE_REVIEWED.toString())+i); caseCountMap.put(RE_REVIEWED_COUNT, map.get(FunctionalCaseReviewStatus.RE_REVIEWED.toString()) + i);
} }
} }