feat(任务中心): 系统任务中心任务详情停止&批量停止

This commit is contained in:
WangXu10 2024-10-18 14:23:44 +08:00 committed by Craftsman
parent be6fe24b60
commit 30c690bf46
11 changed files with 358 additions and 47 deletions

View File

@ -33,6 +33,8 @@ public class ProjectTaskHubController {
@Resource
private BaseTaskHubService baseTaskHubService;
@Resource
private BaseTaskHubLogService baseTaskHubLogService;
@PostMapping("/exec-task/page")
@Operation(summary = "项目-任务中心-执行任务列表")
@ -85,10 +87,11 @@ public class ProjectTaskHubController {
@PostMapping("/exec-task/batch-stop")
@Operation(summary = "项目-任务中心-用例执行任务-批量停止任务")
@Log(type = OperationLogType.UPDATE, expression = "#msClass.projectBatchStopLog(#id)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_EXEC_STOP)
public void batchStopTask(@Validated @RequestBody TableBatchProcessDTO request) {
baseTaskHubService.batchStopTask(request, SessionUtils.getUserId(), null, SessionUtils.getCurrentProjectId());
List<String> ids = baseTaskHubService.getTaskIds(request, null, SessionUtils.getCurrentProjectId());
baseTaskHubService.batchStopTask(ids, SessionUtils.getUserId(), null, SessionUtils.getCurrentProjectId());
baseTaskHubLogService.projectBatchStopLog(ids);
}
@ -102,9 +105,10 @@ public class ProjectTaskHubController {
@PostMapping("/exec-task/batch-delete")
@Operation(summary = "项目-任务中心-用例执行任务-批量删除任务")
@Log(type = OperationLogType.DELETE, expression = "#msClass.projectBatchDeleteLog(#id)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_DELETE)
public void batchDeleteTask(@PathVariable String id) {
baseTaskHubService.deleteTask(id, null, SessionUtils.getCurrentProjectId());
public void batchDeleteTask(@Validated @RequestBody TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request, null, SessionUtils.getCurrentProjectId());
baseTaskHubService.batchDeleteTask(ids, null, SessionUtils.getCurrentProjectId());
baseTaskHubLogService.projectBatchDeleteLog(ids);
}
}

View File

@ -37,6 +37,8 @@ public class OrganizationTaskHubController {
private BaseTaskHubService baseTaskHubService;
@Resource
BaseProjectMapper baseProjectMapper;
@Resource
private BaseTaskHubLogService baseTaskHubLogService;
@PostMapping("/exec-task/page")
@Operation(summary = "组织-任务中心-执行任务列表")
@ -92,10 +94,12 @@ public class OrganizationTaskHubController {
@PostMapping("/exec-task/batch-stop")
@Operation(summary = "组织-任务中心-用例执行任务-批量停止任务")
@Log(type = OperationLogType.UPDATE, expression = "#msClass.orgBatchStopLog(#id)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_EXEC_STOP)
public void batchStopTask(@Validated @RequestBody TableBatchProcessDTO request) {
baseTaskHubService.batchStopTask(request, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), null);
List<String> ids = baseTaskHubService.getTaskIds(request, SessionUtils.getCurrentOrganizationId(), null);
baseTaskHubService.batchStopTask(ids, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), null);
//日志
baseTaskHubLogService.orgBatchStopLog(ids);
}
@ -111,9 +115,11 @@ public class OrganizationTaskHubController {
@PostMapping("/exec-task/batch-delete")
@Operation(summary = "组织-任务中心-用例执行任务-批量删除任务")
@Log(type = OperationLogType.DELETE, expression = "#msClass.orgBatchDeleteLog(#request)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_DELETE)
public void batchDeleteTask(@Validated @RequestBody TableBatchProcessDTO request) {
baseTaskHubService.batchDeleteTask(request, SessionUtils.getCurrentOrganizationId(), null);
List<String> ids = baseTaskHubService.getTaskIds(request, SessionUtils.getCurrentOrganizationId(), null);
baseTaskHubService.batchDeleteTask(ids, SessionUtils.getCurrentOrganizationId(), null);
//日志
baseTaskHubLogService.orgBatchDeleteLog(ids);
}
}

View File

@ -4,6 +4,7 @@ import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.*;
import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse;
import io.metersphere.system.log.annotation.Log;
@ -31,6 +32,8 @@ public class SystemTaskHubController {
@Resource
private BaseTaskHubService baseTaskHubService;
@Resource
private BaseTaskHubLogService baseTaskHubLogService;
@PostMapping("/exec-task/page")
@Operation(summary = "系统-任务中心-执行任务列表")
@ -91,10 +94,12 @@ public class SystemTaskHubController {
@PostMapping("/exec-task/batch-stop")
@Operation(summary = "系统-任务中心-用例执行任务-批量停止任务")
@Log(type = OperationLogType.STOP, expression = "#msClass.systemBatchStopLog(#request)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_EXEC_STOP)
public void batchStopTask(@Validated @RequestBody TableBatchProcessDTO request) {
baseTaskHubService.batchStopTask(request, SessionUtils.getUserId(), null, null);
List<String> ids = baseTaskHubService.getTaskIds(request, null, null);
baseTaskHubService.batchStopTask(ids, SessionUtils.getUserId(), null, null);
//系統日志
baseTaskHubLogService.systemBatchStopLog(ids);
}
@ -109,16 +114,36 @@ public class SystemTaskHubController {
@PostMapping("/exec-task/batch-delete")
@Operation(summary = "系统-任务中心-用例执行任务-批量删除任务")
@Log(type = OperationLogType.DELETE, expression = "#msClass.systemBatchDeleteLog(#request)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_DELETE)
public void batchDeleteTask(@Validated @RequestBody TableBatchProcessDTO request) {
baseTaskHubService.batchDeleteTask(request, SessionUtils.getCurrentOrganizationId(), null);
List<String> ids = baseTaskHubService.getTaskIds(request, null, null);
baseTaskHubService.batchDeleteTask(ids, SessionUtils.getCurrentOrganizationId(), null);
//系統日志
baseTaskHubLogService.systemBatchDeleteLog(ids);
}
//TODO 系统&组织&项目 任务按钮操作失败重跑 查看报告 批量失败重跑
//TODO 系统&组织&项目 任务详情按钮操作查看 停止 批量停止
@GetMapping("/exec-task/item/stop/{id}")
@Operation(summary = "系统-任务中心-用例任务详情-停止任务")
@Log(type = OperationLogType.STOP, expression = "#msClass.systemStopItemLog(#id)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_EXEC_STOP)
public void stopTaskItem(@PathVariable String id) {
baseTaskHubService.stopTaskItem(id, SessionUtils.getUserId(), null, null);
}
@PostMapping("/exec-task/item/batch-stop")
@Operation(summary = "系统-任务中心-用例任务详情-批量停止任务")
@Log(type = OperationLogType.STOP, expression = "#msClass.systemBatchStopItemLog(#request)", msClass = BaseTaskHubLogService.class)
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_EXEC_STOP)
public void batchStopTaskItem(@Validated @RequestBody TaskHubItemBatchRequest request) {
List<String> itemIds = baseTaskHubService.getTaskItemIds(request, null, null);
baseTaskHubService.batchStopTaskItem(itemIds, SessionUtils.getUserId(), null, null);
baseTaskHubLogService.systemBatchStopItemLog(itemIds);
}
//TODO 系统&组织&项目 任务详情按钮操作查看
//TODO 系统&组织&项目 后台任务操作删除 批量开启 批量关闭

View File

@ -0,0 +1,24 @@
package io.metersphere.system.dto.taskhub.request;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* @author wx
*/
@Data
public class TaskHubItemBatchRequest extends TableBatchProcessDTO {
@Schema(description = "任务id")
private String taskId;
@Schema(description = "资源池id")
private List<String> resourcePoolIds;
@Schema(description = "资源池节点")
private List<String> resourcePoolNodes;
}

View File

@ -1,6 +1,7 @@
package io.metersphere.system.mapper;
import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import org.apache.ibatis.annotations.Param;
@ -25,6 +26,7 @@ public interface ExtExecTaskItemMapper {
/**
* 查询时间范围内的任务项ID集合
*
* @param timeMills 时间戳
* @param projectId 项目ID
* @return 任务项ID列表
@ -38,4 +40,10 @@ public interface ExtExecTaskItemMapper {
Boolean hasFakeErrorItem(@Param("taskId") String taskId);
List<String> getItemIdByTaskIds(@Param("taskIds") List<String> taskIds);
void batchUpdateTaskItemStatusByIds(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("organizationId") String organizationId, @Param("projectId") String projectId, @Param("status") String status);
List<ExecTaskItem> getResourcePoolsByItemIds(@Param("ids") List<String> ids);
List<String> getIds(@Param("request") TableBatchProcessDTO request, @Param("organizationId") String organizationId, @Param("projectId") String projectId);
}

View File

@ -99,6 +99,11 @@
and exec_task_item.result in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<!-- 执行方式 -->
<when test="key=='triggerMode'">
and exec_task.trigger_mode in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
</choose>
</if>
</foreach>
@ -160,4 +165,65 @@
#{taskId}
</foreach>
</select>
<update id="batchUpdateTaskItemStatusByIds">
UPDATE exec_task_item
SET `status` = #{status},
executor = #{userId}
WHERE id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
<if test="projectId != null and projectId != ''">
and project_id = #{projectId}
</if>
<if test="organizationId != null and organizationId != ''">
and organization_id = #{organizationId}
</if>
and `status` = 'RUNNING'
</update>
<select id="getResourcePoolsByItemIds" resultType="io.metersphere.system.domain.ExecTaskItem">
SELECT
id,
resource_pool_node,
resource_pool_id
FROM
exec_task_item
<if test="ids != null and ids.size() > 0">
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="getIds" resultType="java.lang.String">
select id from exec_task_item
inner join exec_task on exec_task_item.task_id = exec_task.id
<where>
<if test="projectId != null and projectId != ''">
and exec_task_item.project_id = #{projectId}
</if>
<if test="organizationId != null and organizationId != ''">
and exec_task_item.organization_id = #{organizationId}
</if>
<include refid="queryWhereConditionByBaseQueryRequest"/>
</where>
</select>
<sql id="queryWhereConditionByBaseQueryRequest">
<if test="request.condition.keyword != null and request.condition.keyword != ''">
and (
exec_task.num like concat('%', #{request.keyword},'%')
or exec_task_item.resource_name like concat('%', #{request.keyword},'%')
)
</if>
<include refid="filters">
<property name="filter" value="request.condition.filter"/>
</include>
</sql>
</mapper>

View File

@ -15,7 +15,7 @@ public interface ExtExecTaskMapper {
void deleteTaskByIds(@Param("ids") List<String> ids, @Param("orgId") String orgId, @Param("projectId") String projectId);
List<String> getIds(@Param("request") TableBatchProcessDTO request);
List<String> getIds(@Param("request") TableBatchProcessDTO request, @Param("organizationId") String organizationId, @Param("projectId") String projectId);
void batchUpdateTaskStatus(@Param("ids") List<String> ids, @Param("userId") String userId, @Param("organizationId") String organizationId, @Param("projectId") String projectId, @Param("status") String status);

View File

@ -47,6 +47,12 @@
<select id="getIds" resultType="java.lang.String">
select id from exec_task
<where>
<if test="projectId != null and projectId != ''">
and exec_task.project_id = #{projectId}
</if>
<if test="organizationId != null and organizationId != ''">
and exec_task.organization_id = #{organizationId}
</if>
<include refid="queryWhereConditionByBaseQueryRequest"/>
</where>
</select>

View File

@ -3,10 +3,13 @@ package io.metersphere.system.service;
import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.ExecTaskExample;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.domain.ExecTaskItemExample;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.ExecTaskItemMapper;
import io.metersphere.system.mapper.ExecTaskMapper;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
@ -25,7 +28,9 @@ public class BaseTaskHubLogService {
@Resource
private ExecTaskMapper execTaskMapper;
@Resource
private BaseTaskHubService baseTaskHubService;
private OperationLogService operationLogService;
@Resource
private ExecTaskItemMapper execTaskItemMapper;
/**
* 系统停止任务日志
@ -52,11 +57,13 @@ public class BaseTaskHubLogService {
/**
* 系统批量停止任务日志
*
* @param request
* @param ids
* @return
*/
public List<LogDTO> systemBatchStopLog(TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request);
public void systemBatchStopLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskExample example = new ExecTaskExample();
example.createCriteria().andIdIn(ids);
List<ExecTask> execTasks = execTaskMapper.selectByExample(example);
@ -74,7 +81,7 @@ public class BaseTaskHubLogService {
logDTOList.add(dto);
});
}
return logDTOList;
operationLogService.batchAdd(logDTOList);
}
@ -104,11 +111,13 @@ public class BaseTaskHubLogService {
/**
* 组织批量停止任务日志
*
* @param request
* @param ids
* @return
*/
public List<LogDTO> orgBatchStopLog(TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request);
public void orgBatchStopLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskExample example = new ExecTaskExample();
example.createCriteria().andIdIn(ids);
List<ExecTask> execTasks = execTaskMapper.selectByExample(example);
@ -126,7 +135,7 @@ public class BaseTaskHubLogService {
logDTOList.add(dto);
});
}
return logDTOList;
operationLogService.batchAdd(logDTOList);
}
@ -156,11 +165,13 @@ public class BaseTaskHubLogService {
/**
* 项目批量停止任务日志
*
* @param request
* @param ids
* @return
*/
public List<LogDTO> projectBatchStopLog(TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request);
public void projectBatchStopLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskExample example = new ExecTaskExample();
example.createCriteria().andIdIn(ids);
List<ExecTask> execTasks = execTaskMapper.selectByExample(example);
@ -178,7 +189,7 @@ public class BaseTaskHubLogService {
logDTOList.add(dto);
});
}
return logDTOList;
operationLogService.batchAdd(logDTOList);
}
@ -207,11 +218,13 @@ public class BaseTaskHubLogService {
/**
* 系统批量删除任务日志
*
* @param request
* @param ids
* @return
*/
public List<LogDTO> systemBatchDeleteLog(TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request);
public void systemBatchDeleteLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskExample example = new ExecTaskExample();
example.createCriteria().andIdIn(ids);
List<ExecTask> execTasks = execTaskMapper.selectByExample(example);
@ -229,7 +242,7 @@ public class BaseTaskHubLogService {
logDTOList.add(dto);
});
}
return logDTOList;
operationLogService.batchAdd(logDTOList);
}
/**
@ -257,11 +270,13 @@ public class BaseTaskHubLogService {
/**
* 组织批量删除任务日志
*
* @param request
* @param ids
* @return
*/
public List<LogDTO> orgBatchDeleteLog(TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request);
public void orgBatchDeleteLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskExample example = new ExecTaskExample();
example.createCriteria().andIdIn(ids);
List<ExecTask> execTasks = execTaskMapper.selectByExample(example);
@ -279,7 +294,7 @@ public class BaseTaskHubLogService {
logDTOList.add(dto);
});
}
return logDTOList;
operationLogService.batchAdd(logDTOList);
}
/**
@ -308,11 +323,13 @@ public class BaseTaskHubLogService {
/**
* 项目批量删除任务日志
*
* @param request
* @param ids
* @return
*/
public List<LogDTO> projectBatchDeleteLog(TableBatchProcessDTO request) {
List<String> ids = baseTaskHubService.getTaskIds(request);
public void projectBatchDeleteLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskExample example = new ExecTaskExample();
example.createCriteria().andIdIn(ids);
List<ExecTask> execTasks = execTaskMapper.selectByExample(example);
@ -330,6 +347,61 @@ public class BaseTaskHubLogService {
logDTOList.add(dto);
});
}
return logDTOList;
operationLogService.batchAdd(logDTOList);
}
/**
* 系统停止任务项日志
*
* @param id
* @return
*/
public LogDTO systemStopItemLog(String id) {
ExecTaskItem execTaskItem = execTaskItemMapper.selectByPrimaryKey(id);
LogDTO dto = null;
if (execTaskItem != null) {
dto = new LogDTO(
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
execTaskItem.getId(),
null,
OperationLogType.STOP.name(),
OperationLogModule.SETTING_SYSTEM_TASK_CENTER,
execTaskItem.getResourceName());
}
return dto;
}
/**
* 系统批量停止任务项日志
*
* @param ids
* @return
*/
public void systemBatchStopItemLog(List<String> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
ExecTaskItemExample example = new ExecTaskItemExample();
example.createCriteria().andIdIn(ids);
List<ExecTaskItem> execTasks = execTaskItemMapper.selectByExample(example);
List<LogDTO> logDTOList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(execTasks)) {
execTasks.forEach(item -> {
LogDTO dto = new LogDTO(
OperationLogConstants.SYSTEM,
OperationLogConstants.SYSTEM,
item.getId(),
null,
OperationLogType.STOP.name(),
OperationLogModule.SETTING_SYSTEM_TASK_CENTER,
item.getResourceName());
logDTOList.add(dto);
});
}
operationLogService.batchAdd(logDTOList);
}
}

