fix(测试计划): 子计划删除报告明细清理问题

--bug=1042776 --user=宋昌昌 【测试计划】计划组-删除子计划-集合报告-报告明细-子计划被删除了 https://www.tapd.cn/55049933/s/1552190
This commit is contained in:
song-cc-rock 2024-07-22 15:26:50 +08:00 committed by 刘瑞斌
parent 2599daeee2
commit 9df8359874
6 changed files with 35 additions and 16 deletions

View File

@ -173,7 +173,7 @@ public class TestPlanController {
@Operation(summary = "测试计划-批量复制测试计划")
@RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ADD)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public TestPlanOperationResponse TestPlanOperationResponse(@Validated @RequestBody TestPlanBatchRequest request) {
public TestPlanOperationResponse batchCopy(@Validated @RequestBody TestPlanBatchRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN));
testPlanService.filterArchivedIds(request);
return new TestPlanOperationResponse(

View File

@ -27,7 +27,7 @@ public class TestPlanReportDetailResponse {
@Schema(description = "报告内容")
private String summary;
@Schema(description = "用例总数")
private Integer caseTotal = 0;
private Integer caseTotal;
/**
* 报告分析

View File

@ -65,4 +65,6 @@ public interface ExtTestPlanReportMapper {
void batchUpdateExecuteTimeAndStatus(@Param("startTime") long startTime, @Param("ids") List<String> ids);
List<ReportDTO> getReportsByIds(@Param("ids") List<String> ids);
void deleteGroupReport(@Param("id") String id);
}

View File

@ -142,8 +142,7 @@
tpr.deleted
from test_plan_report tpr
INNER JOIN test_plan_report_summary tprs on tpr.id = tprs.test_plan_report_id
LEFT JOIN test_plan_report_summary tprs on tpr.id = tprs.test_plan_report_id
<include refid="queryWhereConditionByParentId"/>
</select>
<select id="getReports" resultType="io.metersphere.api.dto.report.ReportDTO">
@ -260,6 +259,10 @@
</foreach>
</select>
<delete id="deleteGroupReport" parameterType="java.lang.String">
delete from test_plan_report where id = #{id} or parent_id = #{id}
</delete>
<update id="batchUpdateExecuteTimeAndStatus" parameterType="java.lang.String">
update test_plan_report
set start_time = #{startTime}, exec_status = 'RUNNING'

View File

@ -184,19 +184,33 @@ public class TestPlanReportService {
}
/**
* 删除测试计划报告包括summary
* 删除测试计划报告包括汇总, 明细)
*/
public void deleteByTestPlanIds(List<String> testPlanIds) {
if (CollectionUtils.isNotEmpty(testPlanIds)) {
List<String> reportIdList = extTestPlanReportMapper.selectReportIdTestPlanIds(testPlanIds);
SubListUtils.dealForSubList(reportIdList, SubListUtils.DEFAULT_BATCH_SIZE, subList -> {
TestPlanReportExample example = new TestPlanReportExample();
example.createCriteria().andIdIn(subList);
testPlanReportMapper.deleteByExample(example);
this.deleteTestPlanReportBlobs(subList);
});
TestPlanReportExample reportExample = new TestPlanReportExample();
reportExample.createCriteria().andTestPlanIdIn(testPlanIds);
List<TestPlanReport> testPlanReports = testPlanReportMapper.selectByExample(reportExample);
if (CollectionUtils.isNotEmpty(testPlanReports)) {
Map<String, TestPlanReport> reportMap = testPlanReports.stream().collect(Collectors.toMap(TestPlanReport::getId, r -> r));
List<String> reportIdList = testPlanReports.stream().map(TestPlanReport::getId).toList();
reportIdList.forEach(reportId -> {
/**
* 独立计划直接删除; 子计划的报告删除时, 保留报告记录
*/
TestPlanReport report = reportMap.get(reportId);
if (StringUtils.isNotBlank(report.getParentId()) && !report.getIntegrated() && !report.getDeleted()) {
TestPlanReport record = new TestPlanReport();
record.setId(reportId);
record.setDeleted(true);
testPlanReportMapper.updateByPrimaryKeySelective(record);
} else {
extTestPlanReportMapper.deleteGroupReport(reportId);
}
});
// 清除汇总, 明细数据
this.deleteTestPlanReportBlobs(reportIdList);
}
}
}

View File

@ -105,11 +105,12 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private TestPlanReportCaseService testPlanReportCaseService;
@Resource
private TestPlanReportService testPlanReportService;
@Resource
private TestPlanReportMapper testPlanReportMapper;
@Resource
private ExtTestPlanReportMapper extTestPlanReportMapper;
public void autoUpdateFunctionalCase(String testPlanReportId) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportId);
@ -276,7 +277,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
/*
* 计划组删除逻辑{第一版需求: 删除组, 组下的子计划Group置为None}:
* 1. 查询计划组下的全部子计划并删除(级联删除这些子计划的关联资源)
* 2. 删除所有计划组
*/
TestPlanExample testPlanExample = new TestPlanExample();
testPlanExample.createCriteria().andGroupIdIn(deleteGroupIds);