diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java index fa3099b94f..8990ca9b8c 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java @@ -15,4 +15,6 @@ public interface ExtTestPlanApiCaseMapper { List getExecResultByPlanId(String planId); List getIdsByPlanId(String planId); + + List getNotRelevanceCaseIds(@Param("planId")String planId, @Param("relevanceProjectIds")List relevanceProjectIds); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml index acbbbb07c3..29c947bb9c 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml @@ -90,17 +90,31 @@ - + - + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java index c60c731415..483dc83f09 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java @@ -21,4 +21,6 @@ public interface ExtTestPlanScenarioCaseMapper { List getExecResultByPlanId(String planId); List getIdsByPlanId(String planId); + + List getNotRelevanceCaseIds(String planId, List relevanceProjectIds); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml index 11767c5e7f..d3add4c1a2 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml @@ -92,4 +92,18 @@ where test_plan_id = #{planId} + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java index 95eec7639d..fd83651fcf 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanApiCaseService.java @@ -77,6 +77,9 @@ public class TestPlanApiCaseService { } public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) { + if (CollectionUtils.isEmpty(request.getIds())) { + return; + } apiDefinitionExecResultService.deleteByResourceIds(request.getIds()); TestPlanApiCaseExample example = new TestPlanApiCaseExample(); example.createCriteria() @@ -97,4 +100,11 @@ public class TestPlanApiCaseService { apiCase.setStatus(status); testPlanApiCaseMapper.updateByPrimaryKeySelective(apiCase); } + + public void deleteByRelevanceProjectIds(String planId, List relevanceProjectIds) { + TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest(); + request.setPlanId(planId); + request.setIds(extTestPlanApiCaseMapper.getNotRelevanceCaseIds(planId, relevanceProjectIds)); + deleteApiCaseBath(request); + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java index cee39a7677..683fe4cee1 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -73,6 +73,9 @@ public class TestPlanScenarioCaseService { } public void deleteApiCaseBath(TestPlanApiCaseBatchRequest request) { + if (CollectionUtils.isEmpty(request.getIds())) { + return; + } TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); example.createCriteria() .andIdIn(request.getIds()); @@ -110,4 +113,11 @@ public class TestPlanScenarioCaseService { request.setIds(ids); deleteApiCaseBath(request); } + + public void deleteByRelevanceProjectIds(String planId, List relevanceProjectIds) { + TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest(); + request.setIds(extTestPlanScenarioCaseMapper.getNotRelevanceCaseIds(planId, relevanceProjectIds)); + request.setPlanId(planId); + deleteApiCaseBath(request); + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 72a403bc9b..d3d1959f1b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -10,7 +10,6 @@ import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.TestPlanApiCaseDTO; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; -import io.metersphere.base.mapper.ext.ExtProjectMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestPlanMapper; import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper; @@ -27,7 +26,6 @@ import io.metersphere.notice.service.NoticeSendService; import io.metersphere.service.SystemParameterService; import io.metersphere.track.Factory.ReportComponentFactory; import io.metersphere.track.domain.ReportComponent; - import io.metersphere.track.dto.TestCaseReportMetricDTO; import io.metersphere.track.dto.TestPlanCaseDTO; import io.metersphere.track.dto.TestPlanDTO; @@ -69,8 +67,6 @@ public class TestPlanService { @Resource TestPlanTestCaseService testPlanTestCaseService; @Resource - ExtProjectMapper extProjectMapper; - @Resource TestCaseReportMapper testCaseReportMapper; @Resource TestPlanProjectMapper testPlanProjectMapper; @@ -229,6 +225,14 @@ public class TestPlanService { criteria.andCaseIdNotIn(caseIds); } testPlanTestCaseMapper.deleteByExample(testPlanTestCaseExample); + + List relevanceProjectIds = new ArrayList<>(); + relevanceProjectIds.add(testPlan.getProjectId()); + if (!CollectionUtils.isEmpty(testPlan.getProjectIds())) { + relevanceProjectIds.addAll(testPlan.getProjectIds()); + } + testPlanApiCaseService.deleteByRelevanceProjectIds(testPlan.getId(), relevanceProjectIds); + testPlanScenarioCaseService.deleteByRelevanceProjectIds(testPlan.getId(), relevanceProjectIds); } }