fix: 取消关联项目同取消关联的接口用例

This commit is contained in:
chenjianxing 2021-01-04 18:01:56 +08:00
parent 1fede9b66b
commit 45d0a6515e
7 changed files with 71 additions and 15 deletions

View File

@ -15,4 +15,6 @@ public interface ExtTestPlanApiCaseMapper {
List<String> getExecResultByPlanId(String planId);
List<String> getIdsByPlanId(String planId);
List<String> getNotRelevanceCaseIds(@Param("planId")String planId, @Param("relevanceProjectIds")List<String> relevanceProjectIds);
}

View File

@ -90,17 +90,31 @@
</foreach>
</if>
</select>
<select id="getExecResultByPlanId" resultType="java.lang.String">
select status
from
test_plan_api_case
where test_plan_id = #{planId}
</select>
<select id="getExecResultByPlanId" resultType="java.lang.String">
select status
from
test_plan_api_case
where test_plan_id = #{planId}
</select>
<select id="getIdsByPlanId" resultType="java.lang.String">
select id from
from test_plan_api_case
where id = #{planId}
</select>
<select id="getIdsByPlanId" resultType="java.lang.String">
select id
from test_plan_api_case
where id = #{planId}
</select>
<select id="getNotRelevanceCaseIds" resultType="java.lang.String">
select t.id
from test_plan_api_case t
inner join api_test_case c
on c.id = t.api_case_id
<if test="relevanceProjectIds != null and relevanceProjectIds.size() > 0">
and c.project_id not in
<foreach collection="relevanceProjectIds" item="projectId" separator="," open="(" close=")">
#{projectId}
</foreach>
</if>
where t.test_plan_id = #{planId}
</select>
</mapper>

View File

@ -21,4 +21,6 @@ public interface ExtTestPlanScenarioCaseMapper {
List<String> getExecResultByPlanId(String planId);
List<String> getIdsByPlanId(String planId);
List<String> getNotRelevanceCaseIds(String planId, List<String> relevanceProjectIds);
}

View File

@ -92,4 +92,18 @@
where test_plan_id = #{planId}
</select>
<select id="getNotRelevanceCaseIds" resultType="java.lang.String">
select t.id
from test_plan_api_scenario t
inner join api_scenario c
on c.id = t.api_scenario_id
<if test="relevanceProjectIds != null and relevanceProjectIds.size() > 0">
and c.project_id not in
<foreach collection="relevanceProjectIds" item="projectId" separator="," open="(" close=")">
#{projectId}
</foreach>
</if>
where t.test_plan_id = #{planId}
</select>
</mapper>

View File

@ -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<String> relevanceProjectIds) {
TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest();
request.setPlanId(planId);
request.setIds(extTestPlanApiCaseMapper.getNotRelevanceCaseIds(planId, relevanceProjectIds));
deleteApiCaseBath(request);
}
}

View File

@ -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<String> relevanceProjectIds) {
TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest();
request.setIds(extTestPlanScenarioCaseMapper.getNotRelevanceCaseIds(planId, relevanceProjectIds));
request.setPlanId(planId);
deleteApiCaseBath(request);
}
}

View File

@ -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<String> 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);
}
}