feat(用例管理): 增加用例评审删除,状态变成上一个评审的状态功能

--task=1016125 --user=郭雨琦 https://www.tapd.cn/55049933/prong/tasks/view/1155049933001016125
This commit is contained in:
guoyuqi 2024-08-21 09:47:23 +08:00 committed by 刘瑞斌
parent d4b7cec42b
commit c22c9c47af
2 changed files with 73 additions and 5 deletions

View File

@ -80,8 +80,6 @@ public class CaseReviewService {
@Resource @Resource
private BaseCaseProvider provider; private BaseCaseProvider provider;
@Resource @Resource
private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper;
@Resource
private UserLoginService userLoginService; private UserLoginService userLoginService;
@ -619,9 +617,41 @@ public class CaseReviewService {
} }
public void deleteCaseReview(String reviewId, String projectId) { public void deleteCaseReview(String reviewId, String projectId) {
CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(reviewId);
List<CaseReviewFunctionalCase> caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample);
List<String> caseIds = caseReviewFunctionalCases.stream().map(CaseReviewFunctionalCase::getCaseId).toList();
deleteCaseReviewService.deleteCaseReviewResource(List.of(reviewId), projectId); deleteCaseReviewService.deleteCaseReviewResource(List.of(reviewId), projectId);
//将评审历史状态置为true //将用例置为上一次的评审的结果
extCaseReviewHistoryMapper.updateDelete(new ArrayList<>(), reviewId, true); if (CollectionUtils.isEmpty(caseIds)) {
return;
}
caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andCaseIdIn(caseIds);
caseReviewFunctionalCaseExample.setOrderByClause("update_time DESC");
caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample);
Map<String, List<CaseReviewFunctionalCase>> caseReviewMap = caseReviewFunctionalCases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getCaseId));
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
FunctionalCaseMapper mapper = sqlSession.getMapper(FunctionalCaseMapper.class);
try {
for (String caseId : caseIds) {
FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setId(caseId);
String status;
List<CaseReviewFunctionalCase> statuList = caseReviewMap.get(caseId);
if (CollectionUtils.isNotEmpty(statuList)) {
List<CaseReviewFunctionalCase> list = statuList.stream().sorted(Comparator.comparing(CaseReviewFunctionalCase::getUpdateTime).reversed()).toList();
status = list.getFirst().getStatus();
} else {
status = FunctionalCaseReviewStatus.UN_REVIEWED.toString();
}
functionalCase.setReviewStatus(status);
mapper.updateByPrimaryKeySelective(functionalCase);
}
sqlSession.flushStatements();
} finally {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
} }
public void disassociate(String reviewId, String caseId, String userId) { public void disassociate(String reviewId, String caseId, String userId) {

View File

@ -623,7 +623,45 @@ public class CaseReviewControllerTests extends BaseTest {
public void testDelete() throws Exception { public void testDelete() throws Exception {
List<CaseReview> caseReviews = getCaseReviews("创建评审更新2"); List<CaseReview> caseReviews = getCaseReviews("创建评审更新2");
delCaseReview(caseReviews.getFirst().getId()); delCaseReview(caseReviews.getFirst().getId());
CaseReview caseReview = new CaseReview();
String id = UUID.randomUUID().toString();
caseReview.setId(id);
caseReview.setNum(1001L);
caseReview.setPos(1020L);
caseReview.setCaseCount(2);
caseReview.setStatus(FunctionalCaseReviewStatus.UN_REVIEWED.toString());
caseReview.setPassRate(BigDecimal.ZERO);
caseReview.setName("dddd");
caseReview.setModuleId("root");
caseReview.setProjectId(DEFAULT_PROJECT_ID );
caseReview.setReviewPassRule(CaseReviewPassRule.SINGLE.toString());
caseReview.setCreateUser("Gyq");
caseReview.setCreateTime(System.currentTimeMillis());
caseReview.setUpdateTime(System.currentTimeMillis());
caseReview.setUpdateUser("Gyq");
caseReviewMapper.insert(caseReview);
CaseReviewFunctionalCase caseReviewFunctionalCase = new CaseReviewFunctionalCase();
caseReviewFunctionalCase.setCaseId("CASE_REVIEW_TEST_GYQ_ID2");
caseReviewFunctionalCase.setReviewId(id);
caseReviewFunctionalCase.setId(UUID.randomUUID().toString());
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.PASS.name());
caseReviewFunctionalCase.setPos(110L);
caseReviewFunctionalCase.setCreateUser("Gyq");
caseReviewFunctionalCase.setCreateTime(System.currentTimeMillis());
caseReviewFunctionalCase.setUpdateTime(System.currentTimeMillis());
caseReviewFunctionalCaseMapper.insert(caseReviewFunctionalCase);
caseReviewFunctionalCase = new CaseReviewFunctionalCase();
caseReviewFunctionalCase.setId(UUID.randomUUID().toString());
caseReviewFunctionalCase.setCaseId("CASE_REVIEW_TEST_GYQ_ID3");
caseReviewFunctionalCase.setReviewId(id);
caseReviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.PASS.name());
caseReviewFunctionalCase.setPos(110L);
caseReviewFunctionalCase.setCreateUser("Gyq");
caseReviewFunctionalCase.setCreateTime(System.currentTimeMillis());
caseReviewFunctionalCase.setUpdateTime(System.currentTimeMillis());
caseReviewFunctionalCaseMapper.insert(caseReviewFunctionalCase);
delCaseReview(id);
delCaseReview("caseReviewIdX"); delCaseReview("caseReviewIdX");
} }
@ -702,7 +740,7 @@ public class CaseReviewControllerTests extends BaseTest {
} }
private void delCaseReview(String reviewId) throws Exception { private void delCaseReview(String reviewId) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(DELETE_CASE_REVIEW+reviewId+"/"+projectId).header(SessionConstants.HEADER_TOKEN, sessionId) mockMvc.perform(MockMvcRequestBuilders.get(DELETE_CASE_REVIEW+projectId+"/"+reviewId).header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
.header(SessionConstants.CURRENT_PROJECT, projectId) .header(SessionConstants.CURRENT_PROJECT, projectId)
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))