refactor(任务中心): 执行历史清理优化
--task=1016921 --user=宋昌昌 执行历史优化 https://www.tapd.cn/55049933/s/1610494
This commit is contained in:
parent
268d04f1f5
commit
e2ef7e8c93
|
@ -19,7 +19,11 @@ public class ProjectApplicationType {
|
|||
*/
|
||||
public enum TASK {
|
||||
/**
|
||||
* 清理报告
|
||||
* 系统即时任务
|
||||
*/
|
||||
TASK_RECORD,
|
||||
/**
|
||||
* 任务执行结果
|
||||
*/
|
||||
TASK_CLEAN_REPORT,
|
||||
}
|
||||
|
|
|
@ -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<ApiReportRelateTask> relateTasks = apiReportRelateTaskMapper.selectByExample(example);
|
||||
List<String> ids = relateTasks.stream().map(ApiReportRelateTask::getTaskResourceId).toList();
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> deletedIds = extApiReportRelateTaskMapper.selectDeleteTaskOrItem(ids);
|
||||
relateTasks.removeIf(relateTask -> deletedIds.contains(relateTask.getTaskResourceId()));
|
||||
return relateTasks.stream().map(ApiReportRelateTask::getReportId).toList();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId);
|
||||
List<String> 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<String> cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds);
|
||||
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条");
|
||||
if (CollectionUtils.isNotEmpty(cleanIds)) {
|
||||
|
|
|
@ -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<String, String> map, String projectId) {
|
||||
LogUtils.info("清理当前项目[" + projectId + "]即时任务");
|
||||
String expr = map.get(ProjectApplicationType.TASK.TASK_RECORD.name());
|
||||
long timeMills = getCleanDate(expr);
|
||||
List<String> cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId);
|
||||
List<String> 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 + "]即时任务结束!");
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
|
|
|
@ -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': '重新提审',
|
||||
|
|
|
@ -168,6 +168,15 @@
|
|||
handleMenuStatusChange('TASK_CLEAN_REPORT', v, MenuEnum.taskCenter)"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="record.type === 'TASK_RECORD'">
|
||||
<MsTimeSelectorVue
|
||||
v-model="allValueMap['TASK_RECORD']"
|
||||
:disabled="!hasAnyPermission(['PROJECT_APPLICATION_TASK:UPDATE'])"
|
||||
:default-value="defaultValueMap.TASK_RECORD"
|
||||
@change="(v: string) =>
|
||||
handleMenuStatusChange('TASK_RECORD', v, MenuEnum.taskCenter)"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="record.type === 'UI_CLEAN_REPORT'">
|
||||
<!--UI 报告保留时间范围 -->
|
||||
<MsTimeSelectorVue
|
||||
|
@ -467,6 +476,7 @@
|
|||
API_CLEAN_REPORT: '3M',
|
||||
API_SHARE_REPORT: '1D',
|
||||
TASK_CLEAN_REPORT: '3M',
|
||||
TASK_RECORD: '3M',
|
||||
UI_CLEAN_REPORT: '3M',
|
||||
UI_SHARE_REPORT: '1D',
|
||||
PERFORMANCE_TEST_CLEAN_REPORT: '3M',
|
||||
|
@ -602,6 +612,9 @@
|
|||
}
|
||||
case MenuEnum.taskCenter: {
|
||||
children = [
|
||||
{
|
||||
type: 'TASK_RECORD', // 即时任务保留时间
|
||||
},
|
||||
{
|
||||
type: 'TASK_CLEAN_REPORT', // 任务执行结果保留时间范围
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue