From 9250df2205d7cb05649b3781cecf79b8d891bd07 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Fri, 25 Oct 2024 11:47:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E7=94=A8=E4=BE=8B=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E6=89=A7=E8=A1=8C=EF=BC=8C=E6=B2=A1=E6=9C=89=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047999 --user=陈建星 【系统设置】系统-任务中心-用例执行任务/用例执行任务详情列表-在测试计划内单独执行用例/场景-任务列表未显示该任务 https://www.tapd.cn/55049933/s/1597730 --- .../ApiScenarioDataTransferService.java | 101 ++++++++++-------- .../service/scenario/ApiScenarioService.java | 4 +- .../exportScenario/scenarioExportModal.vue | 2 +- 3 files changed, 62 insertions(+), 45 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java index 3832d52517..e3cf0f6f39 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java @@ -710,57 +710,73 @@ public class ApiScenarioDataTransferService { for (ApiScenarioImportDetail importScenario : analysisResult.getInsertApiScenarioData()) { // 处理步骤里的关联资源文件 - importScenario.getSteps().forEach(item -> { - if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API.name())) { - ApiDefinitionDetail apiDetail = replaceScenarioResource.getApi(item.getResourceId()); - if (apiDetail != null) { - item.setResourceId(apiDetail.getId()); - item.setProjectId(importScenario.getProjectId()); - item.setOriginProjectId(apiDetail.getProjectId()); + List stepList = importScenario.getSteps(); + while (CollectionUtils.isNotEmpty(stepList)) { + List children = new ArrayList<>(); + for (ApiScenarioStepRequest item : stepList) { + if (CollectionUtils.isNotEmpty(item.getChildren())) { + children.addAll(item.getChildren()); } - } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_CASE.name())) { - ApiTestCaseDTO newData = replaceScenarioResource.getApiCase(item.getResourceId()); - if (newData != null) { - item.setResourceId(newData.getId()); - item.setProjectId(importScenario.getProjectId()); - item.setOriginProjectId(newData.getProjectId()); - } - } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_SCENARIO.name())) { - ApiScenarioImportDetail newData = replaceScenarioResource.getApiScenario(item.getResourceId()); - if (newData != null) { - item.setResourceId(newData.getId()); - item.setProjectId(importScenario.getProjectId()); - item.setOriginProjectId(newData.getProjectId()); + if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API.name())) { + ApiDefinitionDetail apiDetail = replaceScenarioResource.getApi(item.getResourceId()); + if (apiDetail != null) { + item.setResourceId(apiDetail.getId()); + item.setProjectId(importScenario.getProjectId()); + item.setOriginProjectId(apiDetail.getProjectId()); + } + } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_CASE.name())) { + ApiTestCaseDTO newData = replaceScenarioResource.getApiCase(item.getResourceId()); + if (newData != null) { + item.setResourceId(newData.getId()); + item.setProjectId(importScenario.getProjectId()); + item.setOriginProjectId(newData.getProjectId()); + } + } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_SCENARIO.name())) { + ApiScenarioImportDetail newData = replaceScenarioResource.getApiScenario(item.getResourceId()); + if (newData != null) { + item.setResourceId(newData.getId()); + item.setProjectId(importScenario.getProjectId()); + item.setOriginProjectId(newData.getProjectId()); + } } } - }); + stepList = children; + } } for (ApiScenarioImportDetail updateScenario : analysisResult.getUpdateApiScenarioData()) { // 处理步骤里的关联资源文件 - updateScenario.getSteps().forEach(item -> { - if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API.name())) { - ApiDefinitionDetail apiDetail = replaceScenarioResource.getApi(item.getResourceId()); - if (apiDetail != null) { - item.setResourceId(apiDetail.getId()); - item.setProjectId(updateScenario.getProjectId()); - item.setOriginProjectId(apiDetail.getProjectId()); + List stepList = updateScenario.getSteps(); + while (CollectionUtils.isNotEmpty(stepList)) { + List children = new ArrayList<>(); + for (ApiScenarioStepRequest item : stepList) { + if (CollectionUtils.isNotEmpty(item.getChildren())) { + children.addAll(item.getChildren()); } - } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_CASE.name())) { - ApiTestCaseDTO newData = replaceScenarioResource.getApiCase(item.getResourceId()); - if (newData != null) { - item.setResourceId(newData.getId()); - item.setProjectId(updateScenario.getProjectId()); - item.setOriginProjectId(newData.getProjectId()); - } - } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_SCENARIO.name())) { - ApiScenarioImportDetail newData = replaceScenarioResource.getApiScenario(item.getResourceId()); - if (newData != null) { - item.setResourceId(newData.getId()); - item.setProjectId(updateScenario.getProjectId()); - item.setOriginProjectId(newData.getProjectId()); + if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API.name())) { + ApiDefinitionDetail apiDetail = replaceScenarioResource.getApi(item.getResourceId()); + if (apiDetail != null) { + item.setResourceId(apiDetail.getId()); + item.setProjectId(updateScenario.getProjectId()); + item.setOriginProjectId(apiDetail.getProjectId()); + } + } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_CASE.name())) { + ApiTestCaseDTO newData = replaceScenarioResource.getApiCase(item.getResourceId()); + if (newData != null) { + item.setResourceId(newData.getId()); + item.setProjectId(updateScenario.getProjectId()); + item.setOriginProjectId(newData.getProjectId()); + } + } else if (StringUtils.equalsIgnoreCase(item.getStepType(), ApiScenarioStepType.API_SCENARIO.name())) { + ApiScenarioImportDetail newData = replaceScenarioResource.getApiScenario(item.getResourceId()); + if (newData != null) { + item.setResourceId(newData.getId()); + item.setProjectId(updateScenario.getProjectId()); + item.setOriginProjectId(newData.getProjectId()); + } } } - }); + stepList = children; + } } return analysisResult; } @@ -852,6 +868,7 @@ public class ApiScenarioDataTransferService { Map modulePathMap = apiModules.stream().collect(Collectors.toMap(BaseTreeNode::getPath, k -> k, (k1, k2) -> k1)); for (ApiDefinitionDetail apiDefinitionDetail : analysisResult.getInsertApiDefinitions()) { List insertModuleList = TreeNodeParseUtils.getInsertNodeByPath(modulePathMap, apiDefinitionDetail.getModulePath()); + apiDefinitionDetail.setModuleId(modulePathMap.get(apiDefinitionDetail.getModulePath()).getId()); insertModuleList.forEach(item -> item.setProjectId(targetProjectId)); analysisResult.getInsertApiModuleList().addAll(insertModuleList); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index dd008cedc0..c09073f3d5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -1849,7 +1849,7 @@ public class ApiScenarioService extends MoveNodeService { returnList.addAll(this.parseConfig(steps, null)); } - List refScenarioSteps = steps.stream().filter(this::isRefOrPartialScenario).toList(); + List refScenarioSteps = steps.stream().filter(k -> isScenarioStep(k.getStepType())).toList(); while (CollectionUtils.isNotEmpty(refScenarioSteps)) { List childStep = new ArrayList<>(); for (ApiScenarioStepDTO step : refScenarioSteps) { @@ -1858,7 +1858,7 @@ public class ApiScenarioService extends MoveNodeService { returnList.addAll(this.parseConfig(childStep, step.getId())); } } - refScenarioSteps = childStep.stream().filter(this::isRefOrPartialScenario).toList(); + refScenarioSteps = childStep.stream().filter(k -> isScenarioStep(k.getStepType())).toList(); } // 嵌套获取引用的场景步骤 return returnList; diff --git a/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue b/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue index a3e3f37db7..1c298fbaed 100644 --- a/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue +++ b/frontend/src/views/api-test/scenario/components/common/exportScenario/scenarioExportModal.vue @@ -7,7 +7,7 @@ :width="400" >
- + {{ t('apiScenario.export.type.all') }}