From e1b04677525182a3043d0fff957f1fa64aa95ab2 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 19 Oct 2021 11:52:32 +0800 Subject: [PATCH] =?UTF-8?q?fix=20(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=AF=BC=E5=85=A5sql=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9B=AE=E5=BD=95=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20--bug=3D1007085=20--user=3D=E8=B5=B5=E5=8B=87=20?= =?UTF-8?q?=E3=80=90=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E3=80=91=E5=AF=BC?= =?UTF-8?q?=E5=85=A5sql=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89=EF=BC=8C?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=AF=BC=E5=85=A5=E5=88=B0=E6=89=80=E9=80=89?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=B8=AD=E3=80=90+github#6024=E3=80=91=20htt?= =?UTF-8?q?ps://www.tapd.cn/55049933/s/1056589?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/definition/parse/ApiDefinitionImportUtil.java | 11 +++++++++-- .../io/metersphere/api/service/ApiModuleService.java | 3 +++ .../components/api/automation/api-automation.js | 4 ++-- .../api/automation/scenario/AddBasisScenario.vue | 3 ++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java index d72c4085c1..b6ccfc2d6b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/ApiDefinitionImportUtil.java @@ -70,12 +70,16 @@ public class ApiDefinitionImportUtil { private static void createNodeTree(NodeTree nodeTree, String pid, String projectId, ApiModuleService apiModuleService, String path, int baseLevel) { + ApiModule apiModule = apiModuleService.get(pid); ApiModule module = new ApiModule(); BeanUtils.copyBean(module, nodeTree); apiModuleService.buildNewModule(module); module.setProjectId(projectId); module.setParentId(pid); module.setLevel(module.getLevel() + baseLevel); + if (apiModule != null) { + module.setProtocol(apiModule.getProtocol()); + } createModule(module, SessionUtils.getUserId()); nodeTree.setNewId(module.getId()); path = path + nodeTree.getName(); @@ -91,6 +95,7 @@ public class ApiDefinitionImportUtil { /** * 根据导出的模块树,创建新的模块树 + * * @param nodeTree * @param projectId */ @@ -124,12 +129,14 @@ public class ApiDefinitionImportUtil { } public static void createModule(ApiModule module) { - createModule(module, null); + createModule(module, null); } public static void createModule(ApiModule module, String userId) { ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class); - module.setProtocol(RequestType.HTTP); + if (StringUtils.isEmpty(module.getProtocol())) { + module.setProtocol(RequestType.HTTP); + } if (module.getName().length() > 64) { module.setName(module.getName().substring(0, 64)); } 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 325608cede..5aae6559d6 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -60,6 +60,9 @@ public class ApiModuleService extends NodeTreeService { super(ApiModuleDTO.class); } + public ApiModule get(String id) { + return apiModuleMapper.selectByPrimaryKey(id); + } public List getNodeTreeByProjectId(String projectId, String protocol) { // 判断当前项目下是否有默认模块,没有添加默认模块 this.getDefaultNode(projectId,protocol); diff --git a/frontend/src/business/components/api/automation/api-automation.js b/frontend/src/business/components/api/automation/api-automation.js index 126fc368f0..36a33ee048 100644 --- a/frontend/src/business/components/api/automation/api-automation.js +++ b/frontend/src/business/components/api/automation/api-automation.js @@ -70,9 +70,9 @@ function getScenarioFiles(obj) { return scenarioFiles; } -export function saveScenario(url, scenario, scenarioDefinition, _this,success) { +export function saveScenario(url, scenario, scenarioDefinition, _this, success) { let bodyFiles = getBodyUploadFiles(scenario, scenarioDefinition); - if (_this.$store.state.pluginFiles && _this.$store.state.pluginFiles.length > 0) { + if (_this && _this.$store && _this.$store.state && _this.$store.state.pluginFiles && _this.$store.state.pluginFiles.length > 0) { _this.$store.state.pluginFiles.forEach(fileItem => { if (fileItem.file) { scenario.bodyFileRequestIds.push(fileItem.file.uid); diff --git a/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue b/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue index f449caf460..019aa564b7 100644 --- a/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/AddBasisScenario.vue @@ -101,7 +101,8 @@ this.$emit('saveAsEdit', this.scenarioForm); this.visible = false; } else { - saveScenario(path, this.scenarioForm, [], () => { + saveScenario(path, this.scenarioForm, [], this,(response) => { + this.$success(this.$t('commons.save_success')); this.visible = false; this.$emit('refresh'); });