fix(接口测试): 任务失败重跑,新增一条执行记录

--bug=1048956 --user=陈建星 【任务中心】-失败重跑没有在CASE、场景的执行历史中新增执行记录,而是更改原执行记录 https://www.tapd.cn/55049933/s/1614487
This commit is contained in:
AgAngle 2024-11-21 16:24:04 +08:00 committed by Craftsman
parent 0e730c9bd6
commit 05bbd1cf80
21 changed files with 160 additions and 72 deletions

View File

@ -94,6 +94,9 @@ public class ExecTaskItem implements Serializable {
@Schema(description = "是否是重跑任务项") @Schema(description = "是否是重跑任务项")
private Boolean rerun; private Boolean rerun;
@Schema(description = "创建时间")
private Long createTime;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public enum Column { public enum Column {
@ -117,7 +120,8 @@ public class ExecTaskItem implements Serializable {
deleted("deleted", "deleted", "BIT", false), deleted("deleted", "deleted", "BIT", false),
caseId("case_id", "caseId", "VARCHAR", false), caseId("case_id", "caseId", "VARCHAR", false),
errorMessage("error_message", "errorMessage", "VARCHAR", false), errorMessage("error_message", "errorMessage", "VARCHAR", false),
rerun("rerun", "rerun", "BIT", false); rerun("rerun", "rerun", "BIT", false),
createTime("create_time", "createTime", "BIGINT", false);
private static final String BEGINNING_DELIMITER = "`"; private static final String BEGINNING_DELIMITER = "`";

View File

@ -1533,6 +1533,66 @@ public class ExecTaskItemExample {
addCriterion("rerun not between", value1, value2, "rerun"); addCriterion("rerun not between", value1, value2, "rerun");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Long value) {
addCriterion("create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Long value) {
addCriterion("create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Long value) {
addCriterion("create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Long value) {
addCriterion("create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
addCriterion("create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> values) {
addCriterion("create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Long value1, Long value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {

View File

@ -23,6 +23,7 @@
<result column="case_id" jdbcType="VARCHAR" property="caseId" /> <result column="case_id" jdbcType="VARCHAR" property="caseId" />
<result column="error_message" jdbcType="VARCHAR" property="errorMessage" /> <result column="error_message" jdbcType="VARCHAR" property="errorMessage" />
<result column="rerun" jdbcType="BIT" property="rerun" /> <result column="rerun" jdbcType="BIT" property="rerun" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -85,7 +86,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, task_id, resource_id, resource_name, task_origin, `status`, `result`, resource_pool_id, 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, resource_pool_node, resource_type, project_id, organization_id, thread_id, start_time,
end_time, executor, collection_id, deleted, case_id, error_message, rerun end_time, executor, collection_id, deleted, case_id, error_message, rerun, create_time
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.system.domain.ExecTaskItemExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.system.domain.ExecTaskItemExample" resultMap="BaseResultMap">
select select
@ -124,16 +125,16 @@
resource_type, project_id, organization_id, resource_type, project_id, organization_id,
thread_id, start_time, end_time, thread_id, start_time, end_time,
executor, collection_id, deleted, executor, collection_id, deleted,
case_id, error_message, rerun case_id, error_message, rerun,
) create_time)
values (#{id,jdbcType=VARCHAR}, #{taskId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{taskId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR},
#{resourceName,jdbcType=VARCHAR}, #{taskOrigin,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{resourceName,jdbcType=VARCHAR}, #{taskOrigin,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},
#{result,jdbcType=VARCHAR}, #{resourcePoolId,jdbcType=VARCHAR}, #{resourcePoolNode,jdbcType=VARCHAR}, #{result,jdbcType=VARCHAR}, #{resourcePoolId,jdbcType=VARCHAR}, #{resourcePoolNode,jdbcType=VARCHAR},
#{resourceType,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR}, #{resourceType,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR},
#{threadId,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT}, #{threadId,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT},
#{executor,jdbcType=VARCHAR}, #{collectionId,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT}, #{executor,jdbcType=VARCHAR}, #{collectionId,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT},
#{caseId,jdbcType=VARCHAR}, #{errorMessage,jdbcType=VARCHAR}, #{rerun,jdbcType=BIT} #{caseId,jdbcType=VARCHAR}, #{errorMessage,jdbcType=VARCHAR}, #{rerun,jdbcType=BIT},
) #{createTime,jdbcType=BIGINT})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.system.domain.ExecTaskItem"> <insert id="insertSelective" parameterType="io.metersphere.system.domain.ExecTaskItem">
insert into exec_task_item insert into exec_task_item
@ -201,6 +202,9 @@
<if test="rerun != null"> <if test="rerun != null">
rerun, rerun,
</if> </if>
<if test="createTime != null">
create_time,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -266,6 +270,9 @@
<if test="rerun != null"> <if test="rerun != null">
#{rerun,jdbcType=BIT}, #{rerun,jdbcType=BIT},
</if> </if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.system.domain.ExecTaskItemExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.metersphere.system.domain.ExecTaskItemExample" resultType="java.lang.Long">
@ -340,6 +347,9 @@
<if test="record.rerun != null"> <if test="record.rerun != null">
rerun = #{record.rerun,jdbcType=BIT}, rerun = #{record.rerun,jdbcType=BIT},
</if> </if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
@ -367,7 +377,8 @@
deleted = #{record.deleted,jdbcType=BIT}, deleted = #{record.deleted,jdbcType=BIT},
case_id = #{record.caseId,jdbcType=VARCHAR}, case_id = #{record.caseId,jdbcType=VARCHAR},
error_message = #{record.errorMessage,jdbcType=VARCHAR}, error_message = #{record.errorMessage,jdbcType=VARCHAR},
rerun = #{record.rerun,jdbcType=BIT} rerun = #{record.rerun,jdbcType=BIT},
create_time = #{record.createTime,jdbcType=BIGINT}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -435,6 +446,9 @@
<if test="rerun != null"> <if test="rerun != null">
rerun = #{rerun,jdbcType=BIT}, rerun = #{rerun,jdbcType=BIT},
</if> </if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
@ -459,14 +473,16 @@
deleted = #{deleted,jdbcType=BIT}, deleted = #{deleted,jdbcType=BIT},
case_id = #{caseId,jdbcType=VARCHAR}, case_id = #{caseId,jdbcType=VARCHAR},
error_message = #{errorMessage,jdbcType=VARCHAR}, error_message = #{errorMessage,jdbcType=VARCHAR},
rerun = #{rerun,jdbcType=BIT} rerun = #{rerun,jdbcType=BIT},
create_time = #{createTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<insert id="batchInsert" parameterType="map"> <insert id="batchInsert" parameterType="map">
insert into exec_task_item insert into exec_task_item
(id, task_id, resource_id, resource_name, task_origin, `status`, `result`, resource_pool_id, (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, resource_pool_node, resource_type, project_id, organization_id, thread_id, start_time,
end_time, executor, collection_id, deleted, case_id, error_message, rerun) end_time, executor, collection_id, deleted, case_id, error_message, rerun, create_time
)
values values
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.taskId,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR}, (#{item.id,jdbcType=VARCHAR}, #{item.taskId,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR},
@ -475,8 +491,8 @@
#{item.resourceType,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,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.threadId,jdbcType=VARCHAR}, #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT},
#{item.executor,jdbcType=VARCHAR}, #{item.collectionId,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}, #{item.executor,jdbcType=VARCHAR}, #{item.collectionId,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT},
#{item.caseId,jdbcType=VARCHAR}, #{item.errorMessage,jdbcType=VARCHAR}, #{item.rerun,jdbcType=BIT} #{item.caseId,jdbcType=VARCHAR}, #{item.errorMessage,jdbcType=VARCHAR}, #{item.rerun,jdbcType=BIT},
) #{item.createTime,jdbcType=BIGINT})
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertSelective" parameterType="map"> <insert id="batchInsertSelective" parameterType="map">
@ -552,6 +568,9 @@
<if test="'rerun'.toString() == column.value"> <if test="'rerun'.toString() == column.value">
#{item.rerun,jdbcType=BIT} #{item.rerun,jdbcType=BIT}
</if> </if>
<if test="'create_time'.toString() == column.value">
#{item.createTime,jdbcType=BIGINT}
</if>
</foreach> </foreach>
) )
</foreach> </foreach>

View File

@ -85,6 +85,8 @@ ALTER TABLE exec_task_item ADD collection_id varchar(50) NULL COMMENT '测试集
ALTER TABLE exec_task_item ADD error_message varchar(50) NULL COMMENT '异常信息'; ALTER TABLE exec_task_item ADD error_message varchar(50) NULL COMMENT '异常信息';
-- 任务项添加重跑字段 -- 任务项添加重跑字段
ALTER TABLE exec_task_item ADD rerun bit(1) DEFAULT 0 NULL COMMENT '是否是重跑任务项'; ALTER TABLE exec_task_item ADD rerun bit(1) DEFAULT 0 NULL COMMENT '是否是重跑任务项';
-- 任务项添加创建时间字段
ALTER TABLE exec_task_item ADD create_time bigint NOT NULL COMMENT '创建时间';
-- 任务添加串并行字段 -- 任务添加串并行字段
ALTER TABLE exec_task ADD parallel bit(1) DEFAULT 1 NOT NULL COMMENT '是否是并行执行'; ALTER TABLE exec_task ADD parallel bit(1) DEFAULT 1 NOT NULL COMMENT '是否是并行执行';

View File

@ -8,5 +8,10 @@ UPDATE test_plan_api_scenario SET last_exec_result = '' WHERE last_exec_result i
UPDATE api_test_case SET last_report_status = '' WHERE last_report_status = 'PENDING' OR last_report_status = '-'; UPDATE api_test_case SET last_report_status = '' WHERE last_report_status = 'PENDING' OR last_report_status = '-';
UPDATE api_scenario SET last_report_status = '' WHERE last_report_status = 'PENDING' OR last_report_status = '-'; UPDATE api_scenario SET last_report_status = '' WHERE last_report_status = 'PENDING' OR last_report_status = '-';
-- 初始化任务项创建时间字段
update exec_task_item
join exec_task on exec_task_item.task_id = exec_task.id
set exec_task_item.create_time = exec_task.create_time;
-- set innodb lock wait timeout to default -- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT; SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -248,9 +248,9 @@ public class ApiTestCaseController {
@RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE}) @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_DEFINITION_CASE_READ, PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE})
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_test_case") @CheckOwner(resourceId = "#request.getId()", resourceType = "api_test_case")
public Pager<List<ExecuteReportDTO>> getExecuteList(@Validated @RequestBody ExecutePageRequest request) { public Pager<List<ExecuteReportDTO>> getExecuteList(@Validated @RequestBody ExecutePageRequest request) {
String sort = StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "eti.id desc"; String sort = StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "eti.create_time desc";
if (StringUtils.isNotBlank(sort)) { if (StringUtils.isNotBlank(sort)) {
sort = sort.replace("start_time", "et.create_time"); sort = sort.replace("start_time", "eti.create_time");
} }
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort); Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort);
return PageUtils.setPageInfo(page, apiTestCaseService.getExecuteList(request)); return PageUtils.setPageInfo(page, apiTestCaseService.getExecuteList(request));

View File

@ -271,9 +271,9 @@ public class ApiScenarioController {
@RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_SCENARIO_READ, PermissionConstants.PROJECT_API_SCENARIO_UPDATE}) @RequiresPermissions(logical = Logical.OR, value = {PermissionConstants.PROJECT_API_SCENARIO_READ, PermissionConstants.PROJECT_API_SCENARIO_UPDATE})
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_scenario") @CheckOwner(resourceId = "#request.getId()", resourceType = "api_scenario")
public Pager<List<ExecuteReportDTO>> getExecuteList(@Validated @RequestBody ExecutePageRequest request) { public Pager<List<ExecuteReportDTO>> getExecuteList(@Validated @RequestBody ExecutePageRequest request) {
String sort = StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "eti.id desc"; String sort = StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "eti.create_time desc";
if (StringUtils.isNotBlank(sort)) { if (StringUtils.isNotBlank(sort)) {
sort = sort.replace("start_time", "et.create_time"); sort = sort.replace("start_time", "eti.create_time");
} }
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort); Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort);
return PageUtils.setPageInfo(page, apiScenarioService.getExecuteList(request)); return PageUtils.setPageInfo(page, apiScenarioService.getExecuteList(request));

View File

@ -107,5 +107,6 @@ public interface ExtApiScenarioMapper {
List<ProjectUserCreateCount> userCreateApiScenarioCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("userIds") Set<String> userIds); List<ProjectUserCreateCount> userCreateApiScenarioCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("userIds") Set<String> userIds);
List<ApiScenario> getSimpleApiScenarioList(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); List<ApiScenario> getSimpleApiScenarioList(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
List<ExecHistoryDTO> selectExecHistory(@Param("request") ExecutePageRequest request); List<ExecHistoryDTO> selectExecHistory(@Param("request") ExecutePageRequest request);
} }

