From c07dc552521e640a0dad2716bb56ddbb085f5302 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 30 Sep 2024 15:24:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2&=E9=A1=B9=E7=9B=AE=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=B8=AD=E5=BF=83=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectTaskHubController.java | 32 ++++++++++ .../ProjectTaskHubControllerTests.java | 37 +++++++++++ .../dml/init_project_exec_task_test.sql | 5 ++ .../OrganizationTaskHubController.java | 35 +++++++++++ .../controller/SystemTaskHubController.java | 2 +- .../system/mapper/ExtExecTaskMapper.xml | 2 +- .../system/service/BaseTaskHubService.java | 6 +- .../BaseTaskHubControllerTests.java | 62 +++++++++++++++++++ .../SystemTaskHubControllerTests.java | 35 ----------- .../resources/dml/init_exec_task_test.sql | 5 ++ 10 files changed, 182 insertions(+), 39 deletions(-) create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java create mode 100644 backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java create mode 100644 backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java create mode 100644 backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java delete mode 100644 backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java create mode 100644 backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java new file mode 100644 index 0000000000..63a17e8393 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java @@ -0,0 +1,32 @@ +package io.metersphere.project.controller; + +import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.taskhub.TaskHubDTO; +import io.metersphere.system.service.BaseTaskHubService; +import io.metersphere.system.utils.Pager; +import io.metersphere.system.utils.SessionUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Tag(name = "项目任务中心") +@RestController +@RequestMapping("/project/task-center") +public class ProjectTaskHubController { + + @Resource + private BaseTaskHubService baseTaskHubService; + + @PostMapping("/exec-task/page") + @Operation(summary = "项目-任务中心-执行任务列表") + public Pager> projectList(@Validated @RequestBody BasePageRequest request) { + return baseTaskHubService.getTaskList(request, null, SessionUtils.getCurrentProjectId()); + } +} diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java new file mode 100644 index 0000000000..16b69607a7 --- /dev/null +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java @@ -0,0 +1,37 @@ +package io.metersphere.project.controller; + +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; +import io.metersphere.system.dto.sdk.BasePageRequest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.MvcResult; + +import java.nio.charset.StandardCharsets; + +public class ProjectTaskHubControllerTests extends BaseTest { + /** + * 项目任务中心测试用例 + */ + public static final String PROJECT_TASK_PAGE = "/project/task-center/exec-task/page"; + + @Test + @Order(1) + @Sql(scripts = {"/dml/init_project_exec_task_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) + public void getProjectTaskPage() throws Exception { + BasePageRequest request = new BasePageRequest(); + this.requestPost(PROJECT_TASK_PAGE, request); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_TASK_PAGE, request); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } +} 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 new file mode 100644 index 0000000000..98b74f19bc --- /dev/null +++ b/backend/services/project-management/src/test/resources/dml/init_project_exec_task_test.sql @@ -0,0 +1,5 @@ +INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `result`, `task_type`, `trigger_mode`, `project_id`, `organization_id`, `create_time`, `create_user`, `start_time`, `end_time`) +VALUES + ('pro_1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639), + ('pro_2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639), + ('pro_3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java new file mode 100644 index 0000000000..91b2f3f6d6 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java @@ -0,0 +1,35 @@ +package io.metersphere.system.controller; + +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.taskhub.TaskHubDTO; +import io.metersphere.system.service.BaseTaskHubService; +import io.metersphere.system.utils.Pager; +import io.metersphere.system.utils.SessionUtils; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Tag(name = "组织任务中心") +@RestController +@RequestMapping("/organization/task-center") +public class OrganizationTaskHubController { + + @Resource + private BaseTaskHubService baseTaskHubService; + + @PostMapping("/exec-task/page") + @Operation(summary = "组织-任务中心-执行任务列表") + @RequiresPermissions(PermissionConstants.ORGANIZATION_TASK_CENTER_READ) + public Pager> projectList(@Validated @RequestBody BasePageRequest request) { + return baseTaskHubService.getTaskList(request, SessionUtils.getCurrentOrganizationId(), null); + } +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java index 87d4a5869d..c0a1de5a1a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java @@ -29,7 +29,7 @@ public class SystemTaskHubController { @Operation(summary = "系统-任务中心-执行任务列表") @RequiresPermissions(PermissionConstants.SYSTEM_TASK_CENTER_READ) public Pager> projectList(@Validated @RequestBody BasePageRequest request) { - return baseTaskHubService.getTaskList(request); + return baseTaskHubService.getTaskList(request, null, null); } } 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 767e7ca5dc..47cb68e3b8 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 @@ -15,7 +15,7 @@ and exec_task.organization_id = #{orgId} - and exec_task.projectId = #{projectId} + and exec_task.project_id = #{projectId} 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 b3174eb20a..2d0d77cf80 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 @@ -29,12 +29,14 @@ public class BaseTaskHubService { * 系统-获取执行任务列表 * * @param request + * @param orgId + * @param projectId * @return */ - public Pager> getTaskList(BasePageRequest request) { + public Pager> getTaskList(BasePageRequest request, String orgId, String projectId) { Page page = PageMethod.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); - return PageUtils.setPageInfo(page, getPage(request, null, null)); + return PageUtils.setPageInfo(page, getPage(request, orgId, projectId)); } private List getPage(BasePageRequest request, String orgId, String 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 new file mode 100644 index 0000000000..aec2646ae6 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java @@ -0,0 +1,62 @@ +package io.metersphere.system.controller; + +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; +import io.metersphere.system.dto.sdk.BasePageRequest; +import org.junit.jupiter.api.*; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.MvcResult; + +import java.nio.charset.StandardCharsets; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class BaseTaskHubControllerTests extends BaseTest { + + /** + * 系统任务中心测试用例 + */ + public static final String SYSTEM_TASK_PAGE = "/system/task-center/exec-task/page"; + + @Test + @Order(1) + @Sql(scripts = {"/dml/init_exec_task_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) + public void getSystemTaskPage() throws Exception { + BasePageRequest request = new BasePageRequest(); + this.requestPost(SYSTEM_TASK_PAGE, request); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_PAGE, request); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + + /** + * 组织任务中心测试用例 + */ + public static final String ORG_TASK_PAGE = "/organization/task-center/exec-task/page"; + + @Test + @Order(20) + public void getOrgTaskPage() throws Exception { + BasePageRequest request = new BasePageRequest(); + this.requestPost(ORG_TASK_PAGE, request); + request.setCurrent(1); + request.setPageSize(10); + MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_TASK_PAGE, request); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } +} diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java deleted file mode 100644 index b702f3e5b1..0000000000 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemTaskHubControllerTests.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.metersphere.system.controller; - -import io.metersphere.sdk.util.JSON; -import io.metersphere.system.base.BaseTest; -import io.metersphere.system.controller.handler.ResultHolder; -import io.metersphere.system.dto.sdk.BasePageRequest; -import org.junit.jupiter.api.*; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MvcResult; - -import java.nio.charset.StandardCharsets; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@AutoConfigureMockMvc -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class SystemTaskHubControllerTests extends BaseTest { - - public static final String TASK_PAGE = "/system/task-center/exec-task/page"; - - @Test - @Order(1) - public void getTaskPage() throws Exception { - BasePageRequest request = new BasePageRequest(); - this.requestPost(TASK_PAGE, request); - request.setCurrent(1); - request.setPageSize(10); - MvcResult mvcResult = this.requestPostWithOkAndReturn(TASK_PAGE, request); - // 获取返回值 - String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); - ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); - // 返回请求正常 - Assertions.assertNotNull(resultHolder); - } -} 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 new file mode 100644 index 0000000000..235aad5b21 --- /dev/null +++ b/backend/services/system-setting/src/test/resources/dml/init_exec_task_test.sql @@ -0,0 +1,5 @@ +INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `result`, `task_type`, `trigger_mode`, `project_id`, `organization_id`, `create_time`, `create_user`, `start_time`, `end_time`) +VALUES + ('1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639), + ('2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639), + ('3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639);