From 82df20db059b27d0ef877d8ec54c20af7a815bfc Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Thu, 1 Feb 2024 16:03:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scenario/ApiScenarioController.java | 10 ++++ .../scenario/ApiScenarioAssociationDTO.java | 26 ++++++++++ .../ApiScenarioAssociationPageRequest.java | 16 ++++++ .../api/mapper/ExtApiScenarioMapper.java | 10 ++-- .../api/mapper/ExtApiScenarioMapper.xml | 23 ++++++++ .../service/scenario/ApiScenarioService.java | 23 ++++++++ .../ApiScenarioControllerTests.java | 52 +++++++++++++++++++ .../OrganizationProjectControllerTests.java | 3 +- .../SystemProjectControllerTests.java | 2 +- 9 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationDTO.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationPageRequest.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index f204867390..ccf6dbd214 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -182,4 +182,14 @@ public class ApiScenarioController { apiValidateService.validateApiMenuInProject(request.getScenarioId(), ApiResource.API_SCENARIO.name()); return apiScenarioService.scheduleConfig(request, SessionUtils.getUserId()); } + + @PostMapping(value = "/association/page") + @Operation(summary = "接口测试-接口场景管理-场景引用关系列表") + @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ) + @CheckOwner(resourceId = "#request.id", resourceType = "api_scenario") + public Pager> getAssociationPage(@Validated @RequestBody ApiScenarioAssociationPageRequest request) { + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "resource_num desc"); + return PageUtils.setPageInfo(page, apiScenarioService.getAssociationPage(request)); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationDTO.java new file mode 100644 index 0000000000..b090231dcc --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationDTO.java @@ -0,0 +1,26 @@ +package io.metersphere.api.dto.scenario; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class ApiScenarioAssociationDTO { + @Schema(description = "编号") + private String resourceNum; + @Schema(description = "资源id") + private String resourceId; + @Schema(description = "资源名称") + private String name; + @Schema(description = "资源类型 ") + private String stepType; + @Schema(description = "引用类型 COPY:复制,REF:引用") + private String refType; + @Schema(description = "项目名称") + private String projectName; + @Schema(description = "项目id") + private String projectId; + + +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationPageRequest.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationPageRequest.java new file mode 100644 index 0000000000..62b272ffe0 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/scenario/ApiScenarioAssociationPageRequest.java @@ -0,0 +1,16 @@ +package io.metersphere.api.dto.scenario; + +import io.metersphere.system.dto.sdk.BasePageRequest; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class ApiScenarioAssociationPageRequest extends BasePageRequest { + + @Schema(description = "场景pk") + @Size(min = 1, max = 50, message = "{api_scenario_step.scenario_id.length_range}") + private String id; +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java index d07e18c5d1..f731cd9140 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java @@ -1,16 +1,14 @@ package io.metersphere.api.mapper; import io.metersphere.api.domain.ApiScenario; -import io.metersphere.api.dto.scenario.ApiScenarioBatchRequest; -import io.metersphere.api.dto.scenario.ApiScenarioDTO; -import io.metersphere.api.dto.scenario.ApiScenarioPageRequest; -import io.metersphere.system.dto.taskcenter.TaskCenterDTO; -import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest; +import io.metersphere.api.dto.scenario.*; import io.metersphere.dto.TestCaseProviderDTO; import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.request.AssociateOtherCaseRequest; import io.metersphere.request.TestCasePageProviderRequest; import io.metersphere.system.dto.sdk.BaseTreeNode; +import io.metersphere.system.dto.taskcenter.TaskCenterDTO; +import io.metersphere.system.dto.taskcenter.request.TaskCenterPageRequest; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -35,4 +33,6 @@ public interface ExtApiScenarioMapper { Long getLastPos(@Param("projectId") String projectId); List taskCenterlist(@Param("request") TaskCenterPageRequest request, @Param("projectIds") List projectIds); + + List getAssociationPage(@Param("request") ApiScenarioAssociationPageRequest request); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml index 6d7c97a78f..e853da7314 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml @@ -417,6 +417,29 @@ + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 6a5a59d267..3e5ead0303 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -23,8 +23,11 @@ import io.metersphere.api.service.definition.ApiTestCaseService; import io.metersphere.api.utils.ApiScenarioBatchOperationUtils; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.domain.FileMetadata; +import io.metersphere.project.domain.Project; +import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.dto.environment.EnvironmentInfoDTO; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.service.*; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.domain.Environment; @@ -141,6 +144,8 @@ public class ApiScenarioService { private EnvironmentGroupService environmentGroupService; @Resource private ApiPluginService apiPluginService; + @Resource + private ProjectMapper projectMapper; public static final String PRIORITY = "Priority"; public static final String STATUS = "Status"; @@ -1186,6 +1191,7 @@ public class ApiScenarioService { /** * 从 scenarioParseEnvInfo 获取对应环境组的 projectEnvMap + * * @param scenarioParseEnvInfo * @param environmentId * @return @@ -1834,4 +1840,21 @@ public class ApiScenarioService { ApiScenarioScheduleJob.class, operator); } + + public List getAssociationPage(ApiScenarioAssociationPageRequest request) { + List list = extApiScenarioMapper.getAssociationPage(request); + if (CollectionUtils.isNotEmpty(list)) { + //获取所有的项目ID + List projectIds = list.stream().map(ApiScenarioAssociationDTO::getProjectId).distinct().toList(); + ProjectExample example = new ProjectExample(); + example.createCriteria().andIdIn(projectIds); + List projects = projectMapper.selectByExample(example); + Map projectMap = projects.stream().collect(Collectors.toMap(Project::getId, Function.identity())); + list.forEach(apiScenarioAssociationDTO -> { + apiScenarioAssociationDTO.setProjectName(projectMap.get(apiScenarioAssociationDTO.getProjectId()).getName()); + }); + } + + return list; + } } \ No newline at end of file diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index dc891cf7b6..83418553ae 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -878,6 +878,57 @@ public class ApiScenarioControllerTests extends BaseTest { requestPostPermissionTest(PermissionConstants.PROJECT_API_SCENARIO_READ, DEFAULT_PAGE, pageRequest); } + + @Test + @Order(11) + public void testGetAssociatedCase() throws Exception { + for (int i = 0; i < 2; i++) { + ApiScenario apiScenario = new ApiScenario(); + apiScenario.setId("test-api-scenario-id" + i); + apiScenario.setProjectId(DEFAULT_PROJECT_ID); + apiScenario.setNum(NumGenerator.nextNum(DEFAULT_PROJECT_ID, ApplicationNumScope.API_SCENARIO)); + apiScenario.setName(StringUtils.join("建国批量测试接口场景-", apiScenario.getId())); + apiScenario.setModuleId("test-associated"); + apiScenario.setStatus("未规划"); + apiScenario.setPos(1L); + apiScenario.setPriority("P0"); + apiScenario.setLatest(true); + apiScenario.setVersionId("1.0"); + apiScenario.setRefId(apiScenario.getId()); + apiScenario.setCreateTime(System.currentTimeMillis()); + apiScenario.setUpdateTime(System.currentTimeMillis()); + apiScenario.setCreateUser("admin"); + apiScenario.setUpdateUser("admin"); + apiScenarioMapper.insertSelective(apiScenario); + } + for (int i = 0; i < 10; i++) { + ApiScenarioStep step1 = new ApiScenarioStep(); + step1.setId(IDGenerator.nextStr()); + step1.setScenarioId("test-api-scenario-id1"); + step1.setName("test" + "_" + IDGenerator.nextStr()); + step1.setSort(0L); + step1.setEnable(true); + step1.setResourceId("test-api-scenario-id0"); + step1.setResourceNum("test-resource-num"); + if (i % 2 == 0) { + step1.setRefType("COPY"); + } else { + step1.setRefType("REF"); + } + step1.setProjectId(DEFAULT_PROJECT_ID); + apiScenarioStepMapper.insertSelective(step1); + } + ApiScenarioAssociationPageRequest request = new ApiScenarioAssociationPageRequest(); + request.setPageSize(10); + request.setCurrent(1); + this.requestPost("/association/page", request, status().is4xxClientError()); + request.setId("test-api-scenario-id1"); + this.requestPostAndReturn("/association/page", request); + request.setId("test-api-scenario-id0"); + this.requestPostAndReturn("association/page", request); + + } + @Test @Order(12) public void follow() throws Exception { @@ -1943,4 +1994,5 @@ public class ApiScenarioControllerTests extends BaseTest { BATCH_OPERATION_SCENARIO_ID.add(apiScenario.getId()); } } + } \ No newline at end of file diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java index 75ad442130..e4fdc2f825 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java @@ -966,8 +966,9 @@ public class OrganizationProjectControllerTests extends BaseTest { @Order(23) public void testGetOptions() throws Exception { ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest(); - projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest")); projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID); + this.requestPost(getPoolOptions, projectPoolRequest, BAD_REQUEST_MATCHER); + projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest")); this.responsePost(getPoolOptions, projectPoolRequest); // @@校验权限 requestPostPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, getPoolOptions, projectPoolRequest); diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java index 07ce0fbff0..39f34d4e73 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java @@ -1097,8 +1097,8 @@ public class SystemProjectControllerTests extends BaseTest { @Order(22) public void testGetOptions() throws Exception { ProjectPoolRequest projectPoolRequest = new ProjectPoolRequest(); + this.requestPost(getPoolOptions, projectPoolRequest, BAD_REQUEST_MATCHER); projectPoolRequest.setModulesIds(List.of("apiTest", "uiTest", "loadTest")); - this.responsePost(getPoolOptions, projectPoolRequest); projectPoolRequest.setOrganizationId(DEFAULT_ORGANIZATION_ID); this.responsePost(getPoolOptions, projectPoolRequest); // @@校验权限