View File

@ -821,7 +821,7 @@
eti.`status` as execStatus, eti.`status` as execStatus,
eti.executor as createUser, eti.executor as createUser,
eti.deleted, eti.deleted,
et.create_time as startTime, eti.create_time as startTime,
et.integrated, et.integrated,
tp.id as testPlanId, tp.id as testPlanId,
tp.num as testPlanNum, tp.num as testPlanNum,

View File

@ -513,6 +513,7 @@ public class ApiCommonService {
public ExecTaskItem newExecTaskItem(String taskId, String projectId, String userId) { public ExecTaskItem newExecTaskItem(String taskId, String projectId, String userId) {
ExecTaskItem execTaskItem = new ExecTaskItem(); ExecTaskItem execTaskItem = new ExecTaskItem();
execTaskItem.setCreateTime(System.currentTimeMillis());
execTaskItem.setId(IDGenerator.nextStr()); execTaskItem.setId(IDGenerator.nextStr());
execTaskItem.setTaskId(taskId); execTaskItem.setTaskId(taskId);
execTaskItem.setProjectId(projectId); execTaskItem.setProjectId(projectId);

View File

@ -617,7 +617,7 @@ public class ApiTestCaseService extends MoveNodeService {
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andTaskResourceIdIn(resourceIds); example.createCriteria().andTaskResourceIdIn(resourceIds);
List<ApiReportRelateTask> reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); List<ApiReportRelateTask> reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example);
reportMap = reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId)); reportRelateTasks.stream().forEach(item -> reportMap.put(item.getTaskResourceId(), item.getReportId()));
} }
return reportMap; return reportMap;
} }

