From 7598c6d87c1b08a66e3275903669a289f494024f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 3 Apr 2023 17:04:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E5=AF=BC=E5=87=BAAPI=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1025069 --user=赵勇 【接口测试】导出全部api数据3000+-导出失败 https://www.tapd.cn/55049933/s/1358748 Signed-off-by: fit2-zhao --- .../mapper/ext/ExtMockExpectConfigMapper.java | 3 ++- .../mapper/ext/ExtMockExpectConfigMapper.xml | 18 +++++++++++------- .../metersphere/service/MockConfigService.java | 12 +----------- .../definition/ApiDefinitionService.java | 9 +-------- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.java index 30afcec229..4d9f018ef2 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.java @@ -1,5 +1,6 @@ package io.metersphere.base.mapper.ext; +import io.metersphere.api.dto.mock.config.MockConfigImportDTO; import io.metersphere.base.domain.MockExpectConfigWithBLOBs; import org.apache.ibatis.annotations.Param; @@ -11,7 +12,7 @@ public interface ExtMockExpectConfigMapper { List selectByApiId(String apiId); - List selectByApiIdIn(@Param("values") List apiIds); + List selectByApiIdIn(@Param("values") List apiIds); List selectExlectNumByMockConfigId(String mockConfigId); diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.xml index 395b9599a1..0c7ea7b06d 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtMockExpectConfigMapper.xml @@ -12,13 +12,17 @@ SELECT id FROM mock_config WHERE api_id = #{0} ) - + SELECT + mock_expect_config.*, + mock_config.api_id AS apiId + FROM + mock_expect_config + LEFT JOIN mock_config ON mock_expect_config.mock_config_id = mock_config.id + WHERE mock_config.api_id in ( + + #{value} + ) diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index 98a920414b..d536fa06cc 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -95,17 +95,7 @@ public class MockConfigService { public List selectMockExpectConfigByApiIdIn(List apiIds) { if (CollectionUtils.isNotEmpty(apiIds)) { - List returnDTO = new ArrayList<>(); - for (String apiId : apiIds) { - List mockExpectConfigWithBLOBsList = extMockExpectConfigMapper.selectByApiId(apiId); - for (MockExpectConfigWithBLOBs model : mockExpectConfigWithBLOBsList) { - MockConfigImportDTO dto = new MockConfigImportDTO(); - BeanUtils.copyBean(dto, model); - dto.setApiId(apiId); - returnDTO.add(dto); - } - } - return returnDTO; + return extMockExpectConfigMapper.selectByApiIdIn(apiIds); } else { return new ArrayList<>(); } diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 8e64c15a8f..1cd3b90f7d 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -1441,8 +1441,7 @@ public class ApiDefinitionService { List apiDefinitions = getByIds(request.getIds()); - if (StringUtils.equals(type, "MS")) { // 导出为 Metersphere 格式 - MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class); + if (StringUtils.equals(type, "MS")) { MsApiExportResult msApiExportResult = new MsApiExportResult(); msApiExportResult.setData(apiDefinitions); msApiExportResult.setCases(apiTestCaseService.selectCasesBydApiIds(request.getIds())); @@ -1451,12 +1450,6 @@ public class ApiDefinitionService { msApiExportResult.setProtocol(request.getProtocol()); msApiExportResult.setProjectId(request.getProjectId()); msApiExportResult.setVersion(System.getenv("MS_VERSION")); - if (CollectionUtils.isNotEmpty((msApiExportResult).getData())) { - List names = (msApiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList()); - request.setName(String.join(",", names)); - List ids = msApiExportResult.getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList()); - request.setId(JSON.toJSONString(ids)); - } return msApiExportResult; } else { // 导出为 Swagger 格式 Swagger3Parser swagger3Parser = new Swagger3Parser();