diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java new file mode 100644 index 0000000000..de4505799f --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java @@ -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 = testCaseIssuesMapper.selectByExample(example); + if (!CollectionUtils.isEmpty(testCaseIssues)) { + List list = testCaseIssues.stream().map(TestCaseIssues::getIssuesId).collect(Collectors.toList()); + list.forEach(id -> { + issuesMapper.deleteByPrimaryKey(id); + }); + } + testCaseIssuesMapper.deleteByExample(example); + } +} diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index ab9ef07a63..802ebe2955 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -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); }