fix(接口测试): 修复批量导出问题

--bug=1044395 --user=王旭 【接口测试】接口定义-选中模块-批量选中当前页导出失败(仅当前数据) https://www.tapd.cn/55049933/s/1553327
This commit is contained in:
WangXu10 2024-07-24 11:21:34 +08:00 committed by Craftsman
parent c67e01d935
commit 3f3c65ea75
2 changed files with 26 additions and 7 deletions

View File

@ -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<String> ids = apiDefinitionService.getBatchApiIds(request, request.getProjectId(), request.getProtocols(), false, userId);
List<String> ids = getBatchApiIds(request, request.getProjectId(), List.of(ModuleConstants.NODE_PROTOCOL_HTTP), false, userId);
if (CollectionUtils.isEmpty(ids)) {
return new ApiExportResponse();
return null;
}
List<ApiDefinitionWithBlob> list = extApiDefinitionMapper.selectApiDefinitionWithBlob(ids);
List<String> moduleIds = list.stream().map(ApiDefinitionWithBlob::getModuleId).toList();
@ -57,6 +61,23 @@ public class ApiDefinitionExportService {
}
private List<String> getBatchApiIds(ApiDefinitionBatchRequest request, String projectId, List<String> protocols, boolean deleted, String userId) {
if (request.isSelectAll()) {
CustomFieldUtils.setBaseQueryRequestCustomMultipleFields(request.getCondition(), userId);
List<String> 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<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(definitionExample);
return apiDefinitions.stream().map(ApiDefinition::getId).toList();
}
}
private ApiExportResponse exportSwagger(ApiDefinitionBatchRequest request, List<ApiDefinitionWithBlob> list, Map<String, String> moduleMap) {
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
Swagger3ExportParser swagger3Parser = new Swagger3ExportParser();

View File

@ -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);
}
}