diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java index 3c4d22ceeb..3fab998ad2 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java @@ -19,7 +19,11 @@ public class ProjectApplicationType { */ public enum TASK { /** - * 清理报告 + * 系统即时任务 + */ + TASK_RECORD, + /** + * 任务执行结果 */ TASK_CLEAN_REPORT, } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java index 3259ef8ec3..79a6865d71 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java @@ -6,11 +6,9 @@ import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.service.BaseCleanUpReport; import jakarta.annotation.Resource; -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; @@ -92,12 +90,6 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport { ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); example.createCriteria().andReportIdIn(reportIds); List relateTasks = apiReportRelateTaskMapper.selectByExample(example); - List ids = relateTasks.stream().map(ApiReportRelateTask::getTaskResourceId).toList(); - if (CollectionUtils.isEmpty(ids)) { - return new ArrayList<>(); - } - List deletedIds = extApiReportRelateTaskMapper.selectDeleteTaskOrItem(ids); - relateTasks.removeIf(relateTask -> deletedIds.contains(relateTask.getTaskResourceId())); return relateTasks.stream().map(ApiReportRelateTask::getReportId).toList(); } 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 a383a39c16..752019f4e4 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 @@ -1,24 +1,18 @@ package io.metersphere.api.service; import io.metersphere.api.domain.ApiReportRelateTaskExample; +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.domain.ExecTask; -import io.metersphere.system.domain.ExecTaskExample; -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 org.apache.commons.collections4.ListUtils; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import io.metersphere.api.mapper.ApiReportRelateTaskMapper; import java.util.List; import java.util.Map; @@ -37,11 +31,7 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { @Resource private ExtExecTaskItemMapper extExecTaskItemMapper; @Resource - private ExecTaskMapper execTaskMapper; - @Resource private ApiReportRelateTaskMapper apiReportRelateTaskMapper; - @Resource - private ExecTaskItemMapper execTaskItemMapper; @Override @@ -51,20 +41,6 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { long timeMills = getCleanDate(expr); List cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); List cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId); - if (CollectionUtils.isNotEmpty(cleanTaskIds)) { - ExecTaskExample example = new ExecTaskExample(); - example.createCriteria().andIdIn(cleanTaskIds); - ExecTask execTask = new ExecTask(); - execTask.setDeleted(true); - execTaskMapper.updateByExampleSelective(execTask, example); - } - if (CollectionUtils.isNotEmpty(cleanTaskItemIds)) { - ExecTaskItemExample example = new ExecTaskItemExample(); - example.createCriteria().andIdIn(cleanTaskItemIds); - ExecTaskItem execTaskItem = new ExecTaskItem(); - execTaskItem.setDeleted(true); - execTaskItemMapper.updateByExampleSelective(execTaskItem, example); - } 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 new file mode 100644 index 0000000000..7c0392cd97 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskServiceImpl.java @@ -0,0 +1,64 @@ +package io.metersphere.api.service; + +import io.metersphere.sdk.constants.ProjectApplicationType; +import io.metersphere.sdk.util.LogUtils; +import io.metersphere.system.domain.ExecTask; +import io.metersphere.system.domain.ExecTaskExample; +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; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; + +import static io.metersphere.sdk.util.ShareUtil.getCleanDate; + +/** + * @author song-cc-rock + */ +@Component +@Transactional(rollbackFor = Exception.class) +public class CleanupTaskServiceImpl implements BaseCleanUpReport { + + @Resource + private ExtExecTaskMapper extExecTaskMapper; + @Resource + private ExtExecTaskItemMapper extExecTaskItemMapper; + @Resource + private ExecTaskMapper execTaskMapper; + @Resource + private ExecTaskItemMapper execTaskItemMapper; + + + @Override + public void cleanReport(Map map, String projectId) { + LogUtils.info("清理当前项目[" + projectId + "]即时任务"); + 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); + if (CollectionUtils.isNotEmpty(cleanTaskIds)) { + ExecTaskExample example = new ExecTaskExample(); + example.createCriteria().andIdIn(cleanTaskIds); + ExecTask execTask = new ExecTask(); + execTask.setDeleted(true); + execTaskMapper.updateByExampleSelective(execTask, example); + } + if (CollectionUtils.isNotEmpty(cleanTaskItemIds)) { + ExecTaskItemExample example = new ExecTaskItemExample(); + example.createCriteria().andIdIn(cleanTaskItemIds); + ExecTaskItem execTaskItem = new ExecTaskItem(); + execTaskItem.setDeleted(true); + execTaskItemMapper.updateByExampleSelective(execTaskItem, example); + } + LogUtils.info("清理当前项目[" + projectId + "]即时任务结束!"); + } +} diff --git a/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/en-US.ts b/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/en-US.ts index 74ed935e8d..ca682b57a0 100644 --- a/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/en-US.ts +++ b/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/en-US.ts @@ -30,7 +30,8 @@ export default { 'project.menu.API_ERROR_REPORT_RULE_TIP': 'When the interface returns a result that matches the false alert rule, the interface result will be treated as a false alert', 'project.menu.API_SYNC_CASE': 'Change Synchronized CASE', - 'project.menu.TASK_CLEAN_REPORT': 'Result Retention Time', + 'project.menu.TASK_CLEAN_REPORT': 'Task Result Keep time', + 'project.menu.TASK_RECORD': 'Task Keep time', 'project.menu.CASE_PUBLIC': 'Public Test Case Library', 'project.menu.CASE_RE_REVIEW': 'Re-review', diff --git a/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/zh-CN.ts b/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/zh-CN.ts index 80a8f128b3..0a31830725 100644 --- a/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/zh-CN.ts +++ b/frontend/src/views/project-management/projectAndPermission/menuManagement/locale/zh-CN.ts @@ -27,7 +27,8 @@ export default { 'project.menu.API_ERROR_REPORT_RULE': '误报规则', 'project.menu.API_ERROR_REPORT_RULE_TIP': '当接口返回结果匹配上误报规则后,会将接口结果处理为误报', 'project.menu.API_SYNC_CASE': '变更同步CASE', - 'project.menu.TASK_CLEAN_REPORT': '执行结果保留时间', + 'project.menu.TASK_CLEAN_REPORT': '任务执行结果保留时间', + 'project.menu.TASK_RECORD': '系统执行任务保留时间', 'project.menu.CASE_PUBLIC': '公共用例库', 'project.menu.CASE_RE_REVIEW': '重新提审', diff --git a/frontend/src/views/project-management/projectAndPermission/menuManagement/menuManagement.vue b/frontend/src/views/project-management/projectAndPermission/menuManagement/menuManagement.vue index 6bb50e5586..58b67f107d 100644 --- a/frontend/src/views/project-management/projectAndPermission/menuManagement/menuManagement.vue +++ b/frontend/src/views/project-management/projectAndPermission/menuManagement/menuManagement.vue @@ -168,6 +168,15 @@ handleMenuStatusChange('TASK_CLEAN_REPORT', v, MenuEnum.taskCenter)" /> +
+ +