From 53c0caeb534ac845d76af4824bf51dacb7e295e8 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 6 Jul 2022 15:03:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=85=A5=E5=85=B6=E4=BB=96=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E5=88=A4=E6=96=AD=E5=AF=BC=E5=85=A5=E6=97=A0=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=8E=A5=E5=8F=A3=E4=B8=8D=E5=A2=9E=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1014632 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014632 --- .../api/service/ApiModuleService.java | 25 ++++++++++++++++--- .../api/service/ApiScenarioModuleService.java | 21 +++++++++------- 2 files changed, 33 insertions(+), 13 deletions(-) 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; }