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:
parent
bc471a2fe4
commit
7598c6d87c
|
@ -1,5 +1,6 @@
|
||||||
package io.metersphere.base.mapper.ext;
|
package io.metersphere.base.mapper.ext;
|
||||||
|
|
||||||
|
import io.metersphere.api.dto.mock.config.MockConfigImportDTO;
|
||||||
import io.metersphere.base.domain.MockExpectConfigWithBLOBs;
|
import io.metersphere.base.domain.MockExpectConfigWithBLOBs;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ public interface ExtMockExpectConfigMapper {
|
||||||
|
|
||||||
List<MockExpectConfigWithBLOBs> selectByApiId(String apiId);
|
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);
|
List<String> selectExlectNumByMockConfigId(String mockConfigId);
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,14 @@
|
||||||
SELECT id FROM mock_config WHERE api_id = #{0}
|
SELECT id FROM mock_config WHERE api_id = #{0}
|
||||||
)
|
)
|
||||||
</select>
|
</select>
|
||||||
<select id="selectByApiIdIn" resultType="io.metersphere.base.domain.MockExpectConfigWithBLOBs">
|
<select id="selectByApiIdIn" resultType="io.metersphere.api.dto.mock.config.MockConfigImportDTO">
|
||||||
SELECT * FROM mock_expect_config WHERE mock_config_id IN
|
SELECT
|
||||||
(
|
mock_expect_config.*,
|
||||||
SELECT id FROM mock_config WHERE api_id IN
|
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=")">
|
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||||
#{value}
|
#{value}
|
||||||
</foreach>
|
</foreach>
|
||||||
|
|
|
@ -95,17 +95,7 @@ public class MockConfigService {
|
||||||
|
|
||||||
public List<MockConfigImportDTO> selectMockExpectConfigByApiIdIn(List<String> apiIds) {
|
public List<MockConfigImportDTO> selectMockExpectConfigByApiIdIn(List<String> apiIds) {
|
||||||
if (CollectionUtils.isNotEmpty(apiIds)) {
|
if (CollectionUtils.isNotEmpty(apiIds)) {
|
||||||
List<MockConfigImportDTO> returnDTO = new ArrayList<>();
|
return extMockExpectConfigMapper.selectByApiIdIn(apiIds);
|
||||||
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;
|
|
||||||
} else {
|
} else {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1441,8 +1441,7 @@ public class ApiDefinitionService {
|
||||||
|
|
||||||
List<ApiDefinitionWithBLOBs> apiDefinitions = getByIds(request.getIds());
|
List<ApiDefinitionWithBLOBs> apiDefinitions = getByIds(request.getIds());
|
||||||
|
|
||||||
if (StringUtils.equals(type, "MS")) { // 导出为 Metersphere 格式
|
if (StringUtils.equals(type, "MS")) {
|
||||||
MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class);
|
|
||||||
MsApiExportResult msApiExportResult = new MsApiExportResult();
|
MsApiExportResult msApiExportResult = new MsApiExportResult();
|
||||||
msApiExportResult.setData(apiDefinitions);
|
msApiExportResult.setData(apiDefinitions);
|
||||||
msApiExportResult.setCases(apiTestCaseService.selectCasesBydApiIds(request.getIds()));
|
msApiExportResult.setCases(apiTestCaseService.selectCasesBydApiIds(request.getIds()));
|
||||||
|
@ -1451,12 +1450,6 @@ public class ApiDefinitionService {
|
||||||
msApiExportResult.setProtocol(request.getProtocol());
|
msApiExportResult.setProtocol(request.getProtocol());
|
||||||
msApiExportResult.setProjectId(request.getProjectId());
|
msApiExportResult.setProjectId(request.getProjectId());
|
||||||
msApiExportResult.setVersion(System.getenv("MS_VERSION"));
|
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;
|
return msApiExportResult;
|
||||||
} else { // 导出为 Swagger 格式
|
} else { // 导出为 Swagger 格式
|
||||||
Swagger3Parser swagger3Parser = new Swagger3Parser();
|
Swagger3Parser swagger3Parser = new Swagger3Parser();
|
||||||
|
|
Loading…
Reference in New Issue