feat(接口测试): #1007047 【接口定义】没有模块的接口,左侧导航树没有统计上

【【接口定义】没有模块的接口,左侧导航树没有统计上】https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001007047
This commit is contained in:
song-tianyang 2021-10-11 18:18:28 +08:00 committed by song-tianyang
parent 607a8bc8ea
commit 55e170c54c
3 changed files with 60 additions and 0 deletions

View File

@ -128,6 +128,53 @@ public class ApiDefinitionService {
return resList;
}
public void initDefaultModuleId(){
ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria().andModuleIdIsNull();
List<ApiDefinition> updateApiList = apiDefinitionMapper.selectByExample(example);
Map<String, Map<String,List<ApiDefinition>>> projectIdMap = new HashMap<>();
for (ApiDefinition api : updateApiList) {
String projectId = api.getProjectId();
String protocal = api.getProtocol();
if (projectIdMap.containsKey(projectId)) {
if(projectIdMap.get(projectId).containsKey(protocal)){
projectIdMap.get(projectId).get(protocal).add(api);
}else {
List<ApiDefinition> list = new ArrayList<>();
list.add(api);
projectIdMap.get(projectId).put(protocal,list);
}
} else {
List<ApiDefinition> list = new ArrayList<>();
list.add(api);
Map<String,List<ApiDefinition>> map = new HashMap<>();
map.put(protocal,list);
projectIdMap.put(projectId, map);
}
}
ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
for (Map.Entry<String, Map<String,List<ApiDefinition>>> entry : projectIdMap.entrySet()) {
String projectId = entry.getKey();
Map<String,List<ApiDefinition>> map = entry.getValue();
for (Map.Entry<String,List<ApiDefinition>> itemEntry : map.entrySet()) {
String protocal = itemEntry.getKey();
ApiModule node = apiModuleService.getDefaultNodeUnCreateNew(projectId, protocal);
if(node != null){
List<ApiDefinition> testCaseList = itemEntry.getValue();
for (ApiDefinition apiDefinition : testCaseList) {
ApiDefinitionWithBLOBs updateCase = new ApiDefinitionWithBLOBs();
updateCase.setId(apiDefinition.getId());
updateCase.setModuleId(node.getId());
updateCase.setModulePath("/" + node.getName());
apiDefinitionMapper.updateByPrimaryKeySelective(updateCase);
}
}
}
}
}
public List<ApiDefinitionResult> listBatch(ApiBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiDefinitionMapper.selectIds(query));

View File

@ -522,4 +522,15 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
return list.get(0);
}
}
public ApiModule getDefaultNodeUnCreateNew(String projectId,String protocol) {
ApiModuleExample example = new ApiModuleExample();
example.createCriteria().andProjectIdEqualTo(projectId).andProtocolEqualTo(protocol).andNameEqualTo("未规划接口").andParentIdIsNull();;
List<ApiModule> list = apiModuleMapper.selectByExample(example);
if (CollectionUtils.isEmpty(list)) {
return null;
}else {
return list.get(0);
}
}
}

View File

@ -131,6 +131,8 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
initOnceOperate(testPlanScenarioCaseService::initOrderField, "init.sort.plan.api.scenario");
initOnceOperate(testPlanLoadCaseService::initOrderField, "init.sort.plan.api.load");
initOnceOperate(testReviewTestCaseService::initOrderField, "init.sort.review.test.case");
initOnceOperate(apiDefinitionService::initDefaultModuleId, "init.default.module.id");
}
/**