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') }}