From 6a118e3b94e770fc7a0f6f2faf25a04b83715ef5 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 22 Apr 2022 11:09:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E4=BF=9D=E5=AD=98=E6=97=B6?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=88=B0=E7=9A=84url=E4=BC=9A=E8=A2=AB?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复场景保存时引用到的url会被覆盖的问题 --- .../service/ApiScenarioReferenceIdService.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReferenceIdService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReferenceIdService.java index 4119c07cb8..87e8f50f17 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReferenceIdService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReferenceIdService.java @@ -102,7 +102,6 @@ public class ApiScenarioReferenceIdService { public List getApiAndScenarioRelation(ApiScenarioWithBLOBs scenario) { List returnList = new ArrayList<>(); - Map referenceIdMap = new HashMap<>(); if (StringUtils.isNotEmpty(scenario.getScenarioDefinition())) { JSONObject jsonObject = JSONObject.parseObject(scenario.getScenarioDefinition(), Feature.DisableSpecialKeyDetect); if (!jsonObject.containsKey(MsHashTreeService.HASH_TREE)) { @@ -136,16 +135,14 @@ public class ApiScenarioReferenceIdService { saveItem.setCreateUserId(SessionUtils.getUserId()); saveItem.setUrl(url); saveItem.setMethod(method); - referenceIdMap.put(item.getString(MsHashTreeService.ID), saveItem); + returnList.add(saveItem); } if (item.containsKey(MsHashTreeService.HASH_TREE)) { - referenceIdMap.putAll(this.deepElementRelation(scenario.getId(), item.getJSONArray(MsHashTreeService.HASH_TREE))); + returnList.addAll(this.deepElementRelation(scenario.getId(), item.getJSONArray(MsHashTreeService.HASH_TREE))); } } } - if (MapUtils.isNotEmpty(referenceIdMap)) { - returnList.addAll(referenceIdMap.values()); - } else { + if (CollectionUtils.isEmpty(returnList)) { ApiScenarioReferenceId saveItem = new ApiScenarioReferenceId(); saveItem.setId(UUID.randomUUID().toString()); saveItem.setApiScenarioId(scenario.getId()); @@ -156,8 +153,8 @@ public class ApiScenarioReferenceIdService { return returnList; } - public Map deepElementRelation(String scenarioId, JSONArray hashTree) { - Map deepRelations = new HashMap<>(); + public List deepElementRelation(String scenarioId, JSONArray hashTree) { + List deepRelations = new LinkedList<>(); if (CollectionUtils.isNotEmpty(hashTree)) { for (int index = 0; index < hashTree.size(); index++) { JSONObject item = hashTree.getJSONObject(index); @@ -182,10 +179,10 @@ public class ApiScenarioReferenceIdService { saveItem.setCreateUserId(SessionUtils.getUserId()); saveItem.setMethod(method); saveItem.setUrl(url); - deepRelations.put(item.getString(MsHashTreeService.ID), saveItem); + deepRelations.add(saveItem); } if (item.containsKey(MsHashTreeService.HASH_TREE)) { - deepRelations.putAll(this.deepElementRelation(scenarioId, item.getJSONArray(MsHashTreeService.HASH_TREE))); + deepRelations.addAll(this.deepElementRelation(scenarioId, item.getJSONArray(MsHashTreeService.HASH_TREE))); } } }