refactor(任务中心): 返回执行结果是否删除判断标识

This commit is contained in:
WangXu10 2024-11-15 14:59:32 +08:00 committed by Craftsman
parent 400194b212
commit e9fa95b1e9
5 changed files with 56 additions and 1 deletions

View File

@ -1,7 +1,9 @@
package io.metersphere.api.service; package io.metersphere.api.service;
import io.metersphere.api.domain.ApiReportRelateTaskExample;
import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.ExecTaskExample; import io.metersphere.system.domain.ExecTaskExample;
import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.domain.ExecTaskItem;
@ -11,10 +13,12 @@ import io.metersphere.system.mapper.ExecTaskMapper;
import io.metersphere.system.mapper.ExtExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskItemMapper;
import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.mapper.ExtExecTaskMapper;
import io.metersphere.system.service.BaseCleanUpReport; import io.metersphere.system.service.BaseCleanUpReport;
import org.apache.commons.collections4.ListUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; 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 io.metersphere.api.mapper.ApiReportRelateTaskMapper;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -35,6 +39,8 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport {
@Resource @Resource
private ExecTaskMapper execTaskMapper; private ExecTaskMapper execTaskMapper;
@Resource @Resource
private ApiReportRelateTaskMapper apiReportRelateTaskMapper;
@Resource
private ExecTaskItemMapper execTaskItemMapper; private ExecTaskItemMapper execTaskItemMapper;
@ -59,6 +65,16 @@ public class CleanupTaskResultServiceImpl implements BaseCleanUpReport {
execTaskItem.setDeleted(true); execTaskItem.setDeleted(true);
execTaskItemMapper.updateByExampleSelective(execTaskItem, example); execTaskItemMapper.updateByExampleSelective(execTaskItem, example);
} }
List<String> cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds);
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条");
if (CollectionUtils.isNotEmpty(cleanIds)) {
// 清理任务-报告关系表
SubListUtils.dealForSubList(cleanIds, 100, ids -> {
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andTaskResourceIdIn(cleanIds);
apiReportRelateTaskMapper.deleteByExample(example);
});
}
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果结束!"); LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果结束!");
} }
} }

View File

@ -24,4 +24,7 @@ public class TaskHubDTO extends ExecTask {
@Schema(description = "报告ID") @Schema(description = "报告ID")
private String reportId; private String reportId;
@Schema(description = "结果是否被删除")
private Boolean resultDeleted = true;
} }

View File

@ -39,4 +39,10 @@ public class TaskHubItemDTO extends ExecTaskItem {
@Schema(description = "错误信息") @Schema(description = "错误信息")
private String errorMessage; private String errorMessage;
@Schema(description = "是否集合报告")
private Boolean integrated;
@Schema(description = "结果是否被删除")
private Boolean resultDeleted = true;
} }

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.system.mapper.ExtExecTaskItemMapper"> <mapper namespace="io.metersphere.system.mapper.ExtExecTaskItemMapper">
<select id="selectList" resultType="io.metersphere.system.dto.taskhub.TaskHubItemDTO"> <select id="selectList" resultType="io.metersphere.system.dto.taskhub.TaskHubItemDTO">
SELECT exec_task_item.*, exec_task.num, exec_task.task_name, exec_task.trigger_mode SELECT exec_task_item.*, exec_task.num, exec_task.task_name, exec_task.trigger_mode, exec_task.integrated
FROM exec_task_item FROM exec_task_item
inner join exec_task on exec_task_item.task_id = exec_task.id inner join exec_task on exec_task_item.task_id = exec_task.id
<include refid="queryWhereCondition"/> <include refid="queryWhereCondition"/>

View File

@ -215,9 +215,11 @@ public class BaseTaskHubService {
reportTasks.forEach(task -> { reportTasks.forEach(task -> {
if (integratedTaskIds.contains(task.getId())) { if (integratedTaskIds.contains(task.getId())) {
task.setReportId(reportMap.get(task.getId())); task.setReportId(reportMap.get(task.getId()));
task.setResultDeleted(false);
} else { } else {
if (taskItemMap.containsKey(task.getId())) { if (taskItemMap.containsKey(task.getId())) {
task.setReportId(reportMap.get(taskItemMap.get(task.getId()))); task.setReportId(reportMap.get(taskItemMap.get(task.getId())));
task.setResultDeleted(false);
} }
} }
}); });
@ -376,6 +378,34 @@ public class BaseTaskHubService {
item.setErrorMessage(Translator.get("task_error_message." + item.getErrorMessage().toLowerCase())); item.setErrorMessage(Translator.get("task_error_message." + item.getErrorMessage().toLowerCase()));
} }
}); });
handleResultFlag(list);
}
/**
* 处理执行结果是否被删除标识
*
* @param list
*/
private void handleResultFlag(List<TaskHubItemDTO> list) {
List<String> integratedTaskIds = list.stream().filter(item -> BooleanUtils.isTrue(item.getIntegrated())).map(TaskHubItemDTO::getTaskId).toList();
List<String> noIntegratedTaskItemIds = list.stream().filter(item -> BooleanUtils.isFalse(item.getIntegrated())).map(TaskHubItemDTO::getId).toList();
List<String> resourceIds = ListUtils.union(integratedTaskIds, noIntegratedTaskItemIds);
if (CollectionUtils.isEmpty(resourceIds)) {
return;
}
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andTaskResourceIdIn(resourceIds);
List<ApiReportRelateTask> reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
Map<String, String> reportMap = reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId));
list.forEach(task -> {
if (BooleanUtils.isTrue(task.getIntegrated()) && reportMap.containsKey(task.getTaskId())) {
task.setResultDeleted(false);
}
if (BooleanUtils.isFalse(task.getIntegrated()) && reportMap.containsKey(task.getId())) {
task.setResultDeleted(false);
}
});
} }
private Map<String, String> getResourcePoolMaps(List<String> resourcePoolIds) { private Map<String, String> getResourcePoolMaps(List<String> resourcePoolIds) {