fix(测试跟踪): 测试计划删除报告时级联删除生成的自动化用例报告

--bug=1025762 --user=宋天阳
【测试跟踪】测试计划-查看历史报告的接口和场景用例内容为空
https://www.tapd.cn/55049933/s/1367408
This commit is contained in:
song-tianyang 2023-04-26 20:05:17 +08:00 committed by fit2-zhao
parent c65163ee09
commit f20411ed9c
4 changed files with 151 additions and 5 deletions

View File

@ -16,4 +16,23 @@ public interface ExtTestPlanReportContentMapper {
boolean hasRunningReportByPlanIds(@Param("planIds") List<String> planIds);
boolean isApiBasicCountIsNull(String testPlanReportId);
List<String> selectScenarioReportByTestPlanReportIds(@Param("testPlanReportIds") List<String> testPlanReportIdList);
List<String> selectUiReportByTestPlanReportIds(@Param("testPlanReportIds") List<String> testPlanReportIdList);
int deleteApiReportByTestPlanReportList(@Param("testPlanReportIds") List<String> testPlanReportIdList);
void deleteScenarioReportByIds(@Param("testPlanReportIds") List<String> scenarioReportIds);
void deleteScenarioReportResultByIds(@Param("testPlanReportIds") List<String> scenarioReportIds);
void deleteScenarioReportStructureByIds(@Param("testPlanReportIds") List<String> scenarioReportIds);
void deleteUiReportByIds(@Param("testPlanReportIds") List<String> scenarioReportIds);
void deleteUiReportResultByIds(@Param("testPlanReportIds") List<String> scenarioReportIds);
void deleteUiReportStructureByIds(@Param("testPlanReportIds") List<String> scenarioReportIds);
}

View File

@ -24,9 +24,12 @@
where test_plan_report_id = #{reportId}
</select>
<select id="hasRunningReport" resultType="java.lang.Boolean">
select count(1) > 0 from test_plan_report
where test_plan_id = #{planId} and status = 'RUNNING'
order by create_time desc limit 1;
select count(1) > 0
from test_plan_report
where test_plan_id = #{planId}
and status = 'RUNNING'
order by create_time desc
limit 1;
</select>
<select id="hasRunningReportByPlanIds" resultType="java.lang.Boolean">
select count(1) > 0 from test_plan_report
@ -40,7 +43,68 @@
<select id="isApiBasicCountIsNull" resultType="java.lang.Boolean">
SELECT (api_base_count IS NULL OR api_base_count = '') AS apiCountIsNull
FROM test_plan_report_content WHERE test_plan_report_id = #{0} limit 1
FROM test_plan_report_content
WHERE test_plan_report_id = #{0}
limit 1
</select>
<select id="selectScenarioReportByTestPlanReportIds" resultType="java.lang.String">
SELECT id FROM api_scenario_report WHERE relevance_test_plan_report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</select>
<select id="selectUiReportByTestPlanReportIds" resultType="java.lang.String">
SELECT id FROM ui_scenario_report WHERE relevance_test_plan_report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</select>
<delete id="deleteApiReportByTestPlanReportList" parameterType="java.lang.String">
DELETE FROM api_definition_exec_result WHERE
(
relevance_test_plan_report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
)
</delete>
<delete id="deleteScenarioReportByIds" parameterType="java.lang.String">
DELETE FROM api_scenario_report WHERE id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteScenarioReportResultByIds" parameterType="java.lang.String">
DELETE FROM api_scenario_report_result WHERE report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteScenarioReportStructureByIds" parameterType="java.lang.String">
DELETE FROM api_scenario_report_structure WHERE report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteUiReportByIds" parameterType="java.lang.String">
DELETE FROM ui_scenario_report WHERE id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteUiReportResultByIds" parameterType="java.lang.String">
DELETE FROM ui_scenario_report_result WHERE report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
<delete id="deleteUiReportStructureByIds" parameterType="java.lang.String">
DELETE FROM ui_scenario_report_structure WHERE report_id IN
<foreach collection="testPlanReportIds" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -33,6 +33,7 @@ import io.metersphere.service.BaseProjectService;
import io.metersphere.service.BaseUserService;
import io.metersphere.service.IssuesService;
import io.metersphere.service.ServiceUtils;
import io.metersphere.utils.BatchProcessingUtil;
import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.xpack.track.dto.IssuesDao;
@ -877,7 +878,39 @@ public class TestPlanReportService {
TestPlanReportContentExample contentExample = new TestPlanReportContentExample();
contentExample.createCriteria().andTestPlanReportIdIn(testPlanReportIdList);
testPlanReportContentMapper.deleteByExample(contentExample);
// todo 删除场景接口的报告
BatchProcessingUtil.batchDeleteApiReport(testPlanReportIdList, this::deleteApiCaseReportByTestPlanExecute, this::deleteScenarioReportByTestPlanExecute, this::deleteUiReportByTestPlanExecute);
}
}
//删除执行测试计划产生的接口用例报告
private void deleteApiCaseReportByTestPlanExecute(List<String> testPlanReportIdList) {
if (CollectionUtils.isNotEmpty(testPlanReportIdList)) {
extTestPlanReportContentMapper.deleteApiReportByTestPlanReportList(testPlanReportIdList);
}
}
//删除执行测试计划产生的场景报告
private void deleteScenarioReportByTestPlanExecute(List<String> testPlanReportIdList) {
if (CollectionUtils.isNotEmpty(testPlanReportIdList)) {
List<String> scenarioReportIds = extTestPlanReportContentMapper.selectScenarioReportByTestPlanReportIds(testPlanReportIdList);
if (CollectionUtils.isNotEmpty(scenarioReportIds)) {
extTestPlanReportContentMapper.deleteScenarioReportByIds(scenarioReportIds);
extTestPlanReportContentMapper.deleteScenarioReportResultByIds(scenarioReportIds);
extTestPlanReportContentMapper.deleteScenarioReportStructureByIds(scenarioReportIds);
}
}
}
//删除执行测试计划产生的UI报告
private void deleteUiReportByTestPlanExecute(List<String> testPlanReportIdList) {
if (CollectionUtils.isNotEmpty(testPlanReportIdList)) {
List<String> scenarioReportIds = extTestPlanReportContentMapper.selectUiReportByTestPlanReportIds(testPlanReportIdList);
if (CollectionUtils.isNotEmpty(scenarioReportIds)) {
extTestPlanReportContentMapper.deleteUiReportByIds(scenarioReportIds);
extTestPlanReportContentMapper.deleteUiReportResultByIds(scenarioReportIds);
extTestPlanReportContentMapper.deleteUiReportStructureByIds(scenarioReportIds);
}
}
}

View File

@ -6,6 +6,7 @@ import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
/**
@ -15,6 +16,35 @@ public class BatchProcessingUtil {
private static final int BATCH_PROCESS_QUANTITY = 100;
public static void batchDeleteApiReport(List<String> testPlanReportIdList, Consumer<List<String>> deleteApiCaseReportFunc, Consumer<List<String>> deleteScenarioReportFunc, Consumer<List<String>> deleteUiReportFunc) {
if (CollectionUtils.isNotEmpty(testPlanReportIdList)) {
int unDeleteReportIdCount = testPlanReportIdList.size();
while (BATCH_PROCESS_QUANTITY < testPlanReportIdList.size()) {
List<String> deleteReportIds = testPlanReportIdList.subList(0, BATCH_PROCESS_QUANTITY);
deleteApiCaseReportFunc.accept(deleteReportIds);
deleteScenarioReportFunc.accept(deleteReportIds);
deleteUiReportFunc.accept(deleteReportIds);
testPlanReportIdList.removeAll(deleteReportIds);
//未删除的报告数量如果未减少跳出防止死循环
if (testPlanReportIdList.size() >= unDeleteReportIdCount) {
break;
} else {
unDeleteReportIdCount = testPlanReportIdList.size();
}
}
//处理剩余数据
if (CollectionUtils.isNotEmpty(testPlanReportIdList)) {
deleteApiCaseReportFunc.accept(testPlanReportIdList);
deleteScenarioReportFunc.accept(testPlanReportIdList);
deleteUiReportFunc.accept(testPlanReportIdList);
}
}
}
public static List<TestCaseTest> selectTestCaseTestByPrimaryKey(List<String> primaryKeyList, Function<TestCaseTestExample, List<TestCaseTest>> func) {
List<TestCaseTest> returnList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(primaryKeyList)) {