fix(接口测试): 接口导入其他协议判断导入无新增接口不增加模块

--user=郭雨琦
--bug=1014632
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014632
This commit is contained in:
guoyuqi 2022-07-06 15:03:32 +08:00 committed by xiaomeinvG
parent 6ce353e65e
commit 53c0caeb53
2 changed files with 33 additions and 13 deletions

View File

@ -36,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@Service
@ -698,6 +699,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
moduleMap = getOtherApiModuleMap(fullCoverage, fullCoverageApi, chooseModuleId, moduleMap, toUpdateList, idPathMap, chooseModule, optionData, repeatApiDefinitionWithBLOBs);
//系统内检查重复
if (!repeatApiDefinitionWithBLOBs.isEmpty()) {
Map<String, ApiDefinitionWithBLOBs> repeatMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
Map<String, ApiDefinitionWithBLOBs> optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api));
@ -767,10 +769,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
private Map<String, ApiModule> cover(Map<String, ApiModule> moduleMap, List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
//覆盖但不覆盖模块
if (nameModuleMap != null) {
//导入文件没有新增场景无需创建接口模块
if (repeatDataMap.size() >= nameModuleMap.size()) {
moduleMap = new HashMap<>();
}
//导入文件没有新增接口无需创建接口模块
moduleMap = judgeModule(moduleMap, nameModuleMap, repeatDataMap);
Map<String, ApiDefinitionWithBLOBs> finalNameModuleMap = nameModuleMap;
repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = finalNameModuleMap.get(k);
@ -791,6 +791,23 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
return moduleMap;
}
private Map<String, ApiModule> judgeModule(Map<String, ApiModule> moduleMap, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
AtomicBoolean remove = new AtomicBoolean(true);
if (repeatDataMap.size() >= nameModuleMap.size()) {
repeatDataMap.forEach((k, v) -> {
ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = nameModuleMap.get(k);
if (apiDefinitionWithBLOBs == null) {
remove.set(false);
}
});
if (remove.get()) {
moduleMap = new HashMap<>();
}
}
return moduleMap;
}
private void coverModule(List<ApiDefinitionWithBLOBs> toUpdateList, Map<String, ApiDefinitionWithBLOBs> nameModuleMap, Map<String, ApiDefinitionWithBLOBs> repeatDataMap) {
if (nameModuleMap != null) {
Map<String, ApiDefinitionWithBLOBs> finalNameModuleMap = nameModuleMap;

View File

@ -32,6 +32,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@Service
@ -72,14 +73,6 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
Map<String, List<String>> filters = new LinkedHashMap<>();
filters.put("status", list);
request.setFilters(filters);
//优化所有SQL统一查出来
// nodes.forEach(node -> {
// List<String> scenarioNodes = new ArrayList<>();
// scenarioNodes = this.nodeList(nodes, node.getId(), scenarioNodes);
// scenarioNodes.add(node.getId());
// request.setModuleIds(scenarioNodes);
// node.setCaseNum(extApiScenarioMapper.listModule(request));
// });
List<String> allModuleIdList = new ArrayList<>();
for (ApiScenarioModuleDTO node : nodes) {
List<String> moduleIds = new ArrayList<>();
@ -629,8 +622,18 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
}
private Map<String, ApiScenarioModule> judgeModuleMap(Map<String, ApiScenarioModule> moduleMap, Map<String, ApiScenarioWithBLOBs> nameModuleMap, Map<String, ApiScenarioWithBLOBs> repeatDataMap) {
AtomicBoolean remove = new AtomicBoolean(true);
if (repeatDataMap.size() >= nameModuleMap.size()) {
moduleMap = new HashMap<>();
repeatDataMap.forEach((k, v) -> {
ApiScenarioWithBLOBs scenario = nameModuleMap.get(k);
if (scenario == null) {
remove.set(false);
}
});
if (remove.get()) {
moduleMap = new HashMap<>();
}
}
return moduleMap;
}