From ea6514c36500d1e4e806cbf56761da269a901756 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Mon, 25 Nov 2024 11:31:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83=E7=9A=84=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1049022 --user=宋昌昌 【任务中心】-系统任务保留时间不生效,超出保留时间的任务没有被清理 https://www.tapd.cn/55049933/s/1616055 --- .../api/service/CleanupTaskResultServiceImpl.java | 3 +-- .../api/service/CleanupTaskServiceImpl.java | 10 +++++++--- .../io/metersphere/system/job/CleanUpReportJob.java | 12 +++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) 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());