diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index 710f2d3aa3..2593fd31d3 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -34,8 +34,8 @@ public class ApiAutomationController { } @PostMapping(value = "/create") - public void create(@RequestPart("request") SaveApiScenarioRequest request, @RequestPart(value = "files") List bodyFiles) { - apiAutomationService.create(request, bodyFiles); + public ApiScenario create(@RequestPart("request") SaveApiScenarioRequest request, @RequestPart(value = "files") List bodyFiles) { + return apiAutomationService.create(request, bodyFiles); } @PostMapping(value = "/update") 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 ee13eb7368..ad04dbc5fd 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -100,11 +100,12 @@ public class ApiAutomationService { apiScenarioMapper.deleteByExample(example); } - public void create(SaveApiScenarioRequest request, List bodyFiles) { + public ApiScenario create(SaveApiScenarioRequest request, List bodyFiles) { + request.setId(UUID.randomUUID().toString()); checkNameExist(request); - + final ApiScenario scenario = new ApiScenario(); - scenario.setId(UUID.randomUUID().toString()); + scenario.setId(request.getId()); scenario.setName(request.getName()); scenario.setProjectId(request.getProjectId()); scenario.setTagId(request.getTagId()); @@ -132,6 +133,7 @@ public class ApiAutomationService { List bodyUploadIds = request.getBodyUploadIds(); apiDefinitionService.createBodyFiles(bodyUploadIds, bodyFiles); + return scenario; } public void update(SaveApiScenarioRequest request, List bodyFiles) { @@ -248,7 +250,7 @@ public class ApiAutomationService { JSONObject element = JSON.parseObject(item.getScenarioDefinition()); MsScenario scenario = JSONObject.parseObject(item.getScenarioDefinition(), MsScenario.class); // 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取 - if (element!= null && StringUtils.isNotEmpty(element.getString("hashTree"))) { + if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { LinkedList elements = mapper.readValue(element.getString("hashTree"), new TypeReference>() { }); diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 61397c1672..1fe20ba15a 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 61397c16728a63493507679f7e0940d9099f337f +Subproject commit 1fe20ba15a7ca3fe9f77ddf866021e7c7dfe5969 diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 20eb794b26..9f89ad79fd 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -240,7 +240,7 @@ }); }, copy(row) { - row.id = getUUID(); + row.copy = true; this.$emit('edit', row); }, showReport(row) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 4c1fb5faea..38c86dc5ac 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -694,9 +694,12 @@ if (valid) { this.setParameter(); let bodyFiles = this.getBodyUploadFiles(this.currentScenario); - this.$fileUpload(this.path, null, bodyFiles, this.currentScenario, () => { + this.$fileUpload(this.path, null, bodyFiles, this.currentScenario, response => { this.$success(this.$t('commons.save_success')); this.path = "/api/automation/update"; + if (response.data) { + this.currentScenario.id = response.data.id; + } this.currentScenario.tagId = JSON.parse(this.currentScenario.tagId); this.$emit('refresh'); }) @@ -719,6 +722,9 @@ this.scenarioDefinition = obj.hashTree; } } + if (this.currentScenario.copy) { + this.path = "/api/automation/create"; + } } }) }