refactor(接口定义): 默认模块校验公共方法提取
This commit is contained in:
parent
cc13993abc
commit
6313a66662
|
@ -264,15 +264,7 @@ public class ApiDefinitionService {
|
|||
test.setEnvironmentId(request.getEnvironmentId());
|
||||
test.setUserId(request.getUserId());
|
||||
test.setTags(request.getTags());
|
||||
if (StringUtils.isEmpty(request.getModuleId()) || "default-module".equals(request.getModuleId())) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(test.getProjectId()).andProtocolEqualTo(test.getProtocol()).andNameEqualTo("默认模块");
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
test.setModuleId(modules.get(0).getId());
|
||||
test.setModulePath(modules.get(0).getName());
|
||||
}
|
||||
}
|
||||
this.setModule(test);
|
||||
apiDefinitionMapper.updateByPrimaryKeySelective(test);
|
||||
return test;
|
||||
}
|
||||
|
@ -591,6 +583,17 @@ public class ApiDefinitionService {
|
|||
return apiTestCaseMapper.selectByPrimaryKey(apiCaseId);
|
||||
}
|
||||
|
||||
private void setModule(ApiDefinitionWithBLOBs item) {
|
||||
if (item != null && StringUtils.isEmpty(item.getModuleId()) || "default-module".equals(item.getModuleId())) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(item.getProjectId()).andProtocolEqualTo(item.getProtocol()).andNameEqualTo("默认模块");
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
item.setModuleId(modules.get(0).getId());
|
||||
item.setModulePath(modules.get(0).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ApiDefinitionImport apiTestImport(MultipartFile file, ApiTestImportRequest request) {
|
||||
ApiImportParser apiImportParser = ApiDefinitionImportParserFactory.getApiImportParser(request.getPlatform());
|
||||
|
@ -616,15 +619,7 @@ public class ApiDefinitionService {
|
|||
}
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
ApiDefinitionWithBLOBs item = data.get(i);
|
||||
if (StringUtils.isEmpty(item.getModuleId()) || "default-module".equals(item.getModuleId())) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
example.createCriteria().andProjectIdEqualTo(item.getProjectId()).andProtocolEqualTo(item.getProtocol()).andNameEqualTo("默认模块");
|
||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
||||
if (CollectionUtils.isNotEmpty(modules)) {
|
||||
item.setModuleId(modules.get(0).getId());
|
||||
item.setModulePath(modules.get(0).getName());
|
||||
}
|
||||
}
|
||||
this.setModule(item);
|
||||
if (item.getName().length() > 255) {
|
||||
item.setName(item.getName().substring(0, 255));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue