refactor(测试用例): 评审删除后刷新评审用例的状态

This commit is contained in:
song-cc-rock 2024-08-21 17:22:53 +08:00 committed by Craftsman
parent 8992c63585
commit 36e7c48b1c
2 changed files with 18 additions and 0 deletions

View File

@ -120,6 +120,14 @@ public class CaseReviewCaseProvider implements BaseCaseProvider {
} }
} }
@Async
public void refreshReviewCaseStatus(List<CaseReviewFunctionalCase> reviewCases) {
if (CollectionUtils.isNotEmpty(reviewCases)) {
List<String> caseIds = reviewCases.stream().map(CaseReviewFunctionalCase::getCaseId).collect(Collectors.toList());
updateCaseStatus(caseIds);
}
}
private void updateCaseStatus(List<String> caseIdList) { private void updateCaseStatus(List<String> caseIdList) {
CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andCaseIdIn(caseIdList); caseReviewFunctionalCaseExample.createCriteria().andCaseIdIn(caseIdList);

View File

@ -2,11 +2,14 @@ package io.metersphere.functional.service;
import io.metersphere.functional.domain.*; import io.metersphere.functional.domain.*;
import io.metersphere.functional.mapper.*; import io.metersphere.functional.mapper.*;
import io.metersphere.functional.provider.CaseReviewCaseProvider;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author guoyuqi * @author guoyuqi
@ -27,12 +30,15 @@ public class DeleteCaseReviewService {
private CaseReviewFollowerMapper caseReviewFollowerMapper; private CaseReviewFollowerMapper caseReviewFollowerMapper;
@Resource @Resource
private CaseReviewHistoryMapper caseReviewHistoryMapper; private CaseReviewHistoryMapper caseReviewHistoryMapper;
@Resource
private CaseReviewCaseProvider caseReviewCaseProvider;
public void deleteCaseReviewResource(List<String> ids, String projectId) { public void deleteCaseReviewResource(List<String> ids, String projectId) {
//TODO 删除各种关联关系 1.关联用例(功能/接口/场景/ui/性能) 2.评审和评审人 3. 归档的用例 4. 关注人 5.评审历史 6. 操作记录 //TODO 删除各种关联关系 1.关联用例(功能/接口/场景/ui/性能) 2.评审和评审人 3. 归档的用例 4. 关注人 5.评审历史 6. 操作记录
//1.刪除评审与功能用例关联关系 //1.刪除评审与功能用例关联关系
CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andReviewIdIn(ids); caseReviewFunctionalCaseExample.createCriteria().andReviewIdIn(ids);
List<CaseReviewFunctionalCase> reviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample);
caseReviewFunctionalCaseMapper.deleteByExample(caseReviewFunctionalCaseExample); caseReviewFunctionalCaseMapper.deleteByExample(caseReviewFunctionalCaseExample);
//2. 删除评审和评审人 //2. 删除评审和评审人
CaseReviewUserExample caseReviewUserExample = new CaseReviewUserExample(); CaseReviewUserExample caseReviewUserExample = new CaseReviewUserExample();
@ -56,5 +62,9 @@ public class DeleteCaseReviewService {
CaseReviewExample caseReviewExample = new CaseReviewExample(); CaseReviewExample caseReviewExample = new CaseReviewExample();
caseReviewExample.createCriteria().andIdIn(ids).andProjectIdEqualTo(projectId); caseReviewExample.createCriteria().andIdIn(ids).andProjectIdEqualTo(projectId);
caseReviewMapper.deleteByExample(caseReviewExample); caseReviewMapper.deleteByExample(caseReviewExample);
// 7. 批量刷新评审中其他用例的评审状态
Map<String, List<CaseReviewFunctionalCase>> reviewFunctionalCaseMap = reviewFunctionalCases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getReviewId));
reviewFunctionalCaseMap.forEach((reviewId, reviewFunctionalCaseList) -> caseReviewCaseProvider.refreshReviewCaseStatus(reviewFunctionalCaseList));
} }
} }