View File

@ -4,8 +4,8 @@ VALUES
('my_2', 2222, '测试2', 'SUCCESS', 11, 'SUCCESS', 'API_SCENARIO', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, 0); ('my_2', 2222, '测试2', 'SUCCESS', 11, 'SUCCESS', 'API_SCENARIO', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, 0);
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`, `case_id`) 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`, `case_id`, `create_time`)
VALUES VALUES
('my_1', 'my_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '1'), ('my_1', 'my_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '1', unix_timestamp() * 1000),
('my_2', 'my_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '2'); ('my_2', 'my_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '2', unix_timestamp() * 1000);

View File

@ -6,11 +6,11 @@ VALUES
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`) 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`, `create_time`)
VALUES VALUES
('scenario_1', 'scenario_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('scenario_1', 'scenario_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('scenario_2', 'scenario_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('scenario_2', 'scenario_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('scenario_3', 'scenario_3', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); ('scenario_3', 'scenario_3', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000);
INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`)

View File

@ -9,12 +9,12 @@ VALUES
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`) 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`, `create_time`)
VALUES VALUES
('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('3', '5', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('3', '5', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('4', '6', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); ('4', '6', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000);
INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) VALUES ('1', 'test-report-id'), ('6', 'test-report-id'); INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) VALUES ('1', 'test-report-id'), ('6', 'test-report-id');

View File

@ -5,12 +5,12 @@ VALUES
('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), ('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'),
('pro_4', 4, '测试任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API_CASE_BATCH', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'1'); ('pro_4', 4, '测试任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API_CASE_BATCH', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'1');
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`) 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`, `create_time`)
VALUES VALUES
('pro_1', 'pro_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('pro_1', 'pro_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('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', unix_timestamp() * 1000),
('pro_4_1', 'pro_4', '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', unix_timestamp() * 1000),
('pro_4_2', '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', unix_timestamp() * 1000);
INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`) INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`)
VALUES VALUES

View File

@ -66,11 +66,11 @@ public interface ExtExecTaskItemMapper {
long getUnDeleteScenarioExecCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("resourceTypes") List<String> resourceTypes); long getUnDeleteScenarioExecCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("resourceTypes") List<String> resourceTypes);
void resetRerunTaskItem(@Param("taskId") String taskId, @Param("userId") String userId); void insertRerunTaskItem(@Param("taskId") String taskId, @Param("userId") String userId);
void deleteRerunTaskItemReportRelation(@Param("taskId") String taskId);
Set<String> selectRerunCollectionIds(@Param("taskId") String taskId); Set<String> selectRerunCollectionIds(@Param("taskId") String taskId);
List<ExecTaskItem> selectIdAndResourceIdByTaskId(@Param("taskId") String taskId); List<ExecTaskItem> selectIdAndResourceIdByTaskId(@Param("taskId") String taskId);
void deleteRerunTaskItem(@Param("taskId") String taskId, String userId);
} }

View File

@ -10,7 +10,7 @@
<select id="selectExecInfoByResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem"> <select id="selectExecInfoByResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem">
SELECT id, resource_id SELECT id, resource_id
FROM exec_task_item FROM exec_task_item
WHERE resource_id IN WHERE deleted = false and resource_id IN
<foreach collection="resourceIds" item="resourceId" open="(" separator="," close=")"> <foreach collection="resourceIds" item="resourceId" open="(" separator="," close=")">
#{resourceId} #{resourceId}
</foreach> </foreach>
@ -23,7 +23,7 @@
<select id="selectExecInfoByTaskIdAndResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem"> <select id="selectExecInfoByTaskIdAndResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem">
SELECT id, resource_id SELECT id, resource_id
FROM exec_task_item FROM exec_task_item
WHERE task_id = #{taskId} and resource_id IN WHERE deleted = false and task_id = #{taskId} and resource_id IN
<foreach collection="resourceIds" item="resourceId" open="(" separator="," close=")"> <foreach collection="resourceIds" item="resourceId" open="(" separator="," close=")">
#{resourceId} #{resourceId}
</foreach> </foreach>
@ -32,7 +32,7 @@
<select id="selectExecInfoByTaskIdAndCollectionId" resultType="io.metersphere.system.domain.ExecTaskItem"> <select id="selectExecInfoByTaskIdAndCollectionId" resultType="io.metersphere.system.domain.ExecTaskItem">
SELECT id, resource_id SELECT id, resource_id
FROM exec_task_item FROM exec_task_item
WHERE task_id = #{taskId} and collection_id = #{collectionId} WHERE task_id = #{taskId} and collection_id = #{collectionId} and deleted = false
<if test="rerun != null and rerun == true"> <if test="rerun != null and rerun == true">
and rerun = true and rerun = true
</if> </if>
@ -41,7 +41,7 @@
<select id="selectItemByTaskIds" resultType="io.metersphere.system.domain.ExecTaskItem"> <select id="selectItemByTaskIds" resultType="io.metersphere.system.domain.ExecTaskItem">
select id, task_id, `status`, result select id, task_id, `status`, result
from exec_task_item from exec_task_item
where task_id in where deleted = false and task_id in
<foreach collection="taskIds" item="taskId" open="(" separator="," close=")"> <foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
#{taskId} #{taskId}
</foreach> </foreach>
@ -333,27 +333,21 @@
where task_id = #{taskId} and deleted = false where task_id = #{taskId} and deleted = false
</select> </select>
<update id="resetRerunTaskItem"> <insert id="insertRerunTaskItem">
UPDATE exec_task_item insert into exec_task_item(id, task_id, resource_id, resource_name, task_origin, status, `result`, resource_pool_id,
SET `status` = 'PENDING', resource_pool_node, resource_type, project_id, organization_id, thread_id, start_time, end_time, executor, collection_id,
`result` = 'PENDING', deleted, case_id, error_message, rerun, create_time)
resource_pool_id = '', select
resource_pool_node = null, UUID_SHORT(), task_id, resource_id, resource_name, task_origin, 'PENDING', 'PENDING', '',
thread_id = null, null, resource_type, project_id, organization_id, null, null, null, #{userId}, collection_id,
start_time = null, deleted, case_id, null, true, unix_timestamp() * 1000
end_time = null, from exec_task_item
error_message = null, where deleted = false and task_id = #{taskId} and `result` = 'ERROR'
executor = #{userId}, </insert>
rerun = true
WHERE
deleted = false
and task_id = #{taskId}
and `result` = 'ERROR'
</update>
<delete id="deleteRerunTaskItemReportRelation"> <update id="deleteRerunTaskItem">
delete arrt update exec_task_item
from api_report_relate_task arrt join exec_task_item eti on eti.id = arrt.task_resource_id set deleted = true
where eti.task_id = #{taskId} and eti.`result` = 'ERROR' and eti.deleted = false where task_id = #{taskId} and `result` = 'ERROR' and rerun = false
</delete> </update>
</mapper> </mapper>

View File

@ -198,7 +198,9 @@ public class BaseTaskHubService {
List<ExecTaskItem> taskItems = new ArrayList<>(); List<ExecTaskItem> taskItems = new ArrayList<>();
if (CollectionUtils.isNotEmpty(noIntegratedTasks)) { if (CollectionUtils.isNotEmpty(noIntegratedTasks)) {
ExecTaskItemExample itemExample = new ExecTaskItemExample(); ExecTaskItemExample itemExample = new ExecTaskItemExample();
itemExample.createCriteria().andTaskIdIn(noIntegratedTasks); itemExample.createCriteria()
.andTaskIdIn(noIntegratedTasks)
.andDeletedEqualTo(false);
taskItems = execTaskItemMapper.selectByExample(itemExample); taskItems = execTaskItemMapper.selectByExample(itemExample);
} }
Map<String, String> taskItemMap = taskItems.stream().collect(Collectors.toMap(ExecTaskItem::getTaskId, ExecTaskItem::getId)); Map<String, String> taskItemMap = taskItems.stream().collect(Collectors.toMap(ExecTaskItem::getTaskId, ExecTaskItem::getId));

View File

@ -45,10 +45,9 @@ public class ExecTaskService {
apiReportRelateTaskMapper.deleteByExample(example); apiReportRelateTaskMapper.deleteByExample(example);
} }
// 删除任务项和报告的关联关系 // 新建需要重跑的任务项
extExecTaskItemMapper.deleteRerunTaskItemReportRelation(execTask.getId()); extExecTaskItemMapper.insertRerunTaskItem(execTask.getId(), userId);
// 假删除原有任务项执行历史需要能查询到
// 更新任务项状态等 extExecTaskItemMapper.deleteRerunTaskItem(execTask.getId(), userId);
extExecTaskItemMapper.resetRerunTaskItem(execTask.getId(), userId);
} }
} }

View File

@ -659,6 +659,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
baseTaskHubService.insertExecTaskAndDetail(new ArrayList<>(), new ArrayList<>()); baseTaskHubService.insertExecTaskAndDetail(new ArrayList<>(), new ArrayList<>());
execTaskItem.setId("2333"); execTaskItem.setId("2333");
execTaskItem.setCreateTime(System.currentTimeMillis());
ExecTask execTask = new ExecTask(); ExecTask execTask = new ExecTask();
execTask.setId("121321"); execTask.setId("121321");
execTask.setNum(123L); execTask.setNum(123L);

View File

@ -18,10 +18,10 @@ VALUES
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`) 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`, `create_time`)
VALUES VALUES
('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000),
('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); ('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin', unix_timestamp() * 1000);
INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`) INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`)