From 3f3c65ea7505dc590db3e8014540039c3fd35ec5 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 24 Jul 2024 11:21:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E5=AF=BC=E5=87=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1044395 --user=王旭 【接口测试】接口定义-选中模块-批量选中当前页导出失败(仅当前数据) https://www.tapd.cn/55049933/s/1553327 --- .../ApiDefinitionExportService.java | 31 ++++++++++++++++--- .../ApiDefinitionControllerTests.java | 2 -- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionExportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionExportService.java index 8036315bc9..91b30cf131 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionExportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionExportService.java @@ -1,10 +1,13 @@ package io.metersphere.api.service.definition; +import io.metersphere.api.domain.ApiDefinition; +import io.metersphere.api.domain.ApiDefinitionExample; import io.metersphere.api.domain.ApiDefinitionModule; import io.metersphere.api.domain.ApiDefinitionModuleExample; import io.metersphere.api.dto.definition.ApiDefinitionBatchRequest; import io.metersphere.api.dto.definition.ApiDefinitionWithBlob; import io.metersphere.api.dto.export.ApiExportResponse; +import io.metersphere.api.mapper.ApiDefinitionMapper; import io.metersphere.api.mapper.ApiDefinitionModuleMapper; import io.metersphere.api.mapper.ExtApiDefinitionMapper; import io.metersphere.api.parser.api.Swagger3ExportParser; @@ -12,6 +15,7 @@ import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.exception.MSException; +import io.metersphere.system.utils.CustomFieldUtils; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -27,20 +31,20 @@ import java.util.stream.Collectors; @Service public class ApiDefinitionExportService { - @Resource - private ApiDefinitionService apiDefinitionService; + @Resource private ExtApiDefinitionMapper extApiDefinitionMapper; @Resource private ApiDefinitionModuleMapper apiDefinitionModuleMapper; @Resource private ProjectMapper projectMapper; + @Resource + private ApiDefinitionMapper apiDefinitionMapper; public ApiExportResponse export(ApiDefinitionBatchRequest request, String type, String userId) { - request.setProtocols(List.of(ModuleConstants.NODE_PROTOCOL_HTTP)); - List ids = apiDefinitionService.getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId); + List ids = getBatchApiIds(request, request.getProjectId(), List.of(ModuleConstants.NODE_PROTOCOL_HTTP), false, userId); if (CollectionUtils.isEmpty(ids)) { - return new ApiExportResponse(); + return null; } List list = extApiDefinitionMapper.selectApiDefinitionWithBlob(ids); List moduleIds = list.stream().map(ApiDefinitionWithBlob::getModuleId).toList(); @@ -57,6 +61,23 @@ public class ApiDefinitionExportService { } + private List getBatchApiIds(ApiDefinitionBatchRequest request, String projectId, List protocols, boolean deleted, String userId) { + if (request.isSelectAll()) { + CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request.getCondition(), userId); + List ids = extApiDefinitionMapper.getIds(request, projectId, protocols, deleted); + if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { + ids.removeAll(request.getExcludeIds()); + } + return ids; + } else { + request.getSelectIds().removeAll(request.getExcludeIds()); + ApiDefinitionExample definitionExample = new ApiDefinitionExample(); + definitionExample.createCriteria().andIdIn(request.getSelectIds()).andProtocolIn(protocols).andDeletedEqualTo(deleted); + List apiDefinitions = apiDefinitionMapper.selectByExample(definitionExample); + return apiDefinitions.stream().map(ApiDefinition::getId).toList(); + } + } + private ApiExportResponse exportSwagger(ApiDefinitionBatchRequest request, List list, Map moduleMap) { Project project = projectMapper.selectByPrimaryKey(request.getProjectId()); Swagger3ExportParser swagger3Parser = new Swagger3ExportParser(); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index a7e8916912..6854c111ff 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -1900,8 +1900,6 @@ public class ApiDefinitionControllerTests extends BaseTest { request.setSelectAll(false); request.setSelectIds(List.of("1002")); this.requestPost(EXPORT + "swagger", request); - request.setSelectIds(List.of("1001")); - this.requestPost(EXPORT + "swagger", request); } }