fix(测试计划): 修复查询关联用例未去掉已删除的数据的问题

This commit is contained in:
guoyuqi 2024-06-21 14:55:35 +08:00 committed by Craftsman
parent 890f04c040
commit ccb6b42143
7 changed files with 53 additions and 17 deletions

View File

@ -73,4 +73,7 @@ public interface ExtTestPlanApiCaseMapper {
List<ApiTestCase> selectApiCaseByDefinitionIds(@Param("ids") List<String> ids, @Param("isRepeat") boolean isRepeat, @Param("testPlanId") String testPlanId);
List<TestPlanApiCase> getSelectIdAndCollectionId(@Param("request") TestPlanApiCaseBatchRequest request);
List<TestPlanApiCase> getPlanApiCaseNotDeletedByCollectionIds(@Param("collectionIds") List<String> collectionIds);
}

View File

@ -440,6 +440,17 @@
AND atc.deleted = false
</select>
<select id="getPlanApiCaseNotDeletedByCollectionIds" resultType="io.metersphere.plan.domain.TestPlanApiCase">
SELECT t.*
FROM test_plan_api_case t
INNER JOIN api_test_case atc ON t.api_case_id = atc.id
WHERE t.test_plan_collection_id IN
<foreach collection="collectionIds" item="collectionId" separator="," open="(" close=")">
#{collectionId}
</foreach>
AND atc.deleted = false
</select>
<sql id="queryApiCaseWhereCondition">
<if test="request.protocols != null and request.protocols.size() > 0">

View File

@ -67,4 +67,6 @@ public interface ExtTestPlanApiScenarioMapper {
List<TestPlanApiScenario> getSelectIdAndCollectionId(@Param("request") TestPlanApiScenarioBatchRunRequest request);
List<String> getIdsByReportIdAndCollectionId(@Param("testPlanReportId") String testPlanReportId, @Param("collectionId") String collectionId);
List<TestPlanApiScenario> getPlanScenarioCaseNotDeletedByCollectionIds(@Param("collectionIds") List<String> collectionIds);
}

View File

@ -474,6 +474,17 @@
</if>
</sql>
<select id="getPlanScenarioCaseNotDeletedByCollectionIds" resultType="io.metersphere.plan.domain.TestPlanApiScenario">
SELECT t.*
FROM test_plan_api_scenario t
INNER JOIN api_scenario a ON t.api_scenario_id = a.id
WHERE t.test_plan_collection_id IN
<foreach collection="collectionIds" item="collectionId" separator="," open="(" close=")">
#{collectionId}
</foreach>
AND a.deleted = false
</select>
<update id="batchUpdateExecutor">
update test_plan_api_scenario

View File

@ -64,4 +64,7 @@ public interface ExtTestPlanFunctionalCaseMapper {
Long getMaxPosByCollectionId(String collectionId);
List<ModuleCountDTO> collectionCountByRequest(@Param("request") TestPlanCaseModuleRequest request);
List<TestPlanFunctionalCase> getPlanCaseNotDeletedByCollectionIds(@Param("collectionIds") List<String> collectionIds);
}

View File

@ -508,6 +508,18 @@
</if>
</where>
</select>
<select id="getPlanCaseNotDeletedByCollectionIds" resultType="io.metersphere.plan.domain.TestPlanFunctionalCase">
SELECT t.*
from test_plan_functional_case t
INNER JOIN functional_case f ON t.functional_case_id = f.id
WHERE t.test_plan_collection_id IN
<foreach collection="collectionIds" item="collectionId" separator="," open="(" close=")">
#{collectionId}
</foreach>
AND f.deleted = false
</select>
<select id="selectCaseExecResultCount" resultType="io.metersphere.plan.dto.TestPlanCaseRunResultCount">
select test_plan_functional_case.last_exec_result as result, count(test_plan_functional_case.id) as resultCount
from test_plan_functional_case

View File

