refactor(接口测试): 优化导出API方法

--bug=1025069 --user=赵勇 【接口测试】导出全部api数据3000+-导出失败 https://www.tapd.cn/55049933/s/1358748

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-04-03 17:04:18 +08:00 committed by fit2-zhao
parent bc471a2fe4
commit 7598c6d87c
4 changed files with 15 additions and 27 deletions

View File

@ -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<MockExpectConfigWithBLOBs> selectByApiId(String apiId);
List<MockExpectConfigWithBLOBs> selectByApiIdIn(@Param("values") List<String> apiIds);
List<MockConfigImportDTO> selectByApiIdIn(@Param("values") List<String> apiIds);
List<String> selectExlectNumByMockConfigId(String mockConfigId);

View File

@ -12,10 +12,14 @@
SELECT id FROM mock_config WHERE api_id = #{0}
)
</select>
<select id="selectByApiIdIn" resultType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
SELECT * FROM mock_expect_config WHERE mock_config_id IN
(
SELECT id FROM mock_config WHERE api_id IN
<select id="selectByApiIdIn" resultType="io.metersphere.api.dto.mock.config.MockConfigImportDTO">
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 (
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>

View File

@ -95,17 +95,7 @@ public class MockConfigService {
public List<MockConfigImportDTO> selectMockExpectConfigByApiIdIn(List<String> apiIds) {
if (CollectionUtils.isNotEmpty(apiIds)) {
List<MockConfigImportDTO> returnDTO = new ArrayList<>();
for (String apiId : apiIds) {
List<MockExpectConfigWithBLOBs> 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<>();
}

View File

@ -1441,8 +1441,7 @@ public class ApiDefinitionService {
List<ApiDefinitionWithBLOBs> 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<String> names = (msApiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList());
request.setName(String.join(",", names));
List<String> ids = msApiExportResult.getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList());
request.setId(JSON.toJSONString(ids));
}
return msApiExportResult;
} else { // 导出为 Swagger 格式
Swagger3Parser swagger3Parser = new Swagger3Parser();