From 4b394b64b0c1039e58ab7f53be84bf3b982e90d3 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 2 Aug 2022 13:09:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=85=A5=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E6=A8=A1=E5=BC=8F=EF=BC=8C=E8=A2=AB=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=97=A0case=EF=BC=8C=E6=96=B0case=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1015475 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015475 --- .../api/service/ApiModuleService.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 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 0cbe925830..87cb213d68 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -1010,7 +1010,7 @@ public class ApiModuleService extends NodeTreeService { Map caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs); updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId()); //组合case - if (caseNameMap != null) { + if (MapUtils.isNotEmpty(caseNameMap)) { buildCaseList(oldCaseMap, caseNameMap, v, optionDataCases); } apiDefinitionWithBLOBs.setId(v.getId()); @@ -1069,7 +1069,7 @@ public class ApiModuleService extends NodeTreeService { Map caseNameMap = getDistinctCaseNameMap(definitionIdCaseMAp, apiDefinitionWithBLOBs); updateEsb(esbApiParamsMap, v.getId(), apiDefinitionWithBLOBs.getId()); //组合case - if (caseNameMap != null) { + if (MapUtils.isNotEmpty(caseNameMap)) { buildCaseList(oldCaseMap, caseNameMap, v, optionDataCases); } apiDefinitionWithBLOBs.setId(v.getId()); @@ -1148,7 +1148,7 @@ public class ApiModuleService extends NodeTreeService { List sameVersionList = v.stream().filter(t -> t.getVersionId().equals(versionId)).collect(Collectors.toList()); if (!sameVersionList.isEmpty()) { optionData.remove(apiDefinitionWithBLOBs); - if (distinctNameCases != null && !distinctNameCases.isEmpty()) { + if (CollectionUtils.isNotEmpty(distinctNameCases)) { distinctNameCases.forEach(optionDataCases::remove); } } else { @@ -1206,7 +1206,7 @@ public class ApiModuleService extends NodeTreeService { continue; } //组合case - if (caseNameMap != null) { + if (MapUtils.isNotEmpty(caseNameMap)) { buildCaseList(oldCaseMap, caseNameMap, definitionWithBLOBs, optionDataCases); } @@ -1232,10 +1232,11 @@ public class ApiModuleService extends NodeTreeService { private void buildCaseList(Map> oldCaseMap, Map caseNameMap, ApiDefinitionWithBLOBs definitionWithBLOBs, List optionDataCases) { - //找出每个接口的case + //找出系统内重复接口每个接口的case List apiTestCases = oldCaseMap.get(definitionWithBLOBs.getId()); //map List 结构是因为表里可能一个接口有多个同名case的可能 Map> oldCaseNameMap; + //如果有重复接口,处理重复接口 if (apiTestCases != null && !apiTestCases.isEmpty()) { oldCaseNameMap = apiTestCases.stream().collect(Collectors.groupingBy(ApiTestCase::getName)); caseNameMap.forEach((name, caseWithBLOBs1) -> { @@ -1273,14 +1274,22 @@ public class ApiModuleService extends NodeTreeService { } else { caseWithBLOBs1.setVersion(0); } - + }); + } else { + //否则直接给新增接口赋值新的接口ID + caseNameMap.forEach((name, caseWithBLOBs1) -> { + //如果导入的有重名,覆盖,接口ID替换成系统内的 + caseWithBLOBs1.setApiDefinitionId(definitionWithBLOBs.getId()); }); } } private Map getDistinctCaseNameMap(Map> definitionIdCaseMAp, ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) { + if (MapUtils.isEmpty(definitionIdCaseMAp)) { + return null; + } List caseWithBLOBs = definitionIdCaseMAp.get(apiDefinitionWithBLOBs.getId()); - if (caseWithBLOBs != null) { + if (CollectionUtils.isNotEmpty(caseWithBLOBs)) { return caseWithBLOBs.stream().filter(t -> !t.getVersionId().equals("create_repeat")).collect(Collectors.toMap(ApiTestCase::getName, testCase -> testCase)); } else { return null; @@ -1306,7 +1315,7 @@ public class ApiModuleService extends NodeTreeService { continue; } //组合case - if (caseNameMap != null) { + if (MapUtils.isNotEmpty(caseNameMap)) { buildCaseList(oldCaseMap, caseNameMap, definitionWithBLOBs, optionDataCases); }