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();