fix(测试计划): 计划删除未同步删除用例关联的缺陷

--bug=1041252 --user=宋昌昌 【测试计划】删除计划-功能用例详情-缺陷-测试计划关联缺陷未同步删除 https://www.tapd.cn/55049933/s/1521488
This commit is contained in:
song-cc-rock 2024-05-27 16:14:03 +08:00 committed by 刘瑞斌
parent aee7e10a90
commit d99a79ac0c
2 changed files with 1 additions and 24 deletions

View File

@ -1,6 +1,5 @@
package io.metersphere.plan.service; package io.metersphere.plan.service;
import io.metersphere.bug.domain.BugRelationCase;
import io.metersphere.bug.domain.BugRelationCaseExample; import io.metersphere.bug.domain.BugRelationCaseExample;
import io.metersphere.bug.mapper.BugRelationCaseMapper; import io.metersphere.bug.mapper.BugRelationCaseMapper;
import io.metersphere.bug.service.BugCommonService; import io.metersphere.bug.service.BugCommonService;
@ -13,7 +12,6 @@ import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.mapper.BaseUserMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
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;
@ -48,24 +46,7 @@ public class TestPlanBugService extends TestPlanResourceService {
public void deleteBatchByTestPlanId(List<String> testPlanIdList) { public void deleteBatchByTestPlanId(List<String> testPlanIdList) {
BugRelationCaseExample example = new BugRelationCaseExample(); BugRelationCaseExample example = new BugRelationCaseExample();
example.createCriteria().andTestPlanIdIn(testPlanIdList); example.createCriteria().andTestPlanIdIn(testPlanIdList);
List<BugRelationCase> bugRelationCases = bugRelationCaseMapper.selectByExample(example); bugRelationCaseMapper.deleteByExample(example);
List<String> relateIdsByDirect = bugRelationCases.stream().filter(relatedCase -> StringUtils.isNotEmpty(relatedCase.getCaseId())).map(BugRelationCase::getId).toList();
List<String> relateIdsByPlan = bugRelationCases.stream().filter(relatedCase -> StringUtils.isEmpty(relatedCase.getCaseId())).map(BugRelationCase::getId).toList();
if (CollectionUtils.isNotEmpty(relateIdsByDirect)) {
// 缺陷-用例, 存在直接关联
BugRelationCaseExample updateExample = new BugRelationCaseExample();
updateExample.createCriteria().andIdIn(relateIdsByDirect);
BugRelationCase record = new BugRelationCase();
record.setTestPlanId(StringUtils.EMPTY);
record.setTestPlanCaseId(StringUtils.EMPTY);
bugRelationCaseMapper.updateByExampleSelective(record, updateExample);
}
if (CollectionUtils.isNotEmpty(relateIdsByPlan)) {
// 缺陷-用例, 计划关联
BugRelationCaseExample deleteExample = new BugRelationCaseExample();
deleteExample.createCriteria().andIdIn(relateIdsByPlan);
bugRelationCaseMapper.deleteByExample(deleteExample);
}
} }
@Override @Override

View File

@ -114,10 +114,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
TestPlanFunctionalCaseExample testPlanFunctionalCaseExample = new TestPlanFunctionalCaseExample(); TestPlanFunctionalCaseExample testPlanFunctionalCaseExample = new TestPlanFunctionalCaseExample();
testPlanFunctionalCaseExample.createCriteria().andTestPlanIdIn(testPlanIdList); testPlanFunctionalCaseExample.createCriteria().andTestPlanIdIn(testPlanIdList);
testPlanFunctionalCaseMapper.deleteByExample(testPlanFunctionalCaseExample); testPlanFunctionalCaseMapper.deleteByExample(testPlanFunctionalCaseExample);
// 取消关联用例需同步删除计划-用例缺陷关系表
BugRelationCaseExample example = new BugRelationCaseExample();
example.createCriteria().andTestPlanIdIn(testPlanIdList);
bugRelationCaseMapper.deleteByExample(example);
// todo:song.tianyang 删除执行历史 // todo:song.tianyang 删除执行历史
testPlanFunctionalCaseMapper.deleteByExample(testPlanFunctionalCaseExample); testPlanFunctionalCaseMapper.deleteByExample(testPlanFunctionalCaseExample);