From f6bc6f6e0d9dd5f74ab3f523658294c31334998d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 9 Jul 2021 16:12:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E6=AD=A5=E9=AA=A4=E5=AF=BC=E5=87=BA=E5=86=8D=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/ApiAutomationService.java | 54 ++++++++++++++++++- .../scenario/component/ApiComponent.vue | 13 ++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 94f281b3b1..067000154f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -306,7 +306,7 @@ public class ApiAutomationService { .andIdNotEqualTo(request.getId()); List list = apiScenarioMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(list)) { - MSException.throwException("自定义ID "+ request.getCustomNum() +" 已存在!"); + MSException.throwException("自定义ID " + request.getCustomNum() + " 已存在!"); } } @@ -1755,12 +1755,64 @@ public class ApiAutomationService { return apiImport; } + private void setHashTree(JSONArray hashTree) { + // 将引用转成复制 + if (CollectionUtils.isNotEmpty(hashTree)) { + for (int i = 0; i < hashTree.size(); i++) { + JSONObject object = (JSONObject) hashTree.get(i); + String referenced = object.getString("referenced"); + if (StringUtils.isNotBlank(referenced) && StringUtils.equals(referenced, "REF")) { + // 检测引用对象是否存在,若果不存在则改成复制对象 + String refType = object.getString("refType"); + if (StringUtils.isNotEmpty(refType)) { + if (refType.equals("CASE")) { + ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(object.getString("id")); + if (bloBs != null) { + object = JSON.parseObject(bloBs.getRequest()); + object.put("id", bloBs.getId()); + object.put("name", bloBs.getName()); + hashTree.set(i, object); + } + } else { + ApiScenarioWithBLOBs bloBs = this.getDto(object.getString("id")); + if (bloBs != null) { + object = JSON.parseObject(bloBs.getScenarioDefinition()); + hashTree.set(i, object); + } + } + } else if ("scenario".equals(object.getString("type"))) { + ApiScenarioWithBLOBs bloBs = this.getDto(object.getString("id")); + if (bloBs != null) { + object = JSON.parseObject(bloBs.getScenarioDefinition()); + hashTree.set(i, object); + } + } + } + if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) { + setHashTree(object.getJSONArray("hashTree")); + } + } + } + } + private List getExportResult(ApiScenarioBatchRequest request) { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query)); ApiScenarioExample example = new ApiScenarioExample(); example.createCriteria().andIdIn(request.getIds()); List apiScenarioWithBLOBs = apiScenarioMapper.selectByExampleWithBLOBs(example); + // 处理引用数据 + if (CollectionUtils.isNotEmpty(apiScenarioWithBLOBs)) { + apiScenarioWithBLOBs.forEach(item -> { + if (StringUtils.isNotEmpty(item.getScenarioDefinition())) { + JSONObject scenario = JSONObject.parseObject(item.getScenarioDefinition()); + JSONArray hashTree = scenario.getJSONArray("hashTree"); + setHashTree(hashTree); + scenario.put("hashTree", hashTree); + item.setScenarioDefinition(JSON.toJSONString(scenario)); + } + }); + } return apiScenarioWithBLOBs; } diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index cef2c048ea..06a32f1507 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -18,7 +18,7 @@ {{ $t('api_test.automation.reference_deleted') }} {{ $t('commons.copy') }} {{ $t('api_test.scenario.reference') }} - {{ getProjectName(request.projectId) }} + {{ getProjectName(request.projectId) }}