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 = "是否是重跑任务项")
private Boolean rerun;
@Schema(description = "创建时间")
private Long createTime;
private static final long serialVersionUID = 1L;
public enum Column {
@ -117,7 +120,8 @@ public class ExecTaskItem implements Serializable {
deleted("deleted", "deleted", "BIT", false),
caseId("case_id", "caseId", "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 = "`";

View File

@ -1533,6 +1533,66 @@ public class ExecTaskItemExample {
addCriterion("rerun not between", value1, value2, "rerun");
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 {

View File

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

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_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 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})
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_test_case")
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)) {
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);
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})
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_scenario")
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)) {
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);
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<ApiScenario> getSimpleApiScenarioList(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
List<ExecHistoryDTO> selectExecHistory(@Param("request") ExecutePageRequest request);
}

View File

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

View File

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

View File

@ -617,7 +617,7 @@ public class ApiTestCaseService extends MoveNodeService {
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andTaskResourceIdIn(resourceIds);
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;
}

View File

@ -4,8 +4,8 @@ VALUES
('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
('my_1', 'my_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '1'),
('my_2', 'my_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '2');
('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', 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
('scenario_1', 'scenario_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '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'),
('scenario_3', 'scenario_3', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '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', unix_timestamp() * 1000),
('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`)

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
('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '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'),
('3', '5', '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');
('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', unix_timestamp() * 1000),
('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', unix_timestamp() * 1000);
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_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
('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_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');
('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', unix_timestamp() * 1000),
('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', unix_timestamp() * 1000);
INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`)
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);
void resetRerunTaskItem(@Param("taskId") String taskId, @Param("userId") String userId);
void deleteRerunTaskItemReportRelation(@Param("taskId") String taskId);
void insertRerunTaskItem(@Param("taskId") String taskId, @Param("userId") String userId);
Set<String> selectRerunCollectionIds(@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, resource_id
FROM exec_task_item
WHERE resource_id IN
WHERE deleted = false and resource_id IN
<foreach collection="resourceIds" item="resourceId" open="(" separator="," close=")">
#{resourceId}
</foreach>
@ -23,7 +23,7 @@
<select id="selectExecInfoByTaskIdAndResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem">
SELECT id, resource_id
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=")">
#{resourceId}
</foreach>
@ -32,7 +32,7 @@
<select id="selectExecInfoByTaskIdAndCollectionId" resultType="io.metersphere.system.domain.ExecTaskItem">
SELECT id, resource_id
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">
and rerun = true
</if>
@ -41,7 +41,7 @@
<select id="selectItemByTaskIds" resultType="io.metersphere.system.domain.ExecTaskItem">
select id, task_id, `status`, result
from exec_task_item
where task_id in
where deleted = false and task_id in
<foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
#{taskId}
</foreach>
@ -333,27 +333,21 @@
where task_id = #{taskId} and deleted = false
</select>
<update id="resetRerunTaskItem">
UPDATE exec_task_item
SET `status` = 'PENDING',
`result` = 'PENDING',
resource_pool_id = '',
resource_pool_node = null,
thread_id = null,
start_time = null,
end_time = null,
error_message = null,
executor = #{userId},
rerun = true
WHERE
deleted = false
and task_id = #{taskId}
and `result` = 'ERROR'
</update>
<insert id="insertRerunTaskItem">
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, collection_id,
deleted, case_id, error_message, rerun, create_time)
select
UUID_SHORT(), task_id, resource_id, resource_name, task_origin, 'PENDING', 'PENDING', '',
null, resource_type, project_id, organization_id, null, null, null, #{userId}, collection_id,
deleted, case_id, null, true, unix_timestamp() * 1000
from exec_task_item
where deleted = false and task_id = #{taskId} and `result` = 'ERROR'
</insert>
<delete id="deleteRerunTaskItemReportRelation">
delete arrt
from api_report_relate_task arrt join exec_task_item eti on eti.id = arrt.task_resource_id
where eti.task_id = #{taskId} and eti.`result` = 'ERROR' and eti.deleted = false
</delete>
<update id="deleteRerunTaskItem">
update exec_task_item
set deleted = true
where task_id = #{taskId} and `result` = 'ERROR' and rerun = false
</update>
</mapper>

View File

@ -198,7 +198,9 @@ public class BaseTaskHubService {
List<ExecTaskItem> taskItems = new ArrayList<>();
if (CollectionUtils.isNotEmpty(noIntegratedTasks)) {
ExecTaskItemExample itemExample = new ExecTaskItemExample();
itemExample.createCriteria().andTaskIdIn(noIntegratedTasks);
itemExample.createCriteria()
.andTaskIdIn(noIntegratedTasks)
.andDeletedEqualTo(false);
taskItems = execTaskItemMapper.selectByExample(itemExample);
}
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);
}
// 删除任务项和报告的关联关系
extExecTaskItemMapper.deleteRerunTaskItemReportRelation(execTask.getId());
// 更新任务项状态等
extExecTaskItemMapper.resetRerunTaskItem(execTask.getId(), userId);
// 新建需要重跑的任务项
extExecTaskItemMapper.insertRerunTaskItem(execTask.getId(), userId);
// 假删除原有任务项执行历史需要能查询到
extExecTaskItemMapper.deleteRerunTaskItem(execTask.getId(), userId);
}
}

View File

@ -659,6 +659,7 @@ public class BaseTaskHubControllerTests extends BaseTest {
baseTaskHubService.insertExecTaskAndDetail(new ArrayList<>(), new ArrayList<>());
execTaskItem.setId("2333");
execTaskItem.setCreateTime(System.currentTimeMillis());
ExecTask execTask = new ExecTask();
execTask.setId("121321");
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
('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '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');
('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', unix_timestamp() * 1000);
INSERT INTO `test_resource_pool` (`id`, `name`, `type`, `description`, `enable`, `create_time`, `update_time`, `create_user`, `server_url`, `all_org`, `deleted`)