From de928b3bcc3a7c2a91423d507e2c7a16f982024a Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Sat, 12 Oct 2024 17:37:47 +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&=E9=A1=B9=E7=9B=AE=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B1=A0=E4=B8=8B=E6=8B=89=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectTaskHubController.java | 14 +++-- .../ProjectTaskHubControllerTests.java | 15 +++++ .../OrganizationTaskHubController.java | 14 +++-- .../controller/SystemTaskHubController.java | 3 +- .../system/dto/taskhub/TaskHubItemDTO.java | 3 + .../system/mapper/ExtExecTaskItemMapper.xml | 5 +- .../system/mapper/ExtResourcePoolMapper.java | 5 ++ .../system/mapper/ExtResourcePoolMapper.xml | 27 +++++++++ .../system/service/BaseTaskHubService.java | 58 ++++++++++++++++++- .../BaseTaskHubControllerTests.java | 16 +++++ 10 files changed, 145 insertions(+), 15 deletions(-) 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 index 193bbb1669..936a64b1e0 100644 --- 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 @@ -2,6 +2,7 @@ package io.metersphere.project.controller; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.sdk.BasePageRequest; +import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; import io.metersphere.system.dto.taskhub.TaskHubItemDTO; import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; @@ -17,10 +18,7 @@ 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 org.springframework.web.bind.annotation.*; import java.util.List; @@ -62,4 +60,12 @@ public class ProjectTaskHubController { public List calculateRate(@RequestBody List ids) { return baseTaskHubService.calculateRate(ids, null, SessionUtils.getCurrentProjectId()); } + + + @GetMapping("/resource-pool/options") + @Operation(summary = "项目-任务中心-获取资源池下拉选项") + @RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_READ) + public List getUserProject() { + return baseTaskHubService.getProjectResourcePoolOptions(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 index 07315dac33..5e2eee13ca 100644 --- 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 @@ -23,6 +23,7 @@ public class ProjectTaskHubControllerTests extends BaseTest { public static final String PROJECT_SCHEDULE_TASK_PAGE = "/project/task-center/schedule/page"; public static final String PROJECT_TASK_ITEM_PAGE = "/project/task-center/exec-task/item/page"; public static final String PROJECT_STATISTICS = "/project/task-center/exec-task/statistics"; + public static final String PROJECT_RESOURCE_POOL_OPTIONS = "/project/task-center/resource-pool/options"; @Test @Order(1) @@ -91,4 +92,18 @@ public class ProjectTaskHubControllerTests extends BaseTest { // 返回请求正常 Assertions.assertNotNull(resultHolder); } + + /** + * 组织获取资源池下拉选项 + */ + @Test + @Order(5) + public void getOrgResourcePoolOptions() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(PROJECT_RESOURCE_POOL_OPTIONS); + // 获取返回值 + 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/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java index 7aac27af9a..8c581d1c80 100644 --- 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 @@ -3,6 +3,7 @@ package io.metersphere.system.controller; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.sdk.OptionDTO; +import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; import io.metersphere.system.dto.taskhub.TaskHubItemDTO; import io.metersphere.system.dto.taskhub.TaskHubScheduleDTO; @@ -19,10 +20,7 @@ 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 org.springframework.web.bind.annotation.*; import java.util.List; @@ -69,4 +67,12 @@ public class OrganizationTaskHubController { public List calculateRate(@RequestBody List ids) { return baseTaskHubService.calculateRate(ids, SessionUtils.getCurrentOrganizationId(), null); } + + + @GetMapping("/resource-pool/options") + @Operation(summary = "组织-任务中心-获取资源池下拉选项") + @RequiresPermissions(PermissionConstants.ORGANIZATION_CASE_TASK_CENTER_READ) + public List getUserProject() { + return baseTaskHubService.getOrgResourcePoolOptions(SessionUtils.getCurrentOrganizationId()); + } } 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 e061f1dd03..99bd836215 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 @@ -63,14 +63,13 @@ public class SystemTaskHubController { @GetMapping("/resource-pool/options") @Operation(summary = "系统-任务中心-获取资源池下拉选项") + @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ) public List getUserProject() { return baseTaskHubService.getResourcePoolOptions(); } //TODO 检查节点状态 - //TODO 组织&项目 获取资源池下拉选项 - //TODO 系统&组织&项目 任务按钮操作:删除 停止 失败重跑 查看报告 批量删除 批量停止 批量失败重跑 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubItemDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubItemDTO.java index 18feabf79e..427da2ed08 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubItemDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskhub/TaskHubItemDTO.java @@ -10,6 +10,9 @@ import lombok.Data; @Data public class TaskHubItemDTO extends ExecTaskItem { + @Schema(description = "业务id") + private Long num; + @Schema(description = "任务名称") private String taskName; 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 099010796d..2dd1d6181f 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 @@ -3,12 +3,13 @@ + SELECT id, name + FROM test_resource_pool + where deleted = false + + and (all_org = true or id + + #{poolId} + + ) + + + and all_org = true + + + + + + \ 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 36dc4560b5..1d4a2f141f 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 @@ -2,6 +2,9 @@ package io.metersphere.system.service; import com.github.pagehelper.Page; import com.github.pagehelper.page.PageMethod; +import io.metersphere.project.domain.ProjectTestResourcePool; +import io.metersphere.project.domain.ProjectTestResourcePoolExample; +import io.metersphere.project.mapper.ProjectTestResourcePoolMapper; import io.metersphere.sdk.constants.ExecStatus; import io.metersphere.sdk.constants.ResultStatus; import io.metersphere.sdk.util.JSON; @@ -59,6 +62,12 @@ public class BaseTaskHubService { private TestResourcePoolMapper testResourcePoolMapper; @Resource private TestResourcePoolBlobMapper testResourcePoolBlobMapper; + @Resource + private TestResourcePoolOrganizationMapper testResourcePoolOrganizationMapper; + @Resource + private ExtResourcePoolMapper extResourcePoolMapper; + @Resource + private ProjectTestResourcePoolMapper projectTestResourcePoolMapper; /** * 系统-获取执行任务列表 @@ -230,15 +239,19 @@ public class BaseTaskHubService { TestResourcePoolExample example = new TestResourcePoolExample(); example.createCriteria().andDeletedEqualTo(false); List allResourcePools = testResourcePoolMapper.selectByExample(example); + Map> poolMap = getPoolMap(allResourcePools); + return handleOptions(allResourcePools, poolMap); + + } + + private Map> getPoolMap(List allResourcePools) { List ids = allResourcePools.stream().map(TestResourcePool::getId).toList(); //获取全部资源池节点 TestResourcePoolBlobExample blobExample = new TestResourcePoolBlobExample(); blobExample.createCriteria().andIdIn(ids); List testResourcePoolBlobs = testResourcePoolBlobMapper.selectByExampleWithBLOBs(blobExample); Map> poolMap = testResourcePoolBlobs.stream().collect(Collectors.groupingBy(TestResourcePoolBlob::getId)); - - return handleOptions(allResourcePools, poolMap); - + return poolMap; } private List handleOptions(List allResourcePools, Map> poolMap) { @@ -264,4 +277,43 @@ public class BaseTaskHubService { return options; } + + /** + * 获取组织下的资源池及节点下拉选项 + * + * @param orgId + * @return + */ + public List getOrgResourcePoolOptions(String orgId) { + TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample(); + example.createCriteria().andOrgIdEqualTo(orgId); + List orgPools = testResourcePoolOrganizationMapper.selectByExample(example); + List poolIds = orgPools.stream().map(TestResourcePoolOrganization::getTestResourcePoolId).toList(); + List allResourcePools = extResourcePoolMapper.selectAllResourcePool(poolIds); + if (CollectionUtils.isEmpty(allResourcePools)) { + return null; + } + Map> poolMap = getPoolMap(allResourcePools); + return handleOptions(allResourcePools, poolMap); + } + + + /** + * 获取项目下的资源池及节点下拉选项 + * + * @param projectId + * @return + */ + public List getProjectResourcePoolOptions(String projectId) { + ProjectTestResourcePoolExample example = new ProjectTestResourcePoolExample(); + example.createCriteria().andProjectIdEqualTo(projectId); + List projectPools = projectTestResourcePoolMapper.selectByExample(example); + List poolIds = projectPools.stream().map(ProjectTestResourcePool::getTestResourcePoolId).toList(); + if (CollectionUtils.isNotEmpty(poolIds)) { + List allResourcePools = extResourcePoolMapper.selectProjectAllResourcePool(poolIds); + Map> poolMap = getPoolMap(allResourcePools); + return handleOptions(allResourcePools, poolMap); + } + return null; + } } 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 d93aff78d5..290ff68d28 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 @@ -129,6 +129,7 @@ public class BaseTaskHubControllerTests extends BaseTest { public static final String ORG_SCHEDULE_TASK_PAGE = "/organization/task-center/schedule/page"; public static final String ORG_TASK_ITEM_PAGE = "/organization/task-center/exec-task/item/page"; public static final String ORG_STATISTICS = "/organization/task-center/exec-task/statistics"; + public static final String ORG_RESOURCE_POOL_OPTIONS = "/organization/task-center/resource-pool/options"; @Test @Order(20) @@ -198,6 +199,21 @@ public class BaseTaskHubControllerTests extends BaseTest { } + /** + * 组织获取资源池下拉选项 + */ + @Test + @Order(5) + public void getOrgResourcePoolOptions() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(ORG_RESOURCE_POOL_OPTIONS); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + @Test @Order(21) public void testInsert() throws Exception {