From 49e605e180034e19edc7f57c9fc0d9c7606bc049 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Tue, 19 Nov 2024 13:44:57 +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=8C=89=E7=85=A7=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1049022 --user=宋昌昌 【任务中心】-系统任务保留时间不生效,超出保留时间的任务没有被清理 https://www.tapd.cn/55049933/s/1611968 --- .../api/service/CleanupTaskResultServiceImpl.java | 15 ++++++++++++--- .../api/service/CleanupTaskServiceImpl.java | 8 ++++---- .../api/controller/CleanupTaskResultTests.java | 2 +- .../system/mapper/ExtExecTaskMapper.xml | 2 +- 4 files changed, 18 insertions(+), 9 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 752019f4e4..29c6b60bbe 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 @@ -5,7 +5,9 @@ import io.metersphere.api.mapper.ApiReportRelateTaskMapper; import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.SubListUtils; -import io.metersphere.system.mapper.ExtExecTaskItemMapper; +import io.metersphere.system.domain.ExecTaskItem; +import io.metersphere.system.domain.ExecTaskItemExample; +import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.service.BaseCleanUpReport; import jakarta.annotation.Resource; @@ -14,6 +16,7 @@ import org.apache.commons.collections4.ListUtils; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -29,7 +32,7 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { @Resource private ExtExecTaskMapper extExecTaskMapper; @Resource - private ExtExecTaskItemMapper extExecTaskItemMapper; + private ExecTaskItemMapper execTaskItemMapper; @Resource private ApiReportRelateTaskMapper apiReportRelateTaskMapper; @@ -40,7 +43,13 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { String expr = map.get(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name()); long timeMills = getCleanDate(expr); List cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); - List cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId); + 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(); List cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds); LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条"); if (CollectionUtils.isNotEmpty(cleanIds)) { 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 7c0392cd97..d2980b987f 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 @@ -8,7 +8,6 @@ import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.domain.ExecTaskItemExample; import io.metersphere.system.mapper.ExecTaskItemMapper; import io.metersphere.system.mapper.ExecTaskMapper; -import io.metersphere.system.mapper.ExtExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.service.BaseCleanUpReport; import jakarta.annotation.Resource; @@ -31,8 +30,6 @@ public class CleanupTaskServiceImpl implements BaseCleanUpReport { @Resource private ExtExecTaskMapper extExecTaskMapper; @Resource - private ExtExecTaskItemMapper extExecTaskItemMapper; - @Resource private ExecTaskMapper execTaskMapper; @Resource private ExecTaskItemMapper execTaskItemMapper; @@ -44,7 +41,10 @@ public class CleanupTaskServiceImpl implements BaseCleanUpReport { String expr = map.get(ProjectApplicationType.TASK.TASK_RECORD.name()); long timeMills = getCleanDate(expr); List cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); - List cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId); + ExecTaskItemExample itemExample = new ExecTaskItemExample(); + itemExample.createCriteria().andTaskIdIn(cleanTaskIds); + List execTaskItems = execTaskItemMapper.selectByExample(itemExample); + List cleanTaskItemIds = execTaskItems.stream().map(ExecTaskItem::getId).toList(); if (CollectionUtils.isNotEmpty(cleanTaskIds)) { ExecTaskExample example = new ExecTaskExample(); example.createCriteria().andIdIn(cleanTaskIds); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java index 6946892567..fac7e247a3 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java @@ -40,7 +40,7 @@ public class CleanupTaskResultTests { task.setStartTime(1700000000000L); task.setResult("PENDING"); task.setCreateUser("admin"); - task.setCreateTime(System.currentTimeMillis()); + task.setCreateTime(1700000000000L); execTaskMapper.insertSelective(task); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml index ba54bb4275..c2b868bde2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml @@ -131,7 +131,7 @@