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; - } - /** * 获取任务详情列表资源节点状态 *