From 05bbd1cf8061a6facec007f6d58b6d3feee0da57 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Thu, 21 Nov 2024 16:24:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=A4=B1=E8=B4=A5=E9=87=8D=E8=B7=91=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E6=9D=A1=E6=89=A7=E8=A1=8C=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048956 --user=陈建星 【任务中心】-失败重跑没有在CASE、场景的执行历史中新增执行记录,而是更改原执行记录 https://www.tapd.cn/55049933/s/1614487 --- .../system/domain/ExecTaskItem.java | 6 +- .../system/domain/ExecTaskItemExample.java | 60 +++++++++++++++++++ .../system/mapper/ExecTaskItemMapper.xml | 39 ++++++++---- .../migration/3.5.0/ddl/V3.5.0_2__ga_ddl.sql | 2 + .../migration/3.5.0/dml/V3.5.0_2_1__data.sql | 5 ++ .../definition/ApiTestCaseController.java | 4 +- .../scenario/ApiScenarioController.java | 4 +- .../api/mapper/ExtApiScenarioMapper.java | 1 + .../api/mapper/ExtApiScenarioMapper.xml | 2 +- .../api/service/ApiCommonService.java | 1 + .../definition/ApiTestCaseService.java | 2 +- .../resources/dml/init_exec_history_test.sql | 6 +- .../dml/init_scenario_task_item_test.sql | 8 +-- .../resources/dml/init_task_item_test.sql | 10 ++-- .../dml/init_project_exec_task_test.sql | 10 ++-- .../system/mapper/ExtExecTaskItemMapper.java | 6 +- .../system/mapper/ExtExecTaskItemMapper.xml | 46 +++++++------- .../system/service/BaseTaskHubService.java | 4 +- .../system/service/ExecTaskService.java | 9 ++- .../BaseTaskHubControllerTests.java | 1 + .../resources/dml/init_exec_task_test.sql | 6 +- 21 files changed, 160 insertions(+), 72 deletions(-) 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 a0cd973225..c3b06f0df3 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 @@ -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 = "`"; 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 d515851356..35195c0029 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 @@ -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 values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List 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 { 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 09262c8cbd..2fd5de9de7 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 @@ -23,6 +23,7 @@ + @@ -85,7 +86,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, collection_id, deleted, case_id, error_message, rerun + end_time, executor, collection_id, deleted, case_id, error_message, rerun, create_time @@ -340,6 +347,9 @@ rerun = #{record.rerun,jdbcType=BIT}, + + create_time = #{record.createTime,jdbcType=BIGINT}, + @@ -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} @@ -435,6 +446,9 @@ rerun = #{rerun,jdbcType=BIT}, + + create_time = #{createTime,jdbcType=BIGINT}, + where id = #{id,jdbcType=VARCHAR} @@ -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} 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 (#{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}) @@ -552,6 +568,9 @@ #{item.rerun,jdbcType=BIT} + + #{item.createTime,jdbcType=BIGINT} + ) 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 3f28683a34..db93ff78d9 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 @@ -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 '是否是并行执行'; diff --git a/backend/framework/domain/src/main/resources/migration/3.5.0/dml/V3.5.0_2_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.5.0/dml/V3.5.0_2_1__data.sql index 86f467391a..f5ca3e00bc 100644 --- a/backend/framework/domain/src/main/resources/migration/3.5.0/dml/V3.5.0_2_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.5.0/dml/V3.5.0_2_1__data.sql @@ -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; \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java index 39193ecaf4..c39a8d6f41 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java @@ -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> 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 page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort); return PageUtils.setPageInfo(page, apiTestCaseService.getExecuteList(request)); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index 3f0ff25211..798e5ce07b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -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> 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 page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), sort); return PageUtils.setPageInfo(page, apiScenarioService.getExecuteList(request)); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java index e2a6fd2ef0..63bd0134fe 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java @@ -107,5 +107,6 @@ public interface ExtApiScenarioMapper { List userCreateApiScenarioCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("userIds") Set userIds); List getSimpleApiScenarioList(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime); + List selectExecHistory(@Param("request") ExecutePageRequest request); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml index 8589a23342..f3642645ee 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml @@ -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, diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java index ee35346bae..dde4a478cf 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiCommonService.java @@ -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); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index ac65f74b7d..af599aa3b5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -617,7 +617,7 @@ public class ApiTestCaseService extends MoveNodeService { ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); example.createCriteria().andTaskResourceIdIn(resourceIds); List 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; } diff --git a/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql b/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql index 0a1c647a6c..4738723cdb 100644 --- a/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql +++ b/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql @@ -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); diff --git a/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql b/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql index e56ad157a5..7ecc2b37b5 100644 --- a/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql +++ b/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql @@ -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`) diff --git a/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql b/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql index 421efe864b..7d2773d351 100644 --- a/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql +++ b/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql @@ -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'); diff --git a/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql b/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql index 2efcb3c2a1..85a6e3919d 100644 --- a/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql +++ b/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql @@ -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 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java index be40fdf9e4..e646581ff6 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java @@ -66,11 +66,11 @@ public interface ExtExecTaskItemMapper { long getUnDeleteScenarioExecCount(@Param("projectId") String projectId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("resourceTypes") List 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 selectRerunCollectionIds(@Param("taskId") String taskId); List selectIdAndResourceIdByTaskId(@Param("taskId") String taskId); + + void deleteRerunTaskItem(@Param("taskId") String taskId, String userId); } 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 615906521f..68ff154f38 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 @@ -10,7 +10,7 @@ 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 #{resourceId} @@ -32,7 +32,7 @@ select id, task_id, `status`, result from exec_task_item - where task_id in + where deleted = false and task_id in #{taskId} @@ -333,27 +333,21 @@ where task_id = #{taskId} and deleted = false - - 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' - + + 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' + - - 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 - + + update exec_task_item + set deleted = true + where task_id = #{taskId} and `result` = 'ERROR' and rerun = false + \ No newline at end of file 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 23e9a17513..29c30805b6 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 @@ -198,7 +198,9 @@ public class BaseTaskHubService { List 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 taskItemMap = taskItems.stream().collect(Collectors.toMap(ExecTaskItem::getTaskId, ExecTaskItem::getId)); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/ExecTaskService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/ExecTaskService.java index 147b5171cb..4160b173ee 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/ExecTaskService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/ExecTaskService.java @@ -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); } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java index 3c9d846d33..4d27aebdd0 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java @@ -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); diff --git a/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql index d51779e117..3c5ad162e1 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql @@ -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`)