From 6c7b8fe6146adde7ab909fa421aa8ed5f47d912e Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 25 Oct 2024 13:49:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=AF=A6=E6=83=85=E5=88=97=E8=A1=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=A1=B9=E7=9B=AE=E4=B8=8B=E8=B5=84=E6=BA=90=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048050 --user=王旭 【项目任务中心】任务详情列表-资源池搜索选项未展示k8s资源池 https://www.tapd.cn/55049933/s/1598006 --- .../controller/ProjectTaskHubController.java | 5 ++- .../project/service/ProjectService.java | 36 ++++++++++++++++--- .../dml/init_project_exec_task_test.sql | 10 +++--- .../system/service/BaseTaskHubService.java | 24 ++----------- 4 files changed, 43 insertions(+), 32 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 23b3a5ef67..c6a1aebbb8 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 com.github.pagehelper.Page; import com.github.pagehelper.page.PageMethod; +import io.metersphere.project.service.ProjectService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.BatchExecTaskReportDTO; import io.metersphere.system.dto.request.BatchExecTaskPageRequest; @@ -45,6 +46,8 @@ public class ProjectTaskHubController { private BaseTaskHubService baseTaskHubService; @Resource private BaseTaskHubLogService baseTaskHubLogService; + @Resource + private ProjectService projectService; @PostMapping("/exec-task/page") @Operation(summary = "项目-任务中心-执行任务列表") @@ -82,7 +85,7 @@ public class ProjectTaskHubController { @Operation(summary = "项目-任务中心-获取资源池下拉选项") @RequiresPermissions(PermissionConstants.PROJECT_CASE_TASK_CENTER_READ) public List getUserProject() { - return baseTaskHubService.getProjectResourcePoolOptions(SessionUtils.getCurrentProjectId()); + return projectService.getProjectResourcePoolOptions(SessionUtils.getCurrentProjectId()); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java index ef40f31b35..c4dcbf766f 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java @@ -13,16 +13,15 @@ import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.Translator; -import io.metersphere.system.domain.TestResourcePool; -import io.metersphere.system.domain.TestResourcePoolExample; -import io.metersphere.system.domain.User; -import io.metersphere.system.domain.UserRoleRelationExample; +import io.metersphere.system.domain.*; import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.SessionUser; +import io.metersphere.system.dto.taskhub.ResourcePoolOptionsDTO; import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.mapper.*; +import io.metersphere.system.service.BaseTaskHubService; import io.metersphere.system.service.CommonProjectService; import io.metersphere.system.service.UserLoginService; import io.metersphere.system.utils.ServiceUtils; @@ -35,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.function.Function; @@ -65,6 +65,8 @@ public class ProjectService { private BaseUserMapper baseUserMapper; public static final Long ORDER_STEP = 5000L; + @Resource + private BaseTaskHubService baseTaskHubService; public List getUserProject(String organizationId, String userId) { @@ -302,5 +304,31 @@ public class ProjectService { return extProjectMapper.getResourcePoolOption(projectId, "api_test"); } } + + /** + * 获取项目下的资源池及节点下拉选项 + * + * @param projectId + * @return + */ + public List getProjectResourcePoolOptions(String projectId) { + List pools = getAllPoolOption(projectId); + if (CollectionUtils.isNotEmpty(pools)) { + Map> poolMap = baseTaskHubService.getPoolMap(pools); + return baseTaskHubService.handleOptions(pools, poolMap); + } + return null; + } + + private List getAllPoolOption(String projectId) { + Project project = projectMapper.selectByPrimaryKey(projectId); + if (project.getAllResourcePool()) { + TestResourcePoolExample example = new TestResourcePoolExample(); + example.createCriteria().andDeletedEqualTo(false); + return testResourcePoolMapper.selectByExample(example); + } else { + return extProjectMapper.getResourcePoolOption(projectId, "api_test"); + } + } } 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 ef7c712978..2efcb3c2a1 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 @@ -1,9 +1,9 @@ -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`) +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`, `integrated`) 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), - ('pro_4', 4, '测试任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API_CASE_BATCH', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639); + ('pro_1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), + ('pro_2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), + ('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`) VALUES 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 a944e64f89..1818a8d600 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 @@ -455,7 +455,7 @@ public class BaseTaskHubService { } - private Map> getPoolMap(List allResourcePools) { + public Map> getPoolMap(List allResourcePools) { List ids = allResourcePools.stream().map(TestResourcePool::getId).toList(); //获取全部资源池节点 TestResourcePoolBlobExample blobExample = new TestResourcePoolBlobExample(); @@ -464,7 +464,7 @@ public class BaseTaskHubService { return testResourcePoolBlobs.stream().collect(Collectors.groupingBy(TestResourcePoolBlob::getId)); } - private List handleOptions(List allResourcePools, Map> poolMap) { + public List handleOptions(List allResourcePools, Map> poolMap) { List options = new ArrayList<>(); allResourcePools.forEach(item -> { ResourcePoolOptionsDTO optionsDTO = new ResourcePoolOptionsDTO(); @@ -507,26 +507,6 @@ public class BaseTaskHubService { 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; - } - /** * 获取任务详情列表资源节点状态 *