diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java index 99031b4339..15bdf24724 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/ApiTestController.java @@ -11,6 +11,7 @@ import io.metersphere.project.dto.environment.EnvironmentConfig; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.dto.api.task.TaskRequestDTO; +import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.dto.ProtocolDTO; import io.metersphere.system.security.CheckOwner; import io.swagger.v3.oas.annotations.Operation; @@ -107,4 +108,30 @@ public class ApiTestController { public EnvironmentConfig getEnvironmentConfig(@PathVariable String environmentId) { return apiTestService.getEnvironmentConfig(environmentId); } + + @GetMapping("/pool-option/{projectId}") + @Operation(summary = "接口测试-获取资源池") + @RequiresPermissions(value = { + PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE, + PermissionConstants.PROJECT_API_DEFINITION_EXECUTE, + PermissionConstants.PROJECT_API_SCENARIO_EXECUTE + }, logical = Logical.OR) + @CheckOwner(resourceId = "#projectId", resourceType = "project") + public List getPool(@PathVariable String projectId) { + return apiTestService.getPoolOption(projectId); + } + + @GetMapping("/get-pool/{projectId}") + @Operation(summary = "接口测试-获取资源池") + @RequiresPermissions(value = { + PermissionConstants.PROJECT_API_DEFINITION_CASE_EXECUTE, + PermissionConstants.PROJECT_API_DEFINITION_EXECUTE, + PermissionConstants.PROJECT_API_SCENARIO_EXECUTE + }, logical = Logical.OR) + @CheckOwner(resourceId = "#projectId", resourceType = "project") + public String getPoolId(@PathVariable String projectId) { + return apiTestService.getPoolId(projectId); + } + + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java index 0310794ee5..03e4e4146b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTestService.java @@ -9,9 +9,13 @@ import io.metersphere.plugin.api.spi.AbstractApiPlugin; import io.metersphere.plugin.api.spi.AbstractProtocolPlugin; import io.metersphere.project.dto.environment.EnvironmentConfig; import io.metersphere.project.mapper.ExtEnvironmentMapper; +import io.metersphere.project.mapper.ExtProjectMapper; import io.metersphere.project.service.EnvironmentService; +import io.metersphere.project.service.ProjectApplicationService; +import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.dto.ProtocolDTO; import io.metersphere.system.service.ApiPluginService; import io.metersphere.system.service.PluginLoadService; @@ -22,7 +26,9 @@ import org.pf4j.PluginWrapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author jianxing @@ -40,6 +46,10 @@ public class ApiTestService { private ExtEnvironmentMapper extEnvironmentMapper; @Resource private EnvironmentService environmentService; + @Resource + private ExtProjectMapper extProjectMapper; + @Resource + private ProjectApplicationService projectApplicationService; public List getProtocols(String orgId) { List protocols = apiPluginService.getProtocols(orgId); @@ -99,4 +109,15 @@ public class ApiTestService { newEnvironmentConfig.setDataSources(environmentConfig.getDataSources()); return newEnvironmentConfig; } + + public List getPoolOption(String projectId) { + //获取资源池 + return extProjectMapper.getResourcePoolOption(projectId, "api_test"); + } + + public String getPoolId(String projectId) { + Map configMap = new HashMap<>(); + projectApplicationService.putResourcePool(projectId, configMap, "apiTest"); + return (String) configMap.get(ProjectApplicationType.API.API_RESOURCE_POOL_ID.name()); + } } \ No newline at end of file diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java index 524101dd6c..6032d13116 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiTestControllerTests.java @@ -223,4 +223,16 @@ public class ApiTestControllerTests extends BaseTest { Assertions.assertNull(environmentConfig.getAssertionConfig()); } + @Test + public void getPoolOption() throws Exception { + // @@请求成功 + this.requestGet("/pool-option/" + DEFAULT_PROJECT_ID); + } + + @Test + public void getPoolId() throws Exception { + // @@请求成功 + this.requestGet("/get-pool/" + DEFAULT_PROJECT_ID); + } + } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java index a6f7889348..a8405390f8 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java @@ -2,6 +2,7 @@ package io.metersphere.project.mapper; import io.metersphere.project.domain.Project; import io.metersphere.project.domain.ProjectTestResourcePool; +import io.metersphere.system.domain.TestResourcePool; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -25,4 +26,7 @@ public interface ExtProjectMapper { List getResourcePool(@Param("projectId") String projectId, @Param("type") String type); List getAllProject(@Param("organizationId") String organizationId); + List getResourcePoolOption(@Param("projectId") String projectId, @Param("type") String type); + + } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml index 5d9f65c918..2782f4c873 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml @@ -84,4 +84,14 @@ order by CONVERT( name USING GBK) ASC + + \ No newline at end of file diff --git a/frontend/src/api/modules/api-test/management.ts b/frontend/src/api/modules/api-test/management.ts index 0d37c2f494..e906462da9 100644 --- a/frontend/src/api/modules/api-test/management.ts +++ b/frontend/src/api/modules/api-test/management.ts @@ -40,11 +40,13 @@ import { GetModuleCountUrl, GetModuleOnlyTreeUrl, GetModuleTreeUrl, + GetPoolId, GetTrashModuleCountUrl, GetTrashModuleTreeUrl, ImportDefinitionUrl, MoveModuleUrl, OperationHistoryUrl, + PoolOption, RecoverCaseUrl, RecoverDefinitionUrl, RecoverOperationHistoryUrl, @@ -115,6 +117,7 @@ import { TableQueryParams, TransferFileParams, } from '@/models/common'; +import { ResourcePoolItem } from '@/models/setting/resourcePool'; // 更新模块 export function updateModule(data: ApiDefinitionUpdateModuleParams) { @@ -460,3 +463,12 @@ export function getApiCaseChangeHistory(data: ApiCaseChangeHistoryParams) { export function getApiCaseDependency(data: ApiCaseDependencyParams) { return MSR.post({ url: GetDependencyUrl, data }); } + +// 获取接口的资源池列表 +export function getPoolOption(projectId: string) { + return MSR.get({ url: PoolOption + projectId }); +} + +export function getPoolId(projectId: string) { + return MSR.get({ url: GetPoolId + projectId }); +} diff --git a/frontend/src/api/requrls/api-test/management.ts b/frontend/src/api/requrls/api-test/management.ts index 1bd53cb892..ffc7231699 100644 --- a/frontend/src/api/requrls/api-test/management.ts +++ b/frontend/src/api/requrls/api-test/management.ts @@ -83,3 +83,6 @@ export const BatchRecoverCaseUrl = '/api/case/batch/recover'; // 接口用例批 export const DeleteRecycleCaseUrl = '/api/case/delete'; // 接口用例彻底删除 export const BatchDeleteRecycleCaseUrl = '/api/case/batch/delete'; // 接口用例批量彻底删除 export const AddCaseUrl = '/api/case/add'; // 添加用例 + +export const PoolOption = '/api/test/pool-option/'; // 获取接口资源池 +export const GetPoolId = '/api/test/get-pool/'; // 获取项目应用设置的资源池id diff --git a/frontend/src/views/api-test/management/components/management/case/caseTable.vue b/frontend/src/views/api-test/management/components/management/case/caseTable.vue index a99980ee71..18e2702a26 100644 --- a/frontend/src/views/api-test/management/components/management/case/caseTable.vue +++ b/frontend/src/views/api-test/management/components/management/case/caseTable.vue @@ -358,18 +358,19 @@ executeCase, getCasePage, getEnvList, + getPoolId, + getPoolOption, updateCasePriority, - updateCaseStatus, updateDefinition, + updateCaseStatus, } from '@/api/modules/api-test/management'; import { getCaseDefaultFields } from '@/api/modules/case-management/featureCase'; - import { getPoolList } from '@/api/modules/setting/resourcePool'; import { useI18n } from '@/hooks/useI18n'; import useModal from '@/hooks/useModal'; import useTableStore from '@/hooks/useTableStore'; import useAppStore from '@/store/modules/app'; import { ApiCaseDetail, Environment } from '@/models/apiTest/management'; - import { DragSortParams, TableQueryParams } from '@/models/common'; + import { DragSortParams } from '@/models/common'; import { ResourcePoolItem } from '@/models/setting/resourcePool'; import { RequestDefinitionStatus } from '@/enums/apiEnum'; import { TableKeyEnum } from '@/enums/tableEnum'; @@ -576,6 +577,7 @@ const environmentList = ref(); const resourcePoolList = ref(); + const defaultPoolId = ref(); const moduleIds = computed(() => { return props.activeModule === 'all' ? [] : [props.activeModule]; @@ -615,22 +617,23 @@ // 初始化资源池列表 async function initPoolList() { - const searchPoolParams = ref({ - current: 1, - pageSize: 10, - keyword: '', - deleted: false, - apiTest: true, - enable: false, - }); - const result = await getPoolList(searchPoolParams.value); - resourcePoolList.value = result.list; + resourcePoolList.value = await getPoolOption(appStore.getCurrentProjectId); + } + + async function getDefaultPoolId() { + try { + defaultPoolId.value = await getPoolId(appStore.getCurrentProjectId); + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } } onBeforeMount(() => { loadCaseList(); initPoolList(); getCaseLevelFields(); + getDefaultPoolId(); }); function handleFilterHidden(val: boolean) { @@ -936,6 +939,7 @@ break; case 'execute': showBatchExecute.value = true; + batchExecuteForm.value.poolId = defaultPoolId.value || ''; initEnvList(); break; default: @@ -974,7 +978,6 @@ :deep(.arco-radio-group) { margin-left: -5px; } - .ms-switch { display: flex; align-items: center;