feat: 删除用例时删除关联的缺陷

This commit is contained in:
shiziyuan9527 2020-08-20 16:03:02 +08:00
parent 1038f50c3f
commit 0602044d6a
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package io.metersphere.track.service;
import io.metersphere.base.domain.TestCaseIssues;
import io.metersphere.base.domain.TestCaseIssuesExample;
import io.metersphere.base.mapper.IssuesMapper;
import io.metersphere.base.mapper.TestCaseIssuesMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
public class TestCaseIssueService {
@Resource
private TestCaseIssuesMapper testCaseIssuesMapper;
@Resource
private IssuesMapper issuesMapper;
public void delTestCaseIssues(String testCaseId) {
TestCaseIssuesExample example = new TestCaseIssuesExample();
example.createCriteria().andTestCaseIdEqualTo(testCaseId);
List<TestCaseIssues> testCaseIssues = testCaseIssuesMapper.selectByExample(example);
if (!CollectionUtils.isEmpty(testCaseIssues)) {
List<String> list = testCaseIssues.stream().map(TestCaseIssues::getIssuesId).collect(Collectors.toList());
list.forEach(id -> {
issuesMapper.deleteByPrimaryKey(id);
});
}
testCaseIssuesMapper.deleteByExample(example);
}
}

View File

@ -73,6 +73,9 @@ public class TestCaseService {
@Resource
UserRoleMapper userRoleMapper;
@Resource
TestCaseIssueService testCaseIssueService;
public void addTestCase(TestCaseWithBLOBs testCase) {
testCase.setName(testCase.getName());
checkTestCaseExist(testCase);
@ -149,6 +152,7 @@ public class TestCaseService {
TestPlanTestCaseExample example = new TestPlanTestCaseExample();
example.createCriteria().andCaseIdEqualTo(testCaseId);
testPlanTestCaseMapper.deleteByExample(example);
testCaseIssueService.delTestCaseIssues(testCaseId);
return testCaseMapper.deleteByPrimaryKey(testCaseId);
}