View File

@ -27,6 +27,7 @@ import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.*;
import io.metersphere.system.dto.taskhub.request.TaskHubItemBatchRequest;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.dto.taskhub.response.TaskStatisticsResponse;
import io.metersphere.system.mapper.*;
@ -552,8 +553,7 @@ public class BaseTaskHubService {
apiReportRelateTaskMapper.deleteByExample(reportExample);
}
public void batchStopTask(TableBatchProcessDTO request, String userId, String orgId, String projectId) {
List<String> ids = getTaskIds(request);
public void batchStopTask(List<String> ids, String userId, String orgId, String projectId) {
if (CollectionUtils.isNotEmpty(ids)) {
//1.更新任务状态
extExecTaskMapper.batchUpdateTaskStatus(ids, userId, orgId, projectId, ExecStatus.STOPPED.name());
@ -564,9 +564,9 @@ public class BaseTaskHubService {
}
public List<String> getTaskIds(TableBatchProcessDTO request) {
public List<String> getTaskIds(TableBatchProcessDTO request, String orgId, String projectId) {
if (request.isSelectAll()) {
List<String> ids = extExecTaskMapper.getIds(request);
List<String> ids = extExecTaskMapper.getIds(request, orgId, projectId);
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
ids.removeAll(request.getExcludeIds());
}
@ -576,8 +576,7 @@ public class BaseTaskHubService {
}
}
public void batchDeleteTask(TableBatchProcessDTO request, String orgId, String projectId) {
List<String> ids = getTaskIds(request);
public void batchDeleteTask(List<String> ids, String orgId, String projectId) {
if (CollectionUtils.isNotEmpty(ids)) {
//1.删除任务
extExecTaskMapper.deleteTaskByIds(ids, orgId, projectId);
@ -590,4 +589,74 @@ public class BaseTaskHubService {
handleStopTask(ids);
}
}
/**
* 停止任务项
*
* @param id
* @param userId
* @param orgId
* @param projectId
*/
public void stopTaskItem(String id, String userId, String orgId, String projectId) {
//1.更新任务明细状态
extExecTaskItemMapper.batchUpdateTaskItemStatusByIds(List.of(id), userId, orgId, projectId, ExecStatus.STOPPED.name());
//2.通过任务项id停止任务
handleStopTaskItem(List.of(id));
}
private void handleStopTaskItem(List<String> ids) {
List<ExecTaskItem> execTaskItems = extExecTaskItemMapper.getResourcePoolsByItemIds(ids);
Map<String, List<ExecTaskItem>> resourcePoolMaps = execTaskItems.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolId));
resourcePoolMaps.forEach((k, v) -> {
//判断资源池类型
TestResourcePoolReturnDTO testResourcePoolDTO = testResourcePoolService.getTestResourcePoolDetail(k);
boolean isK8SResourcePool = StringUtils.equals(testResourcePoolDTO.getType(), ResourcePoolTypeEnum.K8S.getName());
if (isK8SResourcePool) {
List<String> itemIds = v.stream().map(ExecTaskItem::getId).toList();
//K8S 通过任务项id停止任务项
handleK8STaskItem(itemIds, testResourcePoolDTO);
} else {
Map<String, List<ExecTaskItem>> nodeItem = execTaskItems.stream().collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
handleNodeTask(nodeItem);
}
});
}
private void handleK8STaskItem(List<String> itemIds, TestResourcePoolReturnDTO testResourcePoolDTO) {
SubListUtils.dealForSubList(itemIds, 100, subList -> {
try {
TestResourceDTO testResourceDTO = new TestResourceDTO();
BeanUtils.copyBean(testResourceDTO, testResourcePoolDTO.getTestResourceReturnDTO());
EngineFactory.stopApiTaskItem(subList, testResourceDTO);
} catch (Exception e) {
LogUtils.error(e);
}
});
}
public void batchStopTaskItem(List<String> itemIds, String userId, String orgId, String projectId) {
if (CollectionUtils.isNotEmpty(itemIds)) {
//1.更新任务明细状态
extExecTaskItemMapper.batchUpdateTaskItemStatusByIds(itemIds, userId, orgId, projectId, ExecStatus.STOPPED.name());
//2.通过任务项id停止任务
handleStopTaskItem(itemIds);
}
}
public List<String> getTaskItemIds(TaskHubItemBatchRequest request, String orgId, String projectId) {
if (request.isSelectAll()) {
List<String> ids = extExecTaskItemMapper.getIds(request, orgId, projectId);
if (CollectionUtils.isNotEmpty(request.getExcludeIds())) {
ids.removeAll(request.getExcludeIds());
}
return ids;
} else {
return request.getSelectIds();
}
}
}

View File

@ -45,6 +45,8 @@ public class BaseTaskHubControllerTests extends BaseTest {
public static final String SYSTEM_TASK_DELETE = "/system/task-center/exec-task/delete/";
public static final String SYSTEM_TASK_BATCH_STOP = "/system/task-center/exec-task/batch-stop/";
public static final String SYSTEM_TASK_BATCH_DELETE = "/system/task-center/exec-task/batch-delete/";
public static final String SYSTEM_TASK_ITEM_STOP = "/system/task-center/exec-task/item/stop/";
public static final String SYSTEM_TASK_ITEM_BATCH_STOP = "/system/task-center/exec-task/item/batch-stop";
@Test
@Order(1)
@ -161,6 +163,21 @@ public class BaseTaskHubControllerTests extends BaseTest {
Assertions.assertNotNull(resultHolder);
}
/**
* 系统任务项停止
*/
@Test
@Order(4)
public void systemTaskItemStop() throws Exception {
this.requestGet(SYSTEM_TASK_ITEM_STOP + "1");
MvcResult mvcResult = this.requestGetWithOkAndReturn(SYSTEM_TASK_ITEM_STOP + "2");
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* 系统执行任务删除
@ -200,6 +217,20 @@ public class BaseTaskHubControllerTests extends BaseTest {
this.requestPost(SYSTEM_TASK_BATCH_STOP, request);
}
/**
* 系统任务项停止
*/
@Test
@Order(5)
public void systemTaskItemBatchStop() throws Exception {
TableBatchProcessDTO request = new TableBatchProcessDTO();
request.setSelectAll(true);
this.requestPost(SYSTEM_TASK_ITEM_BATCH_STOP, request);
request.setSelectAll(false);
request.setSelectIds(List.of("1", "2"));
this.requestPost(SYSTEM_TASK_ITEM_BATCH_STOP, request);
}
/**
* 组织任务中心测试用例