fix(任务中心): 任务中心的清理有误

--bug=1049022 --user=宋昌昌 【任务中心】-系统任务保留时间不生效,超出保留时间的任务没有被清理 https://www.tapd.cn/55049933/s/1616055
This commit is contained in:
song-cc-rock 2024-11-25 11:31:01 +08:00 committed by Craftsman
parent cebc82c4e3
commit ea6514c365
3 changed files with 19 additions and 6 deletions

View File

@ -51,12 +51,11 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport {
} }
List<String> cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList(); List<String> cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList();
List<String> cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds); List<String> cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds);
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条");
if (CollectionUtils.isNotEmpty(cleanIds)) { if (CollectionUtils.isNotEmpty(cleanIds)) {
// 清理任务-报告关系表 // 清理任务-报告关系表
SubListUtils.dealForSubList(cleanIds, 100, ids -> { SubListUtils.dealForSubList(cleanIds, 100, ids -> {
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andTaskResourceIdIn(cleanIds); example.createCriteria().andTaskResourceIdIn(ids);
apiReportRelateTaskMapper.deleteByExample(example); apiReportRelateTaskMapper.deleteByExample(example);
}); });
} }

View File

@ -15,6 +15,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -41,9 +42,12 @@ public class CleanupTaskServiceImpl implements BaseCleanUpReport {
String expr = map.get(ProjectApplicationType.TASK.TASK_RECORD.name()); String expr = map.get(ProjectApplicationType.TASK.TASK_RECORD.name());
long timeMills = getCleanDate(expr); long timeMills = getCleanDate(expr);
List<String> cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); List<String> cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId);
ExecTaskItemExample itemExample = new ExecTaskItemExample(); List<ExecTaskItem> execTaskItems = new ArrayList<>();
itemExample.createCriteria().andTaskIdIn(cleanTaskIds); if (CollectionUtils.isNotEmpty(cleanTaskIds)) {
List<ExecTaskItem> execTaskItems = execTaskItemMapper.selectByExample(itemExample); ExecTaskItemExample itemExample = new ExecTaskItemExample();
itemExample.createCriteria().andTaskIdIn(cleanTaskIds);
execTaskItems = execTaskItemMapper.selectByExample(itemExample);
}
List<String> cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList(); List<String> cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList();
if (CollectionUtils.isNotEmpty(cleanTaskIds)) { if (CollectionUtils.isNotEmpty(cleanTaskIds)) {
ExecTaskExample example = new ExecTaskExample(); ExecTaskExample example = new ExecTaskExample();

View File

@ -40,7 +40,7 @@ public class CleanUpReportJob {
/** /**
* 清理报告定时任务所有项目共用一个 * 清理报告定时任务所有项目共用一个
*/ */
@QuartzScheduled(cron = "0 0 1 * * ?") @QuartzScheduled(cron = "0 26 11 * * ?")
public void cleanReport() { public void cleanReport() {
long count = getProjectCount(); long count = getProjectCount();
@ -82,6 +82,16 @@ public class CleanUpReportJob {
map.put(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name(), "3M"); 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<ProjectApplication> 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<String, BaseCleanUpReport> beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class); Map<String, BaseCleanUpReport> beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class);
beansOfType.forEach((k, v) -> { beansOfType.forEach((k, v) -> {
v.cleanReport(map, project.getId()); v.cleanReport(map, project.getId());