@ -38,13 +38,13 @@ public class TestPlanCollectionMinderService {
private ExtTestPlanCollectionMapper extTestPlanCollectionMapper;
@Resource
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
private ExtTestPlanFunctionalCaseMapper extTestPlanFunctionalCaseMapper;
@Resource
private TestPlanApiCaseMapper testPlanApiCaseMapper;
private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper;
@Resource
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
private ExtTestPlanApiScenarioMapper exttestPlanApiScenarioMapper;
@Resource
private TestPlanService testPlanService;
@ -119,9 +119,7 @@ public class TestPlanCollectionMinderService {
return new HashMap<>();
}
List<String> scenarioCollectIds = testPlanCollectionConfigDTOS.stream().map(TestPlanCollectionConfigDTO::getId).toList();
TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample();
testPlanApiScenarioExample.createCriteria().andTestPlanCollectionIdIn(scenarioCollectIds);
List<TestPlanApiScenario> testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(testPlanApiScenarioExample);
List<TestPlanApiScenario> testPlanApiScenarios = exttestPlanApiScenarioMapper.getPlanScenarioCaseNotDeletedByCollectionIds(scenarioCollectIds);
return testPlanApiScenarios.stream().collect(Collectors.groupingBy(TestPlanApiScenario::getTestPlanCollectionId));
}
@ -131,9 +129,7 @@ public class TestPlanCollectionMinderService {
return new HashMap<>();
}
List<String> apiCollectIds = testPlanCollectionConfigDTOS.stream().map(TestPlanCollectionConfigDTO::getId).toList();
TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample();
testPlanApiCaseExample.createCriteria().andTestPlanCollectionIdIn(apiCollectIds);
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(testPlanApiCaseExample);
List<TestPlanApiCase> testPlanApiCases = extTestPlanApiCaseMapper.getPlanApiCaseNotDeletedByCollectionIds(apiCollectIds);
return testPlanApiCases.stream().collect(Collectors.groupingBy(TestPlanApiCase::getTestPlanCollectionId));
}
@ -144,9 +140,7 @@ public class TestPlanCollectionMinderService {
return new HashMap<>();
}
List<String> functionalCollectIds = testPlanCollectionConfigDTOS.stream().map(TestPlanCollectionConfigDTO::getId).toList();
TestPlanFunctionalCaseExample testPlanFunctionalCaseExample = new TestPlanFunctionalCaseExample();
testPlanFunctionalCaseExample.createCriteria().andTestPlanCollectionIdIn(functionalCollectIds);
List<TestPlanFunctionalCase> testPlanFunctionalCases = testPlanFunctionalCaseMapper.selectByExample(testPlanFunctionalCaseExample);
List<TestPlanFunctionalCase> testPlanFunctionalCases = extTestPlanFunctionalCaseMapper.getPlanCaseNotDeletedByCollectionIds(functionalCollectIds);
return testPlanFunctionalCases.stream().collect(Collectors.groupingBy(TestPlanFunctionalCase::getTestPlanCollectionId));
}
@ -346,7 +340,7 @@ public class TestPlanCollectionMinderService {
@NotNull
private Map<String, List<TestPlanCollection>> getParentMap(TestPlanCollectionMinderEditRequest request) {
List<TestPlanCollectionMinderEditDTO> list = request.getEditList().stream().filter(t -> StringUtils.isNotBlank(t.getId()) && t.getLevel() == 1).toList();
List<TestPlanCollection>parentList = new ArrayList<>();
List<TestPlanCollection> parentList = new ArrayList<>();
for (TestPlanCollectionMinderEditDTO testPlanCollectionMinderEditDTO : list) {
TestPlanCollection testPlanCollection = new TestPlanCollection();
BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO);
@ -371,8 +365,8 @@ public class TestPlanCollectionMinderService {
} else {
testPlanCollection.setParentId(parent.getId());
}
if (testPlanCollectionMinderEditDTO.getText().length()>255) {
testPlanCollectionMinderEditDTO.setText(testPlanCollectionMinderEditDTO.getText().substring(0,249));
if (testPlanCollectionMinderEditDTO.getText().length() > 255) {
testPlanCollectionMinderEditDTO.setText(testPlanCollectionMinderEditDTO.getText().substring(0, 249));
}
testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText());
testPlanCollection.setTestPlanId(request.getPlanId());
@ -396,8 +390,8 @@ public class TestPlanCollectionMinderService {
BeanUtils.copyBean(testPlanCollection, testPlanCollectionMinderEditDTO);
}
testPlanCollection.setParentId(parent.getId());
if (testPlanCollectionMinderEditDTO.getText().length()>255) {
testPlanCollectionMinderEditDTO.setText(testPlanCollectionMinderEditDTO.getText().substring(0,249));
if (testPlanCollectionMinderEditDTO.getText().length() > 255) {
testPlanCollectionMinderEditDTO.setText(testPlanCollectionMinderEditDTO.getText().substring(0, 249));
}
testPlanCollection.setName(testPlanCollectionMinderEditDTO.getText());
testPlanCollection.setId(IDGenerator.nextStr());