diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java index a52bcc4bf2..917a2a4670 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTask.java @@ -76,6 +76,10 @@ public class ExecTask implements Serializable { @NotNull(message = "{exec_task.integrated.not_blank}", groups = {Created.class}) 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; public enum Column { @@ -94,7 +98,8 @@ public class ExecTask implements Serializable { createUser("create_user", "createUser", "VARCHAR", false), startTime("start_time", "startTime", "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 = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java index 22cbfef906..15825a1d33 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskExample.java @@ -574,76 +574,6 @@ public class ExecTaskExample { 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 values) { - addCriterion("resource_id in", values, "resourceId"); - return (Criteria) this; - } - - public Criteria andResourceIdNotIn(List 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() { addCriterion("trigger_mode is null"); return (Criteria) this; @@ -1163,6 +1093,136 @@ public class ExecTaskExample { addCriterion("integrated not between", value1, value2, "integrated"); 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 values) { + addCriterion("resource_id in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotIn(List 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 values) { + addCriterion("deleted in", values, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedNotIn(List 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 { diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java index b02f04491c..46a9398e7a 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItem.java @@ -4,6 +4,7 @@ import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import java.io.Serializable; 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}) 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; public enum Column { @@ -98,7 +103,8 @@ public class ExecTaskItem implements Serializable { threadId("thread_id", "threadId", "VARCHAR", false), startTime("start_time", "startTime", "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 = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java index 0beeb8dc0e..cb1febb513 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/ExecTaskItemExample.java @@ -1203,6 +1203,66 @@ public class ExecTaskItemExample { addCriterion("executor not between", value1, value2, "executor"); 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 values) { + addCriterion("deleted in", values, "deleted"); + return (Criteria) this; + } + + public Criteria andDeletedNotIn(List 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 { diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml index 0b3a5a1d2f..07ccbe81fe 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskItemMapper.xml @@ -18,6 +18,7 @@ + @@ -80,7 +81,7 @@ 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 + end_time, executor, deleted @@ -286,6 +293,9 @@ executor = #{record.executor,jdbcType=VARCHAR}, + + deleted = #{record.deleted,jdbcType=BIT}, + @@ -308,7 +318,8 @@ thread_id = #{record.threadId,jdbcType=VARCHAR}, start_time = #{record.startTime,jdbcType=BIGINT}, end_time = #{record.endTime,jdbcType=BIGINT}, - executor = #{record.executor,jdbcType=VARCHAR} + executor = #{record.executor,jdbcType=VARCHAR}, + deleted = #{record.deleted,jdbcType=BIT} @@ -361,6 +372,9 @@ executor = #{executor,jdbcType=VARCHAR}, + + deleted = #{deleted,jdbcType=BIT}, + where id = #{id,jdbcType=VARCHAR} @@ -380,14 +394,15 @@ thread_id = #{threadId,jdbcType=VARCHAR}, start_time = #{startTime,jdbcType=BIGINT}, end_time = #{endTime,jdbcType=BIGINT}, - executor = #{executor,jdbcType=VARCHAR} + executor = #{executor,jdbcType=VARCHAR}, + deleted = #{deleted,jdbcType=BIT} where id = #{id,jdbcType=VARCHAR} 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) + end_time, executor, deleted) values (#{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.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.executor,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}) @@ -456,6 +471,9 @@ #{item.executor,jdbcType=VARCHAR} + + #{item.deleted,jdbcType=BIT} + ) diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml index d38f02201a..0d0096c172 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/ExecTaskMapper.xml @@ -9,7 +9,6 @@ - @@ -18,6 +17,8 @@ + + @@ -78,8 +79,9 @@ - id, num, task_name, `status`, case_count, `result`, task_type, resource_id, trigger_mode, - project_id, organization_id, create_time, create_user, start_time, end_time, integrated + id, num, task_name, `status`, case_count, `result`, task_type, trigger_mode, project_id, + organization_id, create_time, create_user, start_time, end_time, integrated, resource_id, + deleted @@ -258,9 +266,6 @@ task_type = #{record.taskType,jdbcType=VARCHAR}, - - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, @@ -285,6 +290,12 @@ integrated = #{record.integrated,jdbcType=BIT}, + + resource_id = #{record.resourceId,jdbcType=VARCHAR}, + + + deleted = #{record.deleted,jdbcType=BIT}, + @@ -299,7 +310,6 @@ case_count = #{record.caseCount,jdbcType=BIGINT}, `result` = #{record.result,jdbcType=VARCHAR}, task_type = #{record.taskType,jdbcType=VARCHAR}, - resource_id = #{record.resourceId,jdbcType=VARCHAR}, trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, project_id = #{record.projectId,jdbcType=VARCHAR}, organization_id = #{record.organizationId,jdbcType=VARCHAR}, @@ -307,7 +317,9 @@ create_user = #{record.createUser,jdbcType=VARCHAR}, start_time = #{record.startTime,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} @@ -333,9 +345,6 @@ task_type = #{taskType,jdbcType=VARCHAR}, - - resource_id = #{resourceId,jdbcType=VARCHAR}, - trigger_mode = #{triggerMode,jdbcType=VARCHAR}, @@ -360,6 +369,12 @@ integrated = #{integrated,jdbcType=BIT}, + + resource_id = #{resourceId,jdbcType=VARCHAR}, + + + deleted = #{deleted,jdbcType=BIT}, + where id = #{id,jdbcType=VARCHAR} @@ -371,7 +386,6 @@ case_count = #{caseCount,jdbcType=BIGINT}, `result` = #{result,jdbcType=VARCHAR}, task_type = #{taskType,jdbcType=VARCHAR}, - resource_id = #{resourceId,jdbcType=VARCHAR}, trigger_mode = #{triggerMode,jdbcType=VARCHAR}, project_id = #{projectId,jdbcType=VARCHAR}, organization_id = #{organizationId,jdbcType=VARCHAR}, @@ -379,22 +393,24 @@ create_user = #{createUser,jdbcType=VARCHAR}, start_time = #{startTime,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} insert into exec_task - (id, num, task_name, `status`, case_count, `result`, task_type, resource_id, trigger_mode, - project_id, organization_id, create_time, create_user, start_time, end_time, integrated - ) + (id, num, task_name, `status`, case_count, `result`, task_type, trigger_mode, project_id, + organization_id, create_time, create_user, start_time, end_time, integrated, resource_id, + deleted) values (#{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.taskType,jdbcType=VARCHAR}, #{item.resourceId,jdbcType=VARCHAR}, #{item.triggerMode,jdbcType=VARCHAR}, - #{item.projectId,jdbcType=VARCHAR}, #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, - #{item.createUser,jdbcType=VARCHAR}, #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT}, - #{item.integrated,jdbcType=BIT}) + #{item.taskType,jdbcType=VARCHAR}, #{item.triggerMode,jdbcType=VARCHAR}, #{item.projectId,jdbcType=VARCHAR}, + #{item.organizationId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, #{item.createUser,jdbcType=VARCHAR}, + #{item.startTime,jdbcType=BIGINT}, #{item.endTime,jdbcType=BIGINT}, #{item.integrated,jdbcType=BIT}, + #{item.resourceId,jdbcType=VARCHAR}, #{item.deleted,jdbcType=BIT}) @@ -428,9 +444,6 @@ #{item.taskType,jdbcType=VARCHAR} - - #{item.resourceId,jdbcType=VARCHAR} - #{item.triggerMode,jdbcType=VARCHAR} @@ -455,6 +468,12 @@ #{item.integrated,jdbcType=BIT} + + #{item.resourceId,jdbcType=VARCHAR} + + + #{item.deleted,jdbcType=BIT} + ) diff --git a/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql index dc16078b78..6961b025ec 100644 --- a/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql @@ -72,5 +72,8 @@ CREATE INDEX idx_project_id_delete_create_time CREATE INDEX idx_project_id_delete_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 SESSION innodb_lock_wait_timeout = DEFAULT; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportRelateTaskMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportRelateTaskMapper.java new file mode 100644 index 0000000000..f907cfcba8 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportRelateTaskMapper.java @@ -0,0 +1,10 @@ +package io.metersphere.api.mapper; + +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtApiReportRelateTaskMapper { + + List selectDeleteTaskOrItem(@Param("ids") List ids); +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportRelateTaskMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportRelateTaskMapper.xml new file mode 100644 index 0000000000..60f3d9c2c0 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportRelateTaskMapper.xml @@ -0,0 +1,28 @@ + + + + + + + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java index e0526bb9e1..3259ef8ec3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupApiReportServiceImpl.java @@ -6,9 +6,11 @@ import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.service.BaseCleanUpReport; import jakarta.annotation.Resource; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -42,6 +44,8 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport { private ApiScenarioReportDetailBlobMapper apiScenarioReportDetailBlobMapper; @Resource private ApiReportRelateTaskMapper apiReportRelateTaskMapper; + @Resource + private ExtApiReportRelateTaskMapper extApiReportRelateTaskMapper; @Override public void cleanReport(Map map, String projectId) { @@ -80,6 +84,7 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport { /** * 获取任务报告ID + * * @param reportIds 报告ID集合 * @return 任务报告ID集合 */ @@ -87,6 +92,12 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport { ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); example.createCriteria().andReportIdIn(reportIds); List relateTasks = apiReportRelateTaskMapper.selectByExample(example); + List ids = relateTasks.stream().map(ApiReportRelateTask::getTaskResourceId).toList(); + if (CollectionUtils.isEmpty(ids)) { + return new ArrayList<>(); + } + List deletedIds = extApiReportRelateTaskMapper.selectDeleteTaskOrItem(ids); + relateTasks.removeIf(relateTask -> deletedIds.contains(relateTask.getTaskResourceId())); return relateTasks.stream().map(ApiReportRelateTask::getReportId).toList(); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java index cd165c7f00..5d5fffa709 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/CleanupTaskResultServiceImpl.java @@ -1,16 +1,18 @@ 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.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.ExtExecTaskMapper; import io.metersphere.system.service.BaseCleanUpReport; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.ListUtils; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -26,31 +28,37 @@ import static io.metersphere.sdk.util.ShareUtil.getCleanDate; @Transactional(rollbackFor = Exception.class) public class CleanupTaskResultServiceImpl implements BaseCleanUpReport { - @Resource - private ExtExecTaskMapper extExecTaskMapper; - @Resource - private ExtExecTaskItemMapper extExecTaskItemMapper; - @Resource - private ApiReportRelateTaskMapper apiReportRelateTaskMapper; + @Resource + private ExtExecTaskMapper extExecTaskMapper; + @Resource + private ExtExecTaskItemMapper extExecTaskItemMapper; + @Resource + private ExecTaskMapper execTaskMapper; + @Resource + private ExecTaskItemMapper execTaskItemMapper; - @Override - public void cleanReport(Map map, String projectId) { - LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果"); - String expr = map.get(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name()); - long timeMills = getCleanDate(expr); - List cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); - List cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId); - List cleanIds = ListUtils.union(cleanTaskIds, cleanTaskItemIds); - LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果, 共[" + cleanIds.size() + "]条"); - if (CollectionUtils.isNotEmpty(cleanIds)) { - // 清理任务-报告关系表 - SubListUtils.dealForSubList(cleanIds, 100, ids -> { - ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); - example.createCriteria().andTaskResourceIdIn(cleanIds); - apiReportRelateTaskMapper.deleteByExample(example); - }); - } - LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果结束!"); - } + @Override + public void cleanReport(Map map, String projectId) { + LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果"); + String expr = map.get(ProjectApplicationType.TASK.TASK_CLEAN_REPORT.name()); + long timeMills = getCleanDate(expr); + List cleanTaskIds = extExecTaskMapper.getTaskIdsByTime(timeMills, projectId); + List cleanTaskItemIds = extExecTaskItemMapper.getTaskItemIdsByTime(timeMills, projectId); + if (CollectionUtils.isNotEmpty(cleanTaskIds)) { + ExecTaskExample example = new ExecTaskExample(); + example.createCriteria().andIdIn(cleanTaskIds); + ExecTask execTask = new ExecTask(); + execTask.setDeleted(true); + execTaskMapper.updateByExampleSelective(execTask, example); + } + if (CollectionUtils.isNotEmpty(cleanTaskItemIds)) { + ExecTaskItemExample example = new ExecTaskItemExample(); + example.createCriteria().andIdIn(cleanTaskItemIds); + ExecTaskItem execTaskItem = new ExecTaskItem(); + execTaskItem.setDeleted(true); + execTaskItemMapper.updateByExampleSelective(execTaskItem, example); + } + LogUtils.info("清理当前项目[" + projectId + "]任务中心执行结果结束!"); + } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java index 3ec80ca1e9..6946892567 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/CleanupTaskResultTests.java @@ -41,7 +41,7 @@ public class CleanupTaskResultTests { task.setResult("PENDING"); task.setCreateUser("admin"); task.setCreateTime(System.currentTimeMillis()); - execTaskMapper.insert(task); + execTaskMapper.insertSelective(task); } @Test diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml index f2a739ca61..d7f7832da0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml @@ -18,7 +18,7 @@ @@ -213,7 +216,9 @@ UPDATE exec_task_item SET `status` = #{status}, executor = #{userId} - WHERE id in + WHERE + deleted = false + and id in #{id} @@ -234,8 +239,9 @@ resource_pool_id FROM exec_task_item + where deleted = false - WHERE id IN + and id IN #{id} @@ -248,6 +254,7 @@ inner join exec_task on exec_task_item.task_id = exec_task.id exec_task_item.status = 'RUNNING' + and exec_task_item.deleted = false and exec_task_item.project_id = #{projectId} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml index 87f8c204c3..ba54bb4275 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml @@ -5,6 +5,7 @@ SELECT * FROM exec_task + exec_task.deleted = false and ( exec_task.num like concat('%', #{request.keyword},'%') @@ -27,9 +28,9 @@ - - DELETE - FROM exec_task + + UPDATE exec_task + SET deleted = true WHERE id in #{id} @@ -40,12 +41,13 @@ and organization_id = #{orgId} - + - select id from exec_task where project_id = #{projectId} and start_time <= #{timeMills} + select id from exec_task where project_id = #{projectId} and start_time <= #{timeMills} and deleted = false diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java index 4c211c85a3..ba093d5aa0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -9,8 +9,6 @@ import io.metersphere.engine.EngineFactory; import io.metersphere.engine.MsHttpClient; import io.metersphere.project.domain.Project; 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.ProjectTestResourcePoolMapper; 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.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; -import org.quartz.CronExpression; import org.quartz.JobKey; import org.quartz.TriggerKey; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import java.text.ParseException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; -import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -620,20 +618,12 @@ public class BaseTaskHubService { //2.删除任务明细 ExecTaskItemExample itemExample = new ExecTaskItemExample(); itemExample.createCriteria().andTaskIdEqualTo(id); - execTaskItemMapper.deleteByExample(itemExample); - //3.删除任务与报告关联关系 - deleteReportRelateTask(List.of(id)); + ExecTaskItem taskItem = new ExecTaskItem(); + taskItem.setDeleted(true); + execTaskItemMapper.updateByExampleSelective(taskItem, itemExample); handleStopTaskAsync(List.of(id)); } - private void deleteReportRelateTask(List ids) { - List itemIds = extExecTaskItemMapper.getItemIdByTaskIds(ids); - itemIds.addAll(ids); - ApiReportRelateTaskExample reportExample = new ApiReportRelateTaskExample(); - reportExample.createCriteria().andTaskResourceIdIn(itemIds); - apiReportRelateTaskMapper.deleteByExample(reportExample); - } - public void batchStopTask(List ids, String userId, String orgId, String projectId) { if (CollectionUtils.isNotEmpty(ids)) { //1.更新任务状态 @@ -664,9 +654,9 @@ public class BaseTaskHubService { //2.删除任务明细 ExecTaskItemExample itemExample = new ExecTaskItemExample(); itemExample.createCriteria().andTaskIdIn(ids); - execTaskItemMapper.deleteByExample(itemExample); - //3.删除任务与报告关联关系 - deleteReportRelateTask(ids); + ExecTaskItem taskItem = new ExecTaskItem(); + taskItem.setDeleted(true); + execTaskItemMapper.updateByExampleSelective(taskItem, itemExample); handleStopTaskAsync(ids); } }