feat(任务中心): 补充任务批量执行查询接口

--task=1016480 --user=宋昌昌 任务中心-后台执行任务业务逻辑 https://www.tapd.cn/55049933/s/1594425
This commit is contained in:
song-cc-rock 2024-10-21 14:36:00 +08:00 committed by Craftsman
parent c268465059
commit e25ba8a7b3
11 changed files with 178 additions and 8 deletions

View File

@ -1,8 +1,11 @@
package io.metersphere.project.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.BatchExecTaskReportDTO;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
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.ResourcePoolOptionsDTO;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
@ -17,6 +20,7 @@ import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.BaseTaskHubLogService;
import io.metersphere.system.service.BaseTaskHubService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation;
@ -24,6 +28,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -181,4 +186,13 @@ public class ProjectTaskHubController {
public void updateValue(@PathVariable ScheduleRequest request) {
baseTaskHubService.updateCron(request);
}
@PostMapping("/exec-task/batch/page")
@Operation(summary = "项目-任务中心-用例执行任务-批量任务列表")
@RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_READ)
public Pager<List<BatchExecTaskReportDTO>> batchTaskList(@Validated @RequestBody BatchExecTaskPageRequest request) {
Page<Object> page = PageMethod.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "r.start_time desc");
return PageUtils.setPageInfo(page, baseTaskHubService.listBatchTaskReport(request));
}
}

View File

@ -1,8 +1,10 @@
package io.metersphere.project.controller;
import io.metersphere.sdk.constants.ExecTaskType;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.request.ScheduleRequest;
@ -18,6 +20,7 @@ import org.springframework.test.web.servlet.MvcResult;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProjectTaskHubControllerTests extends BaseTest {
/**
@ -40,8 +43,9 @@ public class ProjectTaskHubControllerTests extends BaseTest {
public static final String PROJECT_SCHEDULE_TASK_BATCH_ENABLE = "/project/task-center/schedule/batch-enable";
public static final String PROJECT_SCHEDULE_TASK_BATCH_DISABLE = "/project/task-center/schedule/batch-disable";
public static final String PROJECT_SCHEDULE_TASK_UPDATE_CRON = "/organization/task-center/schedule/update-cron";
public static final String PROJECT_BATCH_TASK_PAGE = "/project/task-center/exec-task/batch/page";
@Test
@Test
@Order(1)
@Sql(scripts = {"/dml/init_project_exec_task_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void getProjectTaskPage() throws Exception {
@ -166,7 +170,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
* 项目执行任务删除
*/
@Test
@Order(5)
@Order(7)
public void projectTaskDelete() throws Exception {
MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_TASK_DELETE + "4");
// 获取返回值
@ -177,7 +181,7 @@ public class ProjectTaskHubControllerTests extends BaseTest {
}
@Test
@Order(6)
@Order(8)
public void projectBatchTaskDelete() throws Exception {
TableBatchProcessDTO request = new TableBatchProcessDTO();
request.setSelectAll(false);
@ -264,4 +268,18 @@ public class ProjectTaskHubControllerTests extends BaseTest {
request.setId("pro_wx_1");
this.requestPost(PROJECT_SCHEDULE_TASK_UPDATE_CRON, request);
}
@Test
@Order(10)
public void getProjectBatchTaskPage() throws Exception {
BatchExecTaskPageRequest request = new BatchExecTaskPageRequest();
request.setBatchType(ExecTaskType.API_CASE_BATCH.name());
request.setTaskId("pro_4");
request.setCurrent(1);
request.setPageSize(10);
this.requestPostWithOk(PROJECT_BATCH_TASK_PAGE, request);
request.setSort(Map.of("startTime", "asc"));
request.setBatchType(ExecTaskType.API_SCENARIO_BATCH.name());
this.requestPostWithOk(PROJECT_BATCH_TASK_PAGE, request);
}
}

View File

@ -2,12 +2,15 @@ INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `resul
VALUES
('pro_1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639),
('pro_2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639),
('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639);
('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639),
('pro_4', 4, '测试任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API_CASE_BATCH', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639);
INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`)
VALUES
('pro_1', 'pro_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'),
('pro_2', 'pro_2', '1', '1', '1', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin');
('pro_2', 'pro_2', '1', '1', '1', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'),
('pro_4_1', 'pro_4', '1', '1', '1', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'),
('pro_4_2', 'pro_4', '1', '1', '1', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin');
INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`)
VALUES

View File

@ -1,7 +1,11 @@
package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.BatchExecTaskReportDTO;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
@ -19,6 +23,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.BaseProjectMapper;
import io.metersphere.system.service.BaseTaskHubLogService;
import io.metersphere.system.service.BaseTaskHubService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation;
@ -26,6 +31,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -196,4 +202,14 @@ public class OrganizationTaskHubController {
public void updateValue(@PathVariable ScheduleRequest request) {
baseTaskHubService.updateCron(request);
}
@PostMapping("/exec-task/batch/page")
@Operation(summary = "组织-任务中心-用例执行任务-批量任务列表")
@RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ)
public Pager<List<BatchExecTaskReportDTO>> batchTaskList(@Validated @RequestBody BatchExecTaskPageRequest request) {
Page<Object> page = PageMethod.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "r.start_time desc");
return PageUtils.setPageInfo(page, baseTaskHubService.listBatchTaskReport(request));
}
}

View File

@ -1,7 +1,11 @@
package io.metersphere.system.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import io.metersphere.sdk.constants.OperationLogConstants;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.BatchExecTaskReportDTO;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.*;
@ -15,6 +19,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.service.BaseTaskHubLogService;
import io.metersphere.system.service.BaseTaskHubService;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation;
@ -22,6 +27,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
@ -135,6 +141,15 @@ public class SystemTaskHubController {
"/system/task-center/exec-task/batch-delete", OperationLogModule.SETTING_SYSTEM_TASK_CENTER);
}
@PostMapping("/exec-task/batch/page")
@Operation(summary = "组织-任务中心-用例执行任务-批量任务列表")
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
public Pager<List<BatchExecTaskReportDTO>> batchTaskList(@Validated @RequestBody BatchExecTaskPageRequest request) {
Page<Object> page = PageMethod.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "r.start_time desc");
return PageUtils.setPageInfo(page, baseTaskHubService.listBatchTaskReport(request));
}
//TODO 系统&组织&项目 任务按钮操作失败重跑 查看报告 批量失败重跑

View File

@ -0,0 +1,30 @@
package io.metersphere.system.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author song-cc-rock
*/
@Data
public class BatchExecTaskReportDTO {
@Schema(description = "报告ID")
private String id;
@Schema(description = "报告来源 {API, SCENARIO}")
private String source;
@Schema(description = "是否是集成报告")
private Boolean integrated;
@Schema(description = "报告名称")
private String name;
@Schema(description = "报告状态")
private String status;
@Schema(description = "执行结果")
private String execResult;
@Schema(description = "触发方式")
private String triggerMode;
@Schema(description = "创建人")
private String createUser;
@Schema(description = "创建时间")
private Long createTime;
}

View File

@ -0,0 +1,17 @@
package io.metersphere.system.dto.request;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author song-cc-rock
*/
@Data
public class BatchExecTaskPageRequest extends BasePageRequest {
@Schema(description = "任务ID", requiredMode = Schema.RequiredMode.REQUIRED)
private String taskId;
@Schema(description = "批量任务类型", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"API_CASE_BATCH", "API_SCENARIO_BATCH"})
private String batchType;
}

View File

@ -2,6 +2,8 @@ package io.metersphere.system.mapper;
import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.BatchExecTaskReportDTO;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import org.apache.ibatis.annotations.Param;
@ -46,4 +48,12 @@ public interface ExtExecTaskItemMapper {
List<ExecTaskItem> getResourcePoolsByItemIds(@Param("ids") List<String> ids);
List<String> getIds(@Param("request") TableBatchProcessDTO request, @Param("organizationId") String organizationId, @Param("projectId") String projectId);
/**
* 查询批量执行任务报告
* @param request 请求参数
* @param tableName 表名
* @return 执行任务报告集合
*/
List<BatchExecTaskReportDTO> list(@Param("request") BatchExecTaskPageRequest request, @Param("tableName") String tableName);
}

View File

@ -226,4 +226,12 @@
<property name="filter" value="request.condition.filter"/>
</include>
</sql>
<select id="list" resultType="io.metersphere.system.dto.BatchExecTaskReportDTO">
select r.id, r.name, if(#{tableName} = 'api_report', 'API', 'SCENARIO') as source, false as integrated, r.status,
r.exec_status as execStatus, r.trigger_mode triggerMode, r.create_user as createUser, r.start_time as createTime
from exec_task_item eti join api_report_relate_task arrt on arrt.task_resource_id = eti.id
join ${tableName} r on arrt.report_id = r.id and r.deleted = 0
where eti.task_id = #{request.taskId}
</select>
</mapper>

View File

@ -16,12 +16,22 @@ import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.*;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.sdk.constants.ExecStatus;
import io.metersphere.sdk.constants.ExecTaskType;
import io.metersphere.sdk.constants.ResourcePoolTypeEnum;
import io.metersphere.sdk.constants.ResultStatus;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.system.domain.*;
import io.metersphere.system.dto.BatchExecTaskReportDTO;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.builder.LogDTOBuilder;
import io.metersphere.system.dto.pool.TestResourceDTO;
import io.metersphere.system.dto.pool.TestResourceNodeDTO;
import io.metersphere.system.dto.pool.TestResourcePoolReturnDTO;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
@ -838,4 +848,17 @@ public class BaseTaskHubService {
throw new RuntimeException(e);
}
}
/**
* 查询批量执行任务报告列表
* @param request 请求参数
* @return 执行任务报告集合
*/
public List<BatchExecTaskReportDTO> listBatchTaskReport(BatchExecTaskPageRequest request) {
if (StringUtils.equals(ExecTaskType.API_CASE_BATCH.name(), request.getBatchType())) {
return extExecTaskItemMapper.list(request, "api_report");
} else {
return extExecTaskItemMapper.list(request, "api_scenario_report");
}
}
}

View File

@ -1,11 +1,13 @@
package io.metersphere.system.controller;
import io.metersphere.sdk.constants.ExecTaskType;
import io.metersphere.sdk.constants.SessionConstants;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.dto.request.BatchExecTaskPageRequest;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.table.TableBatchProcessDTO;
import io.metersphere.system.dto.taskhub.request.ScheduleRequest;
@ -62,9 +64,10 @@ public class BaseTaskHubControllerTests extends BaseTest {
public static final String SYSTEM_SCHEDULE_TASK_SWITCH = "/system/task-center/schedule/switch/";
public static final String SYSTEM_SCHEDULE_TASK_BATCH_ENABLE = "/system/task-center/schedule/batch-enable";
public static final String SYSTEM_SCHEDULE_TASK_BATCH_DISABLE = "/system/task-center/schedule/batch-disable";
public static final String SYSTEM_TASK_BATCH_PAGE = "/system/task-center/exec-task/batch/page";
public static final String SYSTEM_SCHEDULE_TASK_UPDATE_CRON = "/system/task-center/schedule/update-cron";
@Test
@Test
@Order(1)
@Sql(scripts = {"/dml/init_exec_task_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
public void getSystemTaskPage() throws Exception {
@ -324,8 +327,9 @@ public class BaseTaskHubControllerTests extends BaseTest {
public static final String ORG_SCHEDULE_TASK_BATCH_ENABLE = "/organization/task-center/schedule/batch-enable";
public static final String ORG_SCHEDULE_TASK_BATCH_DISABLE = "/organization/task-center/schedule/batch-disable";
public static final String ORG_SCHEDULE_TASK_UPDATE_CRON = "/organization/task-center/schedule/update-cron";
public static final String ORG_TASK_BATCH_PAGE = "/organization/task-center/exec-task/batch/page";
@Test
@Test
@Order(20)
public void getOrgTaskPage() throws Exception {
BasePageRequest request = new BasePageRequest();
@ -391,6 +395,18 @@ public class BaseTaskHubControllerTests extends BaseTest {
Assertions.assertNotNull(resultHolder);
}
@Test
@Order(5)
public void getBatchTaskPage() throws Exception {
BatchExecTaskPageRequest request = new BatchExecTaskPageRequest();
request.setBatchType(ExecTaskType.API_CASE_BATCH.name());
request.setTaskId("task-id");
request.setCurrent(1);
request.setPageSize(10);
this.requestPostWithOk(SYSTEM_TASK_BATCH_PAGE, request);
this.requestPostWithOk(ORG_TASK_BATCH_PAGE, request);
}
/**
* 组织获取资源池下拉选项