diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java index 29c6b60bbe..d02469e727 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java @@ -51,12 +51,11 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { } List cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList(); List cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds); - LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条"); if (CollectionUtils.isNotEmpty(cleanIds)) { // 清理任务-报告关系表 SubListUtils.dealForSubList(cleanIds, 100, ids -> { ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); - example.createCriteria().andTaskResourceIdIn(cleanIds); + example.createCriteria().andTaskResourceIdIn(ids); apiReportRelateTaskMapper.deleteByExample(example); }); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskServiceImpl.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskServiceImpl.java index d2980b987f..0b2c3859d1 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskServiceImpl.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskServiceImpl.java @@ -15,6 +15,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,9 +42,12 @@ public class CleanupTaskServiceImpl implements BaseCleanUpReport { String expr = map.get(ProjectApplicationType.TASK.TASK_RECORD.name()); long timeMills = getCleanDate(expr); List cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); - ExecTaskItemExample itemExample = new ExecTaskItemExample(); - itemExample.createCriteria().andTaskIdIn(cleanTaskIds); - List execTaskItems = execTaskItemMapper.selectByExample(itemExample); + List execTaskItems = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(cleanTaskIds)) { + ExecTaskItemExample itemExample = new ExecTaskItemExample(); + itemExample.createCriteria().andTaskIdIn(cleanTaskIds); + execTaskItems = execTaskItemMapper.selectByExample(itemExample); + } List cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList(); if (CollectionUtils.isNotEmpty(cleanTaskIds)) { ExecTaskExample example = new ExecTaskExample(); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java index 3ad3f5cb21..c5e1b4ba25 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java @@ -40,7 +40,7 @@ public class CleanUpReportJob { /** * 清理报告定时任务(所有项目共用一个) */ - @QuartzScheduled(cron = "0 0 1 * * ?") + @QuartzScheduled(cron = "0 26 11 * * ?") public void cleanReport() { long count = getProjectCount(); @@ -82,6 +82,16 @@ public class CleanUpReportJob { map.put(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name(), "3M"); } + // task record + applicationExample.clear(); + applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.TASK.TASK_RECORD.name()); + List taskRecord = projectApplicationMapper.selectByExample(applicationExample); + if (CollectionUtils.isNotEmpty(taskRecord)) { + map.put(ProjectApplicationType.TASK.TASK_RECORD.name(), taskRecord.getFirst().getTypeValue()); + } else { + map.put(ProjectApplicationType.TASK.TASK_RECORD.name(), "3M"); + } + Map beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class); beansOfType.forEach((k, v) -> { v.cleanReport(map, project.getId());