refactor(任务中心): 改造任务中心与执行历史结合

This commit is contained in:
WangXu10 2024-11-11 18:40:40 +08:00 committed by Craftsman
parent 822bb5b664
commit e40dba8fbe
15 changed files with 403 additions and 175 deletions

View File

@ -76,6 +76,10 @@ public class ExecTask implements Serializable {
@NotNull(message = "{exec_task.integrated.not_blank}", groups = {Created.class}) @NotNull(message = "{exec_task.integrated.not_blank}", groups = {Created.class})
private Boolean integrated; private Boolean integrated;
@Schema(description = "删除标识", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "{exec_task.deleted.not_blank}", groups = {Created.class})
private Boolean deleted;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public enum Column { public enum Column {
@ -94,7 +98,8 @@ public class ExecTask implements Serializable {
createUser("create_user", "createUser", "VARCHAR", false), createUser("create_user", "createUser", "VARCHAR", false),
startTime("start_time", "startTime", "BIGINT", false), startTime("start_time", "startTime", "BIGINT", false),
endTime("end_time", "endTime", "BIGINT", false), endTime("end_time", "endTime", "BIGINT", false),
integrated("integrated", "integrated", "BIT", false); integrated("integrated", "integrated", "BIT", false),
deleted("deleted", "deleted", "BIT", false);
private static final String BEGINNING_DELIMITER = "`"; private static final String BEGINNING_DELIMITER = "`";

View File

@ -574,76 +574,6 @@ public class ExecTaskExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andResourceIdIsNull() {
addCriterion("resource_id is null");
return (Criteria) this;
}
public Criteria andResourceIdIsNotNull() {
addCriterion("resource_id is not null");
return (Criteria) this;
}
public Criteria andResourceIdEqualTo(String value) {
addCriterion("resource_id =", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotEqualTo(String value) {
addCriterion("resource_id <>", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThan(String value) {
addCriterion("resource_id >", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThanOrEqualTo(String value) {
addCriterion("resource_id >=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThan(String value) {
addCriterion("resource_id <", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThanOrEqualTo(String value) {
addCriterion("resource_id <=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLike(String value) {
addCriterion("resource_id like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotLike(String value) {
addCriterion("resource_id not like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdIn(List<String> values) {
addCriterion("resource_id in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotIn(List<String> values) {
addCriterion("resource_id not in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdBetween(String value1, String value2) {
addCriterion("resource_id between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotBetween(String value1, String value2) {
addCriterion("resource_id not between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andTriggerModeIsNull() { public Criteria andTriggerModeIsNull() {
addCriterion("trigger_mode is null"); addCriterion("trigger_mode is null");
return (Criteria) this; return (Criteria) this;
@ -1163,6 +1093,136 @@ public class ExecTaskExample {
addCriterion("integrated not between", value1, value2, "integrated"); addCriterion("integrated not between", value1, value2, "integrated");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andResourceIdIsNull() {
addCriterion("resource_id is null");
return (Criteria) this;
}
public Criteria andResourceIdIsNotNull() {
addCriterion("resource_id is not null");
return (Criteria) this;
}
public Criteria andResourceIdEqualTo(String value) {
addCriterion("resource_id =", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotEqualTo(String value) {
addCriterion("resource_id <>", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThan(String value) {
addCriterion("resource_id >", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdGreaterThanOrEqualTo(String value) {
addCriterion("resource_id >=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThan(String value) {
addCriterion("resource_id <", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLessThanOrEqualTo(String value) {
addCriterion("resource_id <=", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdLike(String value) {
addCriterion("resource_id like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotLike(String value) {
addCriterion("resource_id not like", value, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdIn(List<String> values) {
addCriterion("resource_id in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotIn(List<String> values) {
addCriterion("resource_id not in", values, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdBetween(String value1, String value2) {
addCriterion("resource_id between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andResourceIdNotBetween(String value1, String value2) {
addCriterion("resource_id not between", value1, value2, "resourceId");
return (Criteria) this;
}
public Criteria andDeletedIsNull() {
addCriterion("deleted is null");
return (Criteria) this;
}
public Criteria andDeletedIsNotNull() {
addCriterion("deleted is not null");
return (Criteria) this;
}
public Criteria andDeletedEqualTo(Boolean value) {
addCriterion("deleted =", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotEqualTo(Boolean value) {
addCriterion("deleted <>", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedGreaterThan(Boolean value) {
addCriterion("deleted >", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedGreaterThanOrEqualTo(Boolean value) {
addCriterion("deleted >=", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedLessThan(Boolean value) {
addCriterion("deleted <", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedLessThanOrEqualTo(Boolean value) {
addCriterion("deleted <=", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedIn(List<Boolean> values) {
addCriterion("deleted in", values, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotIn(List<Boolean> values) {
addCriterion("deleted not in", values, "deleted");
return (Criteria) this;
}
public Criteria andDeletedBetween(Boolean value1, Boolean value2) {
addCriterion("deleted between", value1, value2, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotBetween(Boolean value1, Boolean value2) {
addCriterion("deleted not between", value1, value2, "deleted");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {

View File

@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -80,6 +81,10 @@ public class ExecTaskItem implements Serializable {
@Size(min = 1, max = 50, message = "{exec_task_item.executor.length_range}", groups = {Created.class, Updated.class}) @Size(min = 1, max = 50, message = "{exec_task_item.executor.length_range}", groups = {Created.class, Updated.class})
private String executor; private String executor;
@Schema(description = "删除标识", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "{exec_task_item.deleted.not_blank}", groups = {Created.class})
private Boolean deleted;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public enum Column { public enum Column {
@ -98,7 +103,8 @@ public class ExecTaskItem implements Serializable {
threadId("thread_id", "threadId", "VARCHAR", false), threadId("thread_id", "threadId", "VARCHAR", false),
startTime("start_time", "startTime", "BIGINT", false), startTime("start_time", "startTime", "BIGINT", false),
endTime("end_time", "endTime", "BIGINT", false), endTime("end_time", "endTime", "BIGINT", false),
executor("executor", "executor", "VARCHAR", false); executor("executor", "executor", "VARCHAR", false),
deleted("deleted", "deleted", "BIT", false);
private static final String BEGINNING_DELIMITER = "`"; private static final String BEGINNING_DELIMITER = "`";

View File

@ -1203,6 +1203,66 @@ public class ExecTaskItemExample {
addCriterion("executor not between", value1, value2, "executor"); addCriterion("executor not between", value1, value2, "executor");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andDeletedIsNull() {
addCriterion("deleted is null");
return (Criteria) this;
}
public Criteria andDeletedIsNotNull() {
addCriterion("deleted is not null");
return (Criteria) this;
}
public Criteria andDeletedEqualTo(Boolean value) {
addCriterion("deleted =", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotEqualTo(Boolean value) {
addCriterion("deleted <>", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedGreaterThan(Boolean value) {
addCriterion("deleted >", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedGreaterThanOrEqualTo(Boolean value) {
addCriterion("deleted >=", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedLessThan(Boolean value) {
addCriterion("deleted <", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedLessThanOrEqualTo(Boolean value) {
addCriterion("deleted <=", value, "deleted");
return (Criteria) this;
}
public Criteria andDeletedIn(List<Boolean> values) {
addCriterion("deleted in", values, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotIn(List<Boolean> values) {
addCriterion("deleted not in", values, "deleted");
return (Criteria) this;
}
public Criteria andDeletedBetween(Boolean value1, Boolean value2) {
addCriterion("deleted between", value1, value2, "deleted");
return (Criteria) this;
}
public Criteria andDeletedNotBetween(Boolean value1, Boolean value2) {
addCriterion("deleted not between", value1, value2, "deleted");
return (Criteria) this;
}
} }
public static class Criteria extends GeneratedCriteria { public static class Criteria extends GeneratedCriteria {

View File

@ -18,6 +18,7 @@
<result column="start_time" jdbcType="BIGINT" property="startTime" /> <result column="start_time" jdbcType="BIGINT" property="startTime" />
<result column="end_time" jdbcType="BIGINT" property="endTime" /> <result column="end_time" jdbcType="BIGINT" property="endTime" />
<result column="executor" jdbcType="VARCHAR" property="executor" /> <result column="executor" jdbcType="VARCHAR" property="executor" />
<result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -80,7 +81,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 end_time, executor, deleted
</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
@ -118,13 +119,13 @@
`result`, resource_pool_id, resource_pool_node, `result`, resource_pool_id, resource_pool_node,
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) executor, deleted)
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}) #{executor,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT})
</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
@ -177,6 +178,9 @@
<if test="executor != null"> <if test="executor != null">
executor, executor,
</if> </if>
<if test="deleted != null">
deleted,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -227,6 +231,9 @@
<if test="executor != null"> <if test="executor != null">
#{executor,jdbcType=VARCHAR}, #{executor,jdbcType=VARCHAR},
</if> </if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</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">
@ -286,6 +293,9 @@
<if test="record.executor != null"> <if test="record.executor != null">
executor = #{record.executor,jdbcType=VARCHAR}, executor = #{record.executor,jdbcType=VARCHAR},
</if> </if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</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" />
@ -308,7 +318,8 @@
thread_id = #{record.threadId,jdbcType=VARCHAR}, thread_id = #{record.threadId,jdbcType=VARCHAR},
start_time = #{record.startTime,jdbcType=BIGINT}, start_time = #{record.startTime,jdbcType=BIGINT},
end_time = #{record.endTime,jdbcType=BIGINT}, end_time = #{record.endTime,jdbcType=BIGINT},
executor = #{record.executor,jdbcType=VARCHAR} executor = #{record.executor,jdbcType=VARCHAR},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -361,6 +372,9 @@
<if test="executor != null"> <if test="executor != null">
executor = #{executor,jdbcType=VARCHAR}, executor = #{executor,jdbcType=VARCHAR},
</if> </if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
@ -380,14 +394,15 @@
thread_id = #{threadId,jdbcType=VARCHAR}, thread_id = #{threadId,jdbcType=VARCHAR},
start_time = #{startTime,jdbcType=BIGINT}, start_time = #{startTime,jdbcType=BIGINT},
end_time = #{endTime,jdbcType=BIGINT}, end_time = #{endTime,jdbcType=BIGINT},
executor = #{executor,jdbcType=VARCHAR} executor = #{executor,jdbcType=VARCHAR},
deleted = #{deleted,jdbcType=BIT}
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) end_time, executor, deleted)
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},
@ -395,7 +410,7 @@
#{item.result,jdbcType=VARCHAR}, #{item.resourcePoolId,jdbcType=VARCHAR}, #{item.resourcePoolNode,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.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.executor,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT})
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertSelective" parameterType="map"> <insert id="batchInsertSelective" parameterType="map">
@ -456,6 +471,9 @@
<if test="'executor'.toString() == column.value"> <if test="'executor'.toString() == column.value">
#{item.executor,jdbcType=VARCHAR} #{item.executor,jdbcType=VARCHAR}
</if> </if>
<if test="'deleted'.toString() == column.value">
#{item.deleted,jdbcType=BIT}
</if>
</foreach> </foreach>
) )
</foreach> </foreach>

View File

@ -9,7 +9,6 @@
<result column="case_count" jdbcType="BIGINT" property="caseCount" /> <result column="case_count" jdbcType="BIGINT" property="caseCount" />
<result column="result" jdbcType="VARCHAR" property="result" /> <result column="result" jdbcType="VARCHAR" property="result" />
<result column="task_type" jdbcType="VARCHAR" property="taskType" /> <result column="task_type" jdbcType="VARCHAR" property="taskType" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="trigger_mode" jdbcType="VARCHAR" property="triggerMode" /> <result column="trigger_mode" jdbcType="VARCHAR" property="triggerMode" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" /> <result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="organization_id" jdbcType="VARCHAR" property="organizationId" /> <result column="organization_id" jdbcType="VARCHAR" property="organizationId" />
@ -18,6 +17,8 @@
<result column="start_time" jdbcType="BIGINT" property="startTime" /> <result column="start_time" jdbcType="BIGINT" property="startTime" />
<result column="end_time" jdbcType="BIGINT" property="endTime" /> <result column="end_time" jdbcType="BIGINT" property="endTime" />
<result column="integrated" jdbcType="BIT" property="integrated" /> <result column="integrated" jdbcType="BIT" property="integrated" />
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="deleted" jdbcType="BIT" property="deleted" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -78,8 +79,9 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, num, task_name, `status`, case_count, `result`, task_type, resource_id, trigger_mode, id, num, task_name, `status`, case_count, `result`, task_type, trigger_mode, project_id,
project_id, organization_id, create_time, create_user, start_time, end_time, integrated organization_id, create_time, create_user, start_time, end_time, integrated, resource_id,
deleted
</sql> </sql>
<select id="selectByExample" parameterType="io.metersphere.system.domain.ExecTaskExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="io.metersphere.system.domain.ExecTaskExample" resultMap="BaseResultMap">
select select
@ -114,16 +116,16 @@
<insert id="insert" parameterType="io.metersphere.system.domain.ExecTask"> <insert id="insert" parameterType="io.metersphere.system.domain.ExecTask">
insert into exec_task (id, num, task_name, insert into exec_task (id, num, task_name,
`status`, case_count, `result`, `status`, case_count, `result`,
task_type, resource_id, trigger_mode, task_type, trigger_mode, project_id,
project_id, organization_id, create_time, organization_id, create_time, create_user,
create_user, start_time, end_time, start_time, end_time, integrated,
integrated) resource_id, deleted)
values (#{id,jdbcType=VARCHAR}, #{num,jdbcType=BIGINT}, #{taskName,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{num,jdbcType=BIGINT}, #{taskName,jdbcType=VARCHAR},
#{status,jdbcType=VARCHAR}, #{caseCount,jdbcType=BIGINT}, #{result,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{caseCount,jdbcType=BIGINT}, #{result,jdbcType=VARCHAR},
#{taskType,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, #{triggerMode,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR}, #{triggerMode,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR},
#{projectId,jdbcType=VARCHAR}, #{organizationId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{organizationId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR},
#{createUser,jdbcType=VARCHAR}, #{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT}, #{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT}, #{integrated,jdbcType=BIT},
#{integrated,jdbcType=BIT}) #{resourceId,jdbcType=VARCHAR}, #{deleted,jdbcType=BIT})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.system.domain.ExecTask"> <insert id="insertSelective" parameterType="io.metersphere.system.domain.ExecTask">
insert into exec_task insert into exec_task
@ -149,9 +151,6 @@
<if test="taskType != null"> <if test="taskType != null">
task_type, task_type,
</if> </if>
<if test="resourceId != null">
resource_id,
</if>
<if test="triggerMode != null"> <if test="triggerMode != null">
trigger_mode, trigger_mode,
</if> </if>
@ -176,6 +175,12 @@
<if test="integrated != null"> <if test="integrated != null">
integrated, integrated,
</if> </if>
<if test="resourceId != null">
resource_id,
</if>
<if test="deleted != null">
deleted,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null"> <if test="id != null">
@ -199,9 +204,6 @@
<if test="taskType != null"> <if test="taskType != null">
#{taskType,jdbcType=VARCHAR}, #{taskType,jdbcType=VARCHAR},
</if> </if>
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
</if>
<if test="triggerMode != null"> <if test="triggerMode != null">
#{triggerMode,jdbcType=VARCHAR}, #{triggerMode,jdbcType=VARCHAR},
</if> </if>
@ -226,6 +228,12 @@
<if test="integrated != null"> <if test="integrated != null">
#{integrated,jdbcType=BIT}, #{integrated,jdbcType=BIT},
</if> </if>
<if test="resourceId != null">
#{resourceId,jdbcType=VARCHAR},
</if>
<if test="deleted != null">
#{deleted,jdbcType=BIT},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="io.metersphere.system.domain.ExecTaskExample" resultType="java.lang.Long"> <select id="countByExample" parameterType="io.metersphere.system.domain.ExecTaskExample" resultType="java.lang.Long">
@ -258,9 +266,6 @@
<if test="record.taskType != null"> <if test="record.taskType != null">
task_type = #{record.taskType,jdbcType=VARCHAR}, task_type = #{record.taskType,jdbcType=VARCHAR},
</if> </if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
</if>
<if test="record.triggerMode != null"> <if test="record.triggerMode != null">
trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, trigger_mode = #{record.triggerMode,jdbcType=VARCHAR},
</if> </if>
@ -285,6 +290,12 @@
<if test="record.integrated != null"> <if test="record.integrated != null">
integrated = #{record.integrated,jdbcType=BIT}, integrated = #{record.integrated,jdbcType=BIT},
</if> </if>
<if test="record.resourceId != null">
resource_id = #{record.resourceId,jdbcType=VARCHAR},
</if>
<if test="record.deleted != null">
deleted = #{record.deleted,jdbcType=BIT},
</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" />
@ -299,7 +310,6 @@
case_count = #{record.caseCount,jdbcType=BIGINT}, case_count = #{record.caseCount,jdbcType=BIGINT},
`result` = #{record.result,jdbcType=VARCHAR}, `result` = #{record.result,jdbcType=VARCHAR},
task_type = #{record.taskType,jdbcType=VARCHAR}, task_type = #{record.taskType,jdbcType=VARCHAR},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, trigger_mode = #{record.triggerMode,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR},
organization_id = #{record.organizationId,jdbcType=VARCHAR}, organization_id = #{record.organizationId,jdbcType=VARCHAR},
@ -307,7 +317,9 @@
create_user = #{record.createUser,jdbcType=VARCHAR}, create_user = #{record.createUser,jdbcType=VARCHAR},
start_time = #{record.startTime,jdbcType=BIGINT}, start_time = #{record.startTime,jdbcType=BIGINT},
end_time = #{record.endTime,jdbcType=BIGINT}, end_time = #{record.endTime,jdbcType=BIGINT},
integrated = #{record.integrated,jdbcType=BIT} integrated = #{record.integrated,jdbcType=BIT},
resource_id = #{record.resourceId,jdbcType=VARCHAR},
deleted = #{record.deleted,jdbcType=BIT}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -333,9 +345,6 @@
<if test="taskType != null"> <if test="taskType != null">
task_type = #{taskType,jdbcType=VARCHAR}, task_type = #{taskType,jdbcType=VARCHAR},
</if> </if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="triggerMode != null"> <if test="triggerMode != null">
trigger_mode = #{triggerMode,jdbcType=VARCHAR}, trigger_mode = #{triggerMode,jdbcType=VARCHAR},
</if> </if>
@ -360,6 +369,12 @@
<if test="integrated != null"> <if test="integrated != null">
integrated = #{integrated,jdbcType=BIT}, integrated = #{integrated,jdbcType=BIT},
</if> </if>
<if test="resourceId != null">
resource_id = #{resourceId,jdbcType=VARCHAR},
</if>
<if test="deleted != null">
deleted = #{deleted,jdbcType=BIT},
</if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
@ -371,7 +386,6 @@
case_count = #{caseCount,jdbcType=BIGINT}, case_count = #{caseCount,jdbcType=BIGINT},
`result` = #{result,jdbcType=VARCHAR}, `result` = #{result,jdbcType=VARCHAR},
task_type = #{taskType,jdbcType=VARCHAR}, task_type = #{taskType,jdbcType=VARCHAR},
resource_id = #{resourceId,jdbcType=VARCHAR},
trigger_mode = #{triggerMode,jdbcType=VARCHAR}, trigger_mode = #{triggerMode,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR}, project_id = #{projectId,jdbcType=VARCHAR},
organization_id = #{organizationId,jdbcType=VARCHAR}, organization_id = #{organizationId,jdbcType=VARCHAR},
@ -379,22 +393,24 @@
create_user = #{createUser,jdbcType=VARCHAR}, create_user = #{createUser,jdbcType=VARCHAR},
start_time = #{startTime,jdbcType=BIGINT}, start_time = #{startTime,jdbcType=BIGINT},
end_time = #{endTime,jdbcType=BIGINT}, end_time = #{endTime,jdbcType=BIGINT},
integrated = #{integrated,jdbcType=BIT} integrated = #{integrated,jdbcType=BIT},
resource_id = #{resourceId,jdbcType=VARCHAR},
deleted = #{deleted,jdbcType=BIT}
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 insert into exec_task
(id, num, task_name, `status`, case_count, `result`, task_type, resource_id, trigger_mode, (id, num, task_name, `status`, case_count, `result`, task_type, trigger_mode, project_id,
project_id, organization_id, create_time, create_user, start_time, end_time, integrated organization_id, create_time, create_user, start_time, end_time, integrated, resource_id,
) deleted)
values values
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.id,jdbcType=VARCHAR}, #{item.num,jdbcType=BIGINT}, #{item.taskName,jdbcType=VARCHAR}, (#{item.id,jdbcType=VARCHAR}, #{item.num,jdbcType=BIGINT}, #{item.taskName,jdbcType=VARCHAR},
#{item.status,jdbcType=VARCHAR}, #{item.caseCount,jdbcType=BIGINT}, #{item.result,jdbcType=VARCHAR}, #{item.status,jdbcType=VARCHAR}, #{item.caseCount,jdbcType=BIGINT}, #{item.result,jdbcType=VARCHAR},
#{item.taskType,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR}, #{item.triggerMode,jdbcType=VARCHAR}, #{item.taskType,jdbcType=VARCHAR}, #{item.triggerMode,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR},
#{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR},
#{item.createUser,jdbcType=VARCHAR}, #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT}, #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT}, #{item.integrated,jdbcType=BIT},
#{item.integrated,jdbcType=BIT}) #{item.resourceId,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT})
</foreach> </foreach>
</insert> </insert>
<insert id="batchInsertSelective" parameterType="map"> <insert id="batchInsertSelective" parameterType="map">
@ -428,9 +444,6 @@
<if test="'task_type'.toString() == column.value"> <if test="'task_type'.toString() == column.value">
#{item.taskType,jdbcType=VARCHAR} #{item.taskType,jdbcType=VARCHAR}
</if> </if>
<if test="'resource_id'.toString() == column.value">
#{item.resourceId,jdbcType=VARCHAR}
</if>
<if test="'trigger_mode'.toString() == column.value"> <if test="'trigger_mode'.toString() == column.value">
#{item.triggerMode,jdbcType=VARCHAR} #{item.triggerMode,jdbcType=VARCHAR}
</if> </if>
@ -455,6 +468,12 @@
<if test="'integrated'.toString() == column.value"> <if test="'integrated'.toString() == column.value">
#{item.integrated,jdbcType=BIT} #{item.integrated,jdbcType=BIT}
</if> </if>
<if test="'resource_id'.toString() == column.value">
#{item.resourceId,jdbcType=VARCHAR}
</if>
<if test="'deleted'.toString() == column.value">
#{item.deleted,jdbcType=BIT}
</if>
</foreach> </foreach>
) )
</foreach> </foreach>

View File

@ -72,5 +72,8 @@ CREATE INDEX idx_project_id_delete_create_time
CREATE INDEX idx_project_id_delete_create_time_create_user CREATE INDEX idx_project_id_delete_create_time_create_user
ON bug (project_id, deleted, create_time, create_user); ON bug (project_id, deleted, create_time, create_user);
ALTER TABLE exec_task ADD COLUMN deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '删除标识';
ALTER TABLE exec_task_item ADD COLUMN deleted bit(1) NOT NULL DEFAULT b'0' COMMENT '删除标识';
-- 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

@ -0,0 +1,10 @@
package io.metersphere.api.mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtApiReportRelateTaskMapper {
List<String> selectDeleteTaskOrItem(@Param("ids") List<String> ids);
}

View File

@ -0,0 +1,28 @@
<?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.api.mapper.ExtApiReportRelateTaskMapper">
<select id="selectDeleteTaskOrItem" resultType="java.lang.String">
SELECT
id
FROM
exec_task
WHERE
id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND deleted = TRUE UNION
SELECT
id
FROM
exec_task_item
WHERE
id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND deleted = TRUE
</select>
</mapper>

View File

@ -6,9 +6,11 @@ import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.service.BaseCleanUpReport; import io.metersphere.system.service.BaseCleanUpReport;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -42,6 +44,8 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
private ApiScenarioReportDetailBlobMapper apiScenarioReportDetailBlobMapper; private ApiScenarioReportDetailBlobMapper apiScenarioReportDetailBlobMapper;
@Resource @Resource
private ApiReportRelateTaskMapper apiReportRelateTaskMapper; private ApiReportRelateTaskMapper apiReportRelateTaskMapper;
@Resource
private ExtApiReportRelateTaskMapper extApiReportRelateTaskMapper;
@Override @Override
public void cleanReport(Map<String, String> map, String projectId) { public void cleanReport(Map<String, String> map, String projectId) {
@ -80,6 +84,7 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
/** /**
* 获取任务报告ID * 获取任务报告ID
*
* @param reportIds 报告ID集合 * @param reportIds 报告ID集合
* @return 任务报告ID集合 * @return 任务报告ID集合
*/ */
@ -87,6 +92,12 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); ApiReportRelateTaskExample example = new ApiReportRelateTaskExample();
example.createCriteria().andReportIdIn(reportIds); example.createCriteria().andReportIdIn(reportIds);
List<ApiReportRelateTask> relateTasks = apiReportRelateTaskMapper.selectByExample(example); List<ApiReportRelateTask> relateTasks = apiReportRelateTaskMapper.selectByExample(example);
List<String> ids = relateTasks.stream().map(ApiReportRelateTask::getTaskResourceId).toList();
if (CollectionUtils.isEmpty(ids)) {
return new ArrayList<>();
}
List<String> deletedIds = extApiReportRelateTaskMapper.selectDeleteTaskOrItem(ids);
relateTasks.removeIf(relateTask -> deletedIds.contains(relateTask.getTaskResourceId()));
return relateTasks.stream().map(ApiReportRelateTask::getReportId).toList(); return relateTasks.stream().map(ApiReportRelateTask::getReportId).toList();
} }

View File

@ -1,16 +1,18 @@
package io.metersphere.api.service; package io.metersphere.api.service;
import io.metersphere.api.domain.ApiReportRelateTaskExample;
import io.metersphere.api.mapper.ApiReportRelateTaskMapper;
import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.sdk.util.SubListUtils; import io.metersphere.system.domain.ExecTask;
import io.metersphere.system.domain.ExecTaskExample;
import io.metersphere.system.domain.ExecTaskItem;
import io.metersphere.system.domain.ExecTaskItemExample;
import io.metersphere.system.mapper.ExecTaskItemMapper;
import io.metersphere.system.mapper.ExecTaskMapper;
import io.metersphere.system.mapper.ExtExecTaskItemMapper; import io.metersphere.system.mapper.ExtExecTaskItemMapper;
import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.mapper.ExtExecTaskMapper;
import io.metersphere.system.service.BaseCleanUpReport; import io.metersphere.system.service.BaseCleanUpReport;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -26,31 +28,37 @@ import static io.metersphere.sdk.util.ShareUtil.getCleanDate;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { public class CleanupTaskResultServiceImpl implements BaseCleanUpReport {
@Resource @Resource
private ExtExecTaskMapper extExecTaskMapper; private ExtExecTaskMapper extExecTaskMapper;
@Resource @Resource
private ExtExecTaskItemMapper extExecTaskItemMapper; private ExtExecTaskItemMapper extExecTaskItemMapper;
@Resource @Resource
private ApiReportRelateTaskMapper apiReportRelateTaskMapper; private ExecTaskMapper execTaskMapper;
@Resource
private ExecTaskItemMapper execTaskItemMapper;
@Override @Override
public void cleanReport(Map<String, String> map, String projectId) { public void cleanReport(Map<String, String> map, String projectId) {
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果"); LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果");
String expr = map.get(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name()); String expr = map.get(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name());
long timeMills = getCleanDate(expr); long timeMills = getCleanDate(expr);
List<String> cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); List<String> cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId);
List<String> cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId); List<String> cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId);
List<String> cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds); if (CollectionUtils.isNotEmpty(cleanTaskIds)) {
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条"); ExecTaskExample example = new ExecTaskExample();
if (CollectionUtils.isNotEmpty(cleanIds)) { example.createCriteria().andIdIn(cleanTaskIds);
// 清理任务-报告关系表 ExecTask execTask = new ExecTask();
SubListUtils.dealForSubList(cleanIds, 100, ids -> { execTask.setDeleted(true);
ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); execTaskMapper.updateByExampleSelective(execTask, example);
example.createCriteria().andTaskResourceIdIn(cleanIds); }
apiReportRelateTaskMapper.deleteByExample(example); if (CollectionUtils.isNotEmpty(cleanTaskItemIds)) {
}); ExecTaskItemExample example = new ExecTaskItemExample();
} example.createCriteria().andIdIn(cleanTaskItemIds);
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果结束!"); ExecTaskItem execTaskItem = new ExecTaskItem();
} execTaskItem.setDeleted(true);
execTaskItemMapper.updateByExampleSelective(execTaskItem, example);
}
LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果结束!");
}
} }

View File

@ -41,7 +41,7 @@ public class CleanupTaskResultTests {
task.setResult("PENDING"); task.setResult("PENDING");
task.setCreateUser("admin"); task.setCreateUser("admin");
task.setCreateTime(System.currentTimeMillis()); task.setCreateTime(System.currentTimeMillis());
execTaskMapper.insert(task); execTaskMapper.insertSelective(task);
} }
@Test @Test

View File

@ -18,7 +18,7 @@
</select> </select>
<select id="getTaskItemIdsByTime" resultType="java.lang.String"> <select id="getTaskItemIdsByTime" resultType="java.lang.String">
select id from exec_task_item where project_id = #{projectId} and start_time &lt;= #{timeMills} select id from exec_task_item where project_id = #{projectId} and start_time &lt;= #{timeMills} and deleted = false
</select> </select>
<select id="selectExecInfoByTaskIdAndResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem"> <select id="selectExecInfoByTaskIdAndResourceIds" resultType="io.metersphere.system.domain.ExecTaskItem">
@ -54,6 +54,7 @@
<sql id="queryWhereCondition"> <sql id="queryWhereCondition">
<where> <where>
exec_task_item.deleted = false
<if test="orgId != null and orgId != ''"> <if test="orgId != null and orgId != ''">
and exec_task_item.organization_id = #{orgId} and exec_task_item.organization_id = #{orgId}
</if> </if>
@ -161,8 +162,9 @@
resource_pool_id resource_pool_id
FROM FROM
exec_task_item exec_task_item
WHERE deleted = false
<if test="taskIds != null and taskIds.size() > 0"> <if test="taskIds != null and taskIds.size() > 0">
WHERE task_id IN and task_id IN
<foreach collection="taskIds" item="taskId" open="(" separator="," close=")"> <foreach collection="taskIds" item="taskId" open="(" separator="," close=")">
#{taskId} #{taskId}
</foreach> </foreach>
@ -185,6 +187,7 @@
and organization_id = #{organizationId} and organization_id = #{organizationId}
</if> </if>
and `status` = 'RUNNING' and `status` = 'RUNNING'
and deleted = false
</update> </update>
<select id="hasErrorItem" resultType="java.lang.Boolean"> <select id="hasErrorItem" resultType="java.lang.Boolean">
@ -213,7 +216,9 @@
UPDATE exec_task_item UPDATE exec_task_item
SET `status` = #{status}, SET `status` = #{status},
executor = #{userId} executor = #{userId}
WHERE id in WHERE
deleted = false
and id in
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
@ -234,8 +239,9 @@
resource_pool_id resource_pool_id
FROM FROM
exec_task_item exec_task_item
where deleted = false
<if test="ids != null and ids.size() > 0"> <if test="ids != null and ids.size() > 0">
WHERE id IN and id IN
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>
@ -248,6 +254,7 @@
inner join exec_task on exec_task_item.task_id = exec_task.id inner join exec_task on exec_task_item.task_id = exec_task.id
<where> <where>
exec_task_item.status = 'RUNNING' exec_task_item.status = 'RUNNING'
and exec_task_item.deleted = false
<if test="projectId != null and projectId != ''"> <if test="projectId != null and projectId != ''">
and exec_task_item.project_id = #{projectId} and exec_task_item.project_id = #{projectId}
</if> </if>

View File

@ -5,6 +5,7 @@
SELECT * SELECT *
FROM exec_task FROM exec_task
<where> <where>
exec_task.deleted = false
<if test="request.keyword != null and request.keyword != ''"> <if test="request.keyword != null and request.keyword != ''">
and ( and (
exec_task.num like concat('%', #{request.keyword},'%') exec_task.num like concat('%', #{request.keyword},'%')
@ -27,9 +28,9 @@
</sql> </sql>
<delete id="deleteTaskByIds"> <update id="deleteTaskByIds">
DELETE UPDATE exec_task
FROM exec_task SET deleted = true
WHERE id in WHERE id in
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{id}
@ -40,12 +41,13 @@
<if test="orgId != null and orgId != ''"> <if test="orgId != null and orgId != ''">
and organization_id = #{orgId} and organization_id = #{orgId}
</if> </if>
</delete> </update>
<select id="getIds" resultType="java.lang.String"> <select id="getIds" resultType="java.lang.String">
select id from exec_task select id from exec_task
<where> <where>
deleted = false
<if test="flag"> <if test="flag">
and status = 'RUNNING' and status = 'RUNNING'
</if> </if>
@ -125,10 +127,11 @@
and organization_id = #{organizationId} and organization_id = #{organizationId}
</if> </if>
and `status` = 'RUNNING' and `status` = 'RUNNING'
and deleted = false
</update> </update>
<select id="getTaskIdsByTime" resultType="java.lang.String"> <select id="getTaskIdsByTime" resultType="java.lang.String">
select id from exec_task where project_id = #{projectId} and start_time &lt;= #{timeMills} select id from exec_task where project_id = #{projectId} and start_time &lt;= #{timeMills} and deleted = false
</select> </select>

View File

@ -9,8 +9,6 @@ import io.metersphere.engine.EngineFactory;
import io.metersphere.engine.MsHttpClient; import io.metersphere.engine.MsHttpClient;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.domain.ProjectExample;
import io.metersphere.project.domain.ProjectTestResourcePool;
import io.metersphere.project.domain.ProjectTestResourcePoolExample;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.project.mapper.ProjectTestResourcePoolMapper; import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
import io.metersphere.sdk.constants.*; import io.metersphere.sdk.constants.*;
@ -52,17 +50,17 @@ import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionUtils; import org.mybatis.spring.SqlSessionUtils;
import org.quartz.CronExpression;
import org.quartz.JobKey; import org.quartz.JobKey;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException; import java.util.ArrayList;
import java.util.*; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -620,20 +618,12 @@ public class BaseTaskHubService {
//2.删除任务明细 //2.删除任务明细
ExecTaskItemExample itemExample = new ExecTaskItemExample(); ExecTaskItemExample itemExample = new ExecTaskItemExample();
itemExample.createCriteria().andTaskIdEqualTo(id); itemExample.createCriteria().andTaskIdEqualTo(id);
execTaskItemMapper.deleteByExample(itemExample); ExecTaskItem taskItem = new ExecTaskItem();
//3.删除任务与报告关联关系 taskItem.setDeleted(true);
deleteReportRelateTask(List.of(id)); execTaskItemMapper.updateByExampleSelective(taskItem, itemExample);
handleStopTaskAsync(List.of(id)); handleStopTaskAsync(List.of(id));
} }
private void deleteReportRelateTask(List<String> ids) {
List<String> itemIds = extExecTaskItemMapper.getItemIdByTaskIds(ids);
itemIds.addAll(ids);
ApiReportRelateTaskExample reportExample = new ApiReportRelateTaskExample();
reportExample.createCriteria().andTaskResourceIdIn(itemIds);
apiReportRelateTaskMapper.deleteByExample(reportExample);
}
public void batchStopTask(List<String> ids, String userId, String orgId, String projectId) { public void batchStopTask(List<String> ids, String userId, String orgId, String projectId) {
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
//1.更新任务状态 //1.更新任务状态
@ -664,9 +654,9 @@ public class BaseTaskHubService {
//2.删除任务明细 //2.删除任务明细
ExecTaskItemExample itemExample = new ExecTaskItemExample(); ExecTaskItemExample itemExample = new ExecTaskItemExample();
itemExample.createCriteria().andTaskIdIn(ids); itemExample.createCriteria().andTaskIdIn(ids);
execTaskItemMapper.deleteByExample(itemExample); ExecTaskItem taskItem = new ExecTaskItem();
//3.删除任务与报告关联关系 taskItem.setDeleted(true);
deleteReportRelateTask(ids); execTaskItemMapper.updateByExampleSelective(taskItem, itemExample);
handleStopTaskAsync(ids); handleStopTaskAsync(ids);
} }
} }