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 @@