From 8504c5b089ec55b8847f3d7ba6a0ee5a6a613376 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 10 Oct 2024 11:49:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E4=BB=BB=E5=8A=A1=E8=AF=A6=E6=83=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/system/domain/ExecTask.java | 2 - .../system/domain/ExecTaskItem.java | 6 ++ .../system/domain/ExecTaskItemExample.java | 70 +++++++++++++++++++ .../system/mapper/ExecTaskItemMapper.xml | 53 +++++++++----- .../migration/3.4.0/ddl/V3.4.0_2__ga_ddl.sql | 2 + .../controller/SystemTaskHubController.java | 9 +++ .../system/dto/taskhub/TaskHubItemDTO.java | 32 +++++++++ .../taskhub/request/TaskHubItemRequest.java | 24 +++++++ .../system/mapper/ExtExecTaskItemMapper.java | 16 +++++ .../system/mapper/ExtExecTaskItemMapper.xml | 24 +++++++ .../system/service/BaseTaskHubService.java | 21 ++++++ .../BaseTaskHubControllerTests.java | 23 ++++++ .../resources/dml/init_exec_task_test.sql | 5 ++ 13 files changed, 268 insertions(+), 19 deletions(-) create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubItemDTO.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/request/TaskHubItemRequest.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskItemMapper.xml 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 e5233d2d2e..232b461456 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 @@ -31,8 +31,6 @@ public class ExecTask implements Serializable { private String status; @Schema(description = "用例数量", requiredMode = Schema.RequiredMode.REQUIRED) - @NotBlank(message = "{exec_task.case_count.not_blank}", groups = {Created.class}) - @Size(min = 1, max = 19, message = "{exec_task.case_count.length_range}", groups = {Created.class, Updated.class}) private Long caseCount; @Schema(description = "执行结果") 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 87f74a4ac9..b02f04491c 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 @@ -27,6 +27,11 @@ public class ExecTaskItem implements Serializable { @Size(min = 1, max = 50, message = "{exec_task_item.resource_id.length_range}", groups = {Created.class, Updated.class}) private String resourceId; + @Schema(description = "资源名称", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{exec_task_item.resource_name.not_blank}", groups = {Created.class}) + @Size(min = 1, max = 255, message = "{exec_task_item.resource_name.length_range}", groups = {Created.class, Updated.class}) + private String resourceName; + @Schema(description = "任务来源(任务组下的任务id)") private String taskOrigin; @@ -81,6 +86,7 @@ public class ExecTaskItem implements Serializable { id("id", "id", "VARCHAR", false), taskId("task_id", "taskId", "VARCHAR", false), resourceId("resource_id", "resourceId", "VARCHAR", false), + resourceName("resource_name", "resourceName", "VARCHAR", false), taskOrigin("task_origin", "taskOrigin", "VARCHAR", false), status("status", "status", "VARCHAR", true), result("result", "result", "VARCHAR", true), 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 05a019317f..0beeb8dc0e 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 @@ -314,6 +314,76 @@ public class ExecTaskItemExample { return (Criteria) this; } + public Criteria andResourceNameIsNull() { + addCriterion("resource_name is null"); + return (Criteria) this; + } + + public Criteria andResourceNameIsNotNull() { + addCriterion("resource_name is not null"); + return (Criteria) this; + } + + public Criteria andResourceNameEqualTo(String value) { + addCriterion("resource_name =", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameNotEqualTo(String value) { + addCriterion("resource_name <>", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameGreaterThan(String value) { + addCriterion("resource_name >", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameGreaterThanOrEqualTo(String value) { + addCriterion("resource_name >=", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameLessThan(String value) { + addCriterion("resource_name <", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameLessThanOrEqualTo(String value) { + addCriterion("resource_name <=", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameLike(String value) { + addCriterion("resource_name like", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameNotLike(String value) { + addCriterion("resource_name not like", value, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameIn(List values) { + addCriterion("resource_name in", values, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameNotIn(List values) { + addCriterion("resource_name not in", values, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameBetween(String value1, String value2) { + addCriterion("resource_name between", value1, value2, "resourceName"); + return (Criteria) this; + } + + public Criteria andResourceNameNotBetween(String value1, String value2) { + addCriterion("resource_name not between", value1, value2, "resourceName"); + return (Criteria) this; + } + public Criteria andTaskOriginIsNull() { addCriterion("task_origin is null"); return (Criteria) this; 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 22ea7706f0..0b3a5a1d2f 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 @@ -5,6 +5,7 @@ + @@ -77,8 +78,9 @@ - id, task_id, resource_id, task_origin, `status`, `result`, resource_pool_id, resource_pool_node, - resource_type, project_id, organization_id, thread_id, start_time, end_time, executor + 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 + SELECT * + FROM exec_task_item + + + and ( + exec_task_item.task_id like concat('%', #{request.keyword},'%') + or exec_task_item.resource_name like concat('%', #{request.keyword},'%') + ) + + + and exec_task_item.organization_id = #{orgId} + + + and exec_task_item.project_id = #{projectId} + + + + + \ 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 f6f353c6cc..2a630b4ffc 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 @@ -8,7 +8,9 @@ import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; +import io.metersphere.system.dto.taskhub.TaskHubItemDTO; import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; +import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.mapper.*; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; @@ -46,6 +48,8 @@ public class BaseTaskHubService { UserLoginService userLoginService; @Resource private SqlSessionFactory sqlSessionFactory; + @Resource + private ExtExecTaskItemMapper extExecTaskItemMapper; /** * 系统-获取执行任务列表 @@ -153,4 +157,21 @@ public class BaseTaskHubService { sqlSession.flushStatements(); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } + + + /** + * 用例任务详情列表查询 + * + * @param request + * @return + */ + public Pager> getCaseTaskItemList(TaskHubItemRequest request, String orgId, String projectId) { + Page page = PageMethod.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "id asc"); + return PageUtils.setPageInfo(page, getCaseTaskItemPage(request, orgId, projectId)); + } + + private List getCaseTaskItemPage(TaskHubItemRequest request, String orgId, String projectId) { + return extExecTaskItemMapper.selectList(request, orgId, projectId); + } } 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 3ca30ff11f..2ca5fdeee3 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 @@ -6,6 +6,7 @@ import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.ExecTaskItem; import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.taskhub.request.TaskHubItemRequest; import io.metersphere.system.service.BaseTaskHubService; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; @@ -32,6 +33,7 @@ public class BaseTaskHubControllerTests extends BaseTest { */ public static final String SYSTEM_TASK_PAGE = "/system/task-center/exec-task/page"; public static final String SYSTEM_SCHEDULE_TASK_PAGE = "/system/task-center/schedule/page"; + public static final String SYSTEM_TASK_ITEM_PAGE = "/system/task-center/exec-task/item/page"; @Test @Order(1) @@ -69,6 +71,26 @@ public class BaseTaskHubControllerTests extends BaseTest { } + /** + * 系统后台任务 + */ + @Test + @Order(3) + public void getSystemTaskItemPage() throws Exception { + TaskHubItemRequest request = new TaskHubItemRequest(); + request.setTaskId("1"); + this.requestPost(SYSTEM_TASK_ITEM_PAGE, request); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_ITEM_PAGE, request); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + /** * 组织任务中心测试用例 */ @@ -124,6 +146,7 @@ public class BaseTaskHubControllerTests extends BaseTest { execTaskItem.setProjectId("1234"); execTaskItem.setOrganizationId("1234123"); execTaskItem.setExecutor("admin"); + execTaskItem.setResourceName("测试"); baseTaskHubService.insertExecTaskAndDetail(List.of(execTaskItem)); 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 af06bcec2b..d17071cc9f 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 @@ -14,3 +14,8 @@ VALUES ('wx_3', 'wx_key_3', 'cron', '50 15 10 20 05 ?', 'JobClass22', 'DEMAND_SYNC', b'1', 'NONE', 'admin', 1640778100000, 1640779100000, '100001100001', 'Schedule 22', '', 102), ('wx_4', 'wx_key_4', 'cron', '59 46 16 01 06 ?', 'JobClass29', 'API_SCENARIO', b'1', 'NONE', 'admin', 1640778800000, 1640779800000, '100001100001', 'Schedule 29', '{\"param1\": \"value1\", \"param2\": \"value2\"}', 103), ('wx_5', 'wx_key_5', 'cron', '59 46 16 01 06 ?', 'JobClass29', 'TEST_PLAN', b'1', 'NONE', 'admin', 1640778800000, 1640779800000, '100001100001', 'Schedule 29', '{\"param1\": \"value1\", \"param2\": \"value2\"}', 104); + + + +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`) +VALUES ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '1', '1', '1', NULL, NULL, 'admin');