diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index 3a539b1ed3..57a0b139e9 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -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 { moduleMap = getOtherApiModuleMap(fullCoverage, fullCoverageApi, chooseModuleId, moduleMap, toUpdateList, idPathMap, chooseModule, optionData, repeatApiDefinitionWithBLOBs); + //系统内检查重复 if (!repeatApiDefinitionWithBLOBs.isEmpty()) { Map repeatMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api)); Map optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName() + t.getModulePath(), api -> api)); @@ -767,10 +769,8 @@ public class ApiModuleService extends NodeTreeService { private Map cover(Map moduleMap, List toUpdateList, Map nameModuleMap, Map repeatDataMap) { //覆盖但不覆盖模块 if (nameModuleMap != null) { - //导入文件没有新增场景无需创建接口模块 - if (repeatDataMap.size() >= nameModuleMap.size()) { - moduleMap = new HashMap<>(); - } + //导入文件没有新增接口无需创建接口模块 + moduleMap = judgeModule(moduleMap, nameModuleMap, repeatDataMap); Map finalNameModuleMap = nameModuleMap; repeatDataMap.forEach((k, v) -> { ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = finalNameModuleMap.get(k); @@ -791,6 +791,23 @@ public class ApiModuleService extends NodeTreeService { return moduleMap; } + private Map judgeModule(Map moduleMap, Map nameModuleMap, Map 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 toUpdateList, Map nameModuleMap, Map repeatDataMap) { if (nameModuleMap != null) { Map finalNameModuleMap = nameModuleMap; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java index e264411616..b89dc2e02e 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java @@ -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> filters = new LinkedHashMap<>(); filters.put("status", list); request.setFilters(filters); - //优化:所有SQL统一查出来 -// nodes.forEach(node -> { -// List scenarioNodes = new ArrayList<>(); -// scenarioNodes = this.nodeList(nodes, node.getId(), scenarioNodes); -// scenarioNodes.add(node.getId()); -// request.setModuleIds(scenarioNodes); -// node.setCaseNum(extApiScenarioMapper.listModule(request)); -// }); List allModuleIdList = new ArrayList<>(); for (ApiScenarioModuleDTO node : nodes) { List moduleIds = new ArrayList<>(); @@ -629,8 +622,18 @@ public class ApiScenarioModuleService extends NodeTreeService judgeModuleMap(Map moduleMap, Map nameModuleMap, Map 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; }