feat(任务中心): 执行任务详情列表查询初版

This commit is contained in:
WangXu10 2024-10-10 11:49:43 +08:00 committed by Craftsman
parent c15a5881c2
commit 8504c5b089
13 changed files with 268 additions and 19 deletions

View File

@ -31,8 +31,6 @@ public class ExecTask implements Serializable {
private String status;
@Schema(description = "用例数量", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{exec_task.case_count.not_blank}", groups = {Created.class})
@Size(min = 1, max = 19, message = "{exec_task.case_count.length_range}", groups = {Created.class, Updated.class})
private Long caseCount;
@Schema(description = "执行结果")

View File

@ -27,6 +27,11 @@ public class ExecTaskItem implements Serializable {
@Size(min = 1, max = 50, message = "{exec_task_item.resource_id.length_range}", groups = {Created.class, Updated.class})
private String resourceId;
@Schema(description = "资源名称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{exec_task_item.resource_name.not_blank}", groups = {Created.class})
@Size(min = 1, max = 255, message = "{exec_task_item.resource_name.length_range}", groups = {Created.class, Updated.class})
private String resourceName;
@Schema(description = "任务来源任务组下的任务id")
private String taskOrigin;
@ -81,6 +86,7 @@ public class ExecTaskItem implements Serializable {
id("id", "id", "VARCHAR", false),
taskId("task_id", "taskId", "VARCHAR", false),
resourceId("resource_id", "resourceId", "VARCHAR", false),
resourceName("resource_name", "resourceName", "VARCHAR", false),
taskOrigin("task_origin", "taskOrigin", "VARCHAR", false),
status("status", "status", "VARCHAR", true),
result("result", "result", "VARCHAR", true),

View File

@ -314,6 +314,76 @@ public class ExecTaskItemExample {
return (Criteria) this;
}
public Criteria andResourceNameIsNull() {
addCriterion("resource_name is null");
return (Criteria) this;
}
public Criteria andResourceNameIsNotNull() {
addCriterion("resource_name is not null");
return (Criteria) this;
}
public Criteria andResourceNameEqualTo(String value) {
addCriterion("resource_name =", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameNotEqualTo(String value) {
addCriterion("resource_name <>", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameGreaterThan(String value) {
addCriterion("resource_name >", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameGreaterThanOrEqualTo(String value) {
addCriterion("resource_name >=", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameLessThan(String value) {
addCriterion("resource_name <", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameLessThanOrEqualTo(String value) {
addCriterion("resource_name <=", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameLike(String value) {
addCriterion("resource_name like", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameNotLike(String value) {
addCriterion("resource_name not like", value, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameIn(List<String> values) {
addCriterion("resource_name in", values, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameNotIn(List<String> values) {
addCriterion("resource_name not in", values, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameBetween(String value1, String value2) {
addCriterion("resource_name between", value1, value2, "resourceName");
return (Criteria) this;
}
public Criteria andResourceNameNotBetween(String value1, String value2) {
addCriterion("resource_name not between", value1, value2, "resourceName");
return (Criteria) this;
}
public Criteria andTaskOriginIsNull() {
addCriterion("task_origin is null");
return (Criteria) this;

View File

@ -5,6 +5,7 @@
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="task_id" jdbcType="VARCHAR" property="taskId" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="resource_name" jdbcType="VARCHAR" property="resourceName" />
<result column="task_origin" jdbcType="VARCHAR" property="taskOrigin" />
<result column="status" jdbcType="VARCHAR" property="status" />
<result column="result" jdbcType="VARCHAR" property="result" />
@ -77,8 +78,9 @@
</where>
</sql>
<sql id="Base_Column_List">
id, task_id, resource_id, task_origin, `status`, `result`, resource_pool_id, resource_pool_node,
resource_type, project_id, organization_id, thread_id, start_time, end_time, executor
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
</sql>
<select id="selectByExample" parameterType="io.metersphere.system.domain.ExecTaskItemExample" resultMap="BaseResultMap">
select
@ -112,17 +114,17 @@
</delete>
<insert id="insert" parameterType="io.metersphere.system.domain.ExecTaskItem">
insert into exec_task_item (id, task_id, resource_id,
task_origin, `status`, `result`,
resource_pool_id, resource_pool_node, resource_type,
project_id, organization_id, thread_id,
start_time, end_time, executor
)
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 (#{id,jdbcType=VARCHAR}, #{taskId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
#{taskOrigin,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{result,jdbcType=VARCHAR},
#{resourcePoolId,jdbcType=VARCHAR}, #{resourcePoolNode,jdbcType=VARCHAR}, #{resourceType,jdbcType=VARCHAR},
#{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR}, #{threadId,jdbcType=VARCHAR},
#{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT}, #{executor,jdbcType=VARCHAR}
)
#{resourceName,jdbcType=VARCHAR}, #{taskOrigin,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{result,jdbcType=VARCHAR}, #{resourcePoolId,jdbcType=VARCHAR}, #{resourcePoolNode,jdbcType=VARCHAR},
#{resourceType,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR},
#{threadId,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT},
#{executor,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.system.domain.ExecTaskItem">
insert into exec_task_item
@ -136,6 +138,9 @@
<if test="resourceId != null">
resource_id,
</if>
<if test="resourceName != null">
resource_name,
</if>
<if test="taskOrigin != null">
task_origin,
</if>
@ -183,6 +188,9 @@
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
</if>
<if test="resourceName != null">
#{resourceName,jdbcType=VARCHAR},
</if>
<if test="taskOrigin != null">
#{taskOrigin,jdbcType=VARCHAR},
</if>
@ -239,6 +247,9 @@
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
</if>
<if test="record.resourceName != null">
resource_name = #{record.resourceName,jdbcType=VARCHAR},
</if>
<if test="record.taskOrigin != null">
task_origin = #{record.taskOrigin,jdbcType=VARCHAR},
</if>
@ -285,6 +296,7 @@
set id = #{record.id,jdbcType=VARCHAR},
task_id = #{record.taskId,jdbcType=VARCHAR},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
resource_name = #{record.resourceName,jdbcType=VARCHAR},
task_origin = #{record.taskOrigin,jdbcType=VARCHAR},
`status` = #{record.status,jdbcType=VARCHAR},
`result` = #{record.result,jdbcType=VARCHAR},
@ -310,6 +322,9 @@
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="resourceName != null">
resource_name = #{resourceName,jdbcType=VARCHAR},
</if>
<if test="taskOrigin != null">
task_origin = #{taskOrigin,jdbcType=VARCHAR},
</if>
@ -353,6 +368,7 @@
update exec_task_item
set task_id = #{taskId,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
resource_name = #{resourceName,jdbcType=VARCHAR},
task_origin = #{taskOrigin,jdbcType=VARCHAR},
`status` = #{status,jdbcType=VARCHAR},
`result` = #{result,jdbcType=VARCHAR},
@ -369,14 +385,14 @@
</update>
<insert id="batchInsert" parameterType="map">
insert into exec_task_item
(id, task_id, resource_id, task_origin, `status`, `result`, resource_pool_id, resource_pool_node,
resource_type, project_id, organization_id, thread_id, start_time, end_time, executor
)
(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
<foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.taskId,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR},
#{item.taskOrigin,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR}, #{item.result,jdbcType=VARCHAR},
#{item.resourcePoolId,jdbcType=VARCHAR}, #{item.resourcePoolNode,jdbcType=VARCHAR},
#{item.resourceName,jdbcType=VARCHAR}, #{item.taskOrigin,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR},
#{item.result,jdbcType=VARCHAR}, #{item.resourcePoolId,jdbcType=VARCHAR}, #{item.resourcePoolNode,jdbcType=VARCHAR},
#{item.resourceType,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR},
#{item.threadId,jdbcType=VARCHAR}, #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT},
#{item.executor,jdbcType=VARCHAR})
@ -401,6 +417,9 @@
<if test="'resource_id'.toString() == column.value">
#{item.resourceId,jdbcType=VARCHAR}
</if>
<if test="'resource_name'.toString() == column.value">
#{item.resourceName,jdbcType=VARCHAR}
</if>
<if test="'task_origin'.toString() == column.value">
#{item.taskOrigin,jdbcType=VARCHAR}
</if>

View File

@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS exec_task_item(
`id` VARCHAR(50) NOT NULL COMMENT '主键ID' ,
`task_id` VARCHAR(50) NOT NULL COMMENT '任务ID' ,
`resource_id` VARCHAR(50) NOT NULL COMMENT '资源ID' ,
`resource_name` VARCHAR(255) NOT NULL COMMENT '资源名称' ,
`task_origin` VARCHAR(50) COMMENT '任务来源任务组下的任务id' ,
`status` VARCHAR(20) NOT NULL COMMENT '执行状态' ,
`result` VARCHAR(255) COMMENT '执行结果' ,
@ -59,6 +60,7 @@ CREATE TABLE IF NOT EXISTS exec_task_item(
CREATE INDEX idx_task_id ON exec_task_item(task_id);
CREATE INDEX idx_resource_id ON exec_task_item(resource_id);
CREATE INDEX idx_resource_name ON exec_task_item(resource_name);
CREATE INDEX idx_status ON exec_task_item(status);
CREATE INDEX idx_result ON exec_task_item(result);
CREATE INDEX idx_resource_pool_id ON exec_task_item(resource_pool_id);

View File

@ -3,7 +3,9 @@ package io.metersphere.system.controller;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.service.BaseTaskHubService;
import io.metersphere.system.utils.Pager;
import io.swagger.v3.oas.annotations.Operation;
@ -41,4 +43,11 @@ public class SystemTaskHubController {
return baseTaskHubService.getScheduleTaskList(request, null);
}
@PostMapping("/exec-task/item/page")
@Operation(summary = "系统-任务中心-用例执行任务详情列表")
@RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ)
public Pager<List<TaskHubItemDTO>> itemPageList(@Validated @RequestBody TaskHubItemRequest request) {
return baseTaskHubService.getCaseTaskItemList(request, null, null);
}
}

View File

@ -0,0 +1,32 @@
package io.metersphere.system.dto.taskhub;
import io.metersphere.system.domain.ExecTaskItem;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author wx
*/
@Data
public class TaskHubItemDTO extends ExecTaskItem {
@Schema(description = "任务名称")
private String taskName;
@Schema(description = "操作人名称")
private String userName;
@Schema(description = "资源池名称")
private String resourcePoolName;
@Schema(description = "执行方式")
private String triggerMode;
@Schema(description = "排队数")
private int lineNum;
@Schema(description = "线程id")
private String threadId;
}

View File

@ -0,0 +1,24 @@
package io.metersphere.system.dto.taskhub.request;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
public class TaskHubItemRequest extends BasePageRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "任务id")
private String taskId;
@Schema(description = "资源池id")
private String resourcePoolId;
}

View File

@ -0,0 +1,16 @@
package io.metersphere.system.mapper;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author wx
*/
public interface ExtExecTaskItemMapper {
List<TaskHubItemDTO> selectList(@Param("request") TaskHubItemRequest request, @Param("orgId") String orgId, @Param("projectId") String projectId);
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!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">
<select id="selectList" resultType="io.metersphere.system.dto.taskhub.TaskHubItemDTO">
SELECT *
FROM exec_task_item
<where>
<if test="request.keyword != null and request.keyword != ''">
and (
exec_task_item.task_id like concat('%', #{request.keyword},'%')
or exec_task_item.resource_name like concat('%', #{request.keyword},'%')
)
</if>
<if test="orgId != null">
and exec_task_item.organization_id = #{orgId}
</if>
<if test="projectId != null">
and exec_task_item.project_id = #{projectId}
</if>
</where>
</select>
</mapper>

View File

@ -8,7 +8,9 @@ import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.metersphere.system.dto.taskhub.TaskHubDTO;
import io.metersphere.system.dto.taskhub.TaskHubItemDTO;
import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.mapper.*;
import io.metersphere.system.utils.PageUtils;
import io.metersphere.system.utils.Pager;
@ -46,6 +48,8 @@ public class BaseTaskHubService {
UserLoginService userLoginService;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Resource
private ExtExecTaskItemMapper extExecTaskItemMapper;
/**
* 系统-获取执行任务列表
@ -153,4 +157,21 @@ public class BaseTaskHubService {
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
/**
* 用例任务详情列表查询
*
* @param request
* @return
*/
public Pager<List<TaskHubItemDTO>> getCaseTaskItemList(TaskHubItemRequest request, String orgId, String projectId) {
Page<Object> page = PageMethod.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "id asc");
return PageUtils.setPageInfo(page, getCaseTaskItemPage(request, orgId, projectId));
}
private List<TaskHubItemDTO> getCaseTaskItemPage(TaskHubItemRequest request, String orgId, String projectId) {
return extExecTaskItemMapper.selectList(request, orgId, projectId);
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.dto.sdk.BasePageRequest;
import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest;
import io.metersphere.system.service.BaseTaskHubService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.*;
@ -32,6 +33,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
*/
public static final String SYSTEM_TASK_PAGE = "/system/task-center/exec-task/page";
public static final String SYSTEM_SCHEDULE_TASK_PAGE = "/system/task-center/schedule/page";
public static final String SYSTEM_TASK_ITEM_PAGE = "/system/task-center/exec-task/item/page";
@Test
@Order(1)
@ -69,6 +71,26 @@ public class BaseTaskHubControllerTests extends BaseTest {
}
/**
* 系统后台任务
*/
@Test
@Order(3)
public void getSystemTaskItemPage() throws Exception {
TaskHubItemRequest request = new TaskHubItemRequest();
request.setTaskId("1");
this.requestPost(SYSTEM_TASK_ITEM_PAGE, request);
request.setCurrent(1);
request.setPageSize(10);
MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_ITEM_PAGE, request);
// 获取返回值
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(resultHolder);
}
/**
* 组织任务中心测试用例
*/
@ -124,6 +146,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
execTaskItem.setProjectId("1234");
execTaskItem.setOrganizationId("1234123");
execTaskItem.setExecutor("admin");
execTaskItem.setResourceName("测试");
baseTaskHubService.insertExecTaskAndDetail(List.of(execTaskItem));

View File

@ -14,3 +14,8 @@ VALUES
('wx_3', 'wx_key_3', 'cron', '50 15 10 20 05 ?', 'JobClass22', 'DEMAND_SYNC', b'1', 'NONE', 'admin', 1640778100000, 1640779100000, '100001100001', 'Schedule 22', '', 102),
('wx_4', 'wx_key_4', 'cron', '59 46 16 01 06 ?', 'JobClass29', 'API_SCENARIO', b'1', 'NONE', 'admin', 1640778800000, 1640779800000, '100001100001', 'Schedule 29', '{\"param1\": \"value1\", \"param2\": \"value2\"}', 103),
('wx_5', 'wx_key_5', 'cron', '59 46 16 01 06 ?', 'JobClass29', 'TEST_PLAN', b'1', 'NONE', 'admin', 1640778800000, 1640779800000, '100001100001', 'Schedule 29', '{\"param1\": \"value1\", \"param2\": \"value2\"}', 104);
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 ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '1', '1', '1', NULL, NULL, 'admin');