From 90d25c111c533da64c714ff36de7bcf05d02777c Mon Sep 17 00:00:00 2001 From: CaptainB Date: Tue, 25 Jan 2022 18:57:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/api/dto/ApiTestImportRequest.java | 2 ++ .../metersphere/api/service/ApiAutomationService.java | 10 +++++----- .../metersphere/api/service/ApiDefinitionService.java | 10 +++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java b/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java index 332ce92622..6afc2d1578 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java @@ -4,6 +4,7 @@ import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.scenario.KeyValue; import lombok.Getter; import lombok.Setter; + import java.util.List; @Setter @@ -25,6 +26,7 @@ public class ApiTestImportRequest { private String userId; private String versionId; // 新导入选择的版本 private String updateVersionId; // 覆盖导入已存在的接口选择的版本 + private String defaultVersion; //调用类型 private String type; // 是否开启自定义ID 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 bea42c576f..8f87f185d8 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1222,7 +1222,6 @@ public class ApiAutomationService { private void _importCreate(List sameRequest, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper, ApiScenarioWithBLOBs scenarioWithBLOBs, ApiTestImportRequest apiTestImportRequest) { - String defaultVersion = extProjectVersionMapper.getDefaultVersion(apiTestImportRequest.getProjectId()); if (CollectionUtils.isEmpty(sameRequest)) { scenarioWithBLOBs.setId(UUID.randomUUID().toString()); List useUrl = this.parseUrl(scenarioWithBLOBs); @@ -1233,7 +1232,7 @@ public class ApiAutomationService { if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) { scenarioWithBLOBs.setVersionId(apiTestImportRequest.getVersionId()); } else { - scenarioWithBLOBs.setVersionId(defaultVersion); + scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion()); } scenarioWithBLOBs.setLatest(true); batchMapper.insert(scenarioWithBLOBs); @@ -1241,7 +1240,7 @@ public class ApiAutomationService { } else { //如果存在则修改 if (StringUtils.isEmpty(apiTestImportRequest.getUpdateVersionId())) { - apiTestImportRequest.setUpdateVersionId(defaultVersion); + apiTestImportRequest.setUpdateVersionId(apiTestImportRequest.getDefaultVersion()); } Optional scenarioOp = sameRequest.stream() .filter(api -> StringUtils.equals(api.getVersionId(), apiTestImportRequest.getUpdateVersionId())) @@ -1333,8 +1332,7 @@ public class ApiAutomationService { if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) { scenarioWithBLOBs.setVersionId(apiTestImportRequest.getVersionId()); } else { - String defaultVersion = extProjectVersionMapper.getDefaultVersion(apiTestImportRequest.getProjectId()); - scenarioWithBLOBs.setVersionId(defaultVersion); + scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion()); } scenarioWithBLOBs.setLatest(true); batchMapper.insert(scenarioWithBLOBs); @@ -1366,6 +1364,8 @@ public class ApiAutomationService { num = getNextNum(data.get(0).getProjectId()); request.setOpenCustomNum(project.getScenarioCustomNum()); } + String defaultVersion = extProjectVersionMapper.getDefaultVersion(request.getProjectId()); + request.setDefaultVersion(defaultVersion); for (int i = 0; i < data.size(); i++) { ApiScenarioWithBLOBs item = data.get(i); if (item.getName().length() > 255) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 8e04f0bfcc..8563a8d65a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -752,8 +752,7 @@ public class ApiDefinitionService { if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) { apiDefinition.setVersionId(apiTestImportRequest.getVersionId()); } else { - String defaultVersion = extProjectVersionMapper.getDefaultVersion(apiTestImportRequest.getProjectId()); - apiDefinition.setVersionId(defaultVersion); + apiDefinition.setVersionId(apiTestImportRequest.getDefaultVersion()); } apiDefinition.setLatest(true); // 新增的接口 latest = true batchMapper.insert(apiDefinition); @@ -802,7 +801,6 @@ public class ApiDefinitionService { ApiTestCaseMapper apiTestCaseMapper, ExtApiDefinitionMapper extApiDefinitionMapper, ApiTestImportRequest apiTestImportRequest, List cases, List mocks) { String originId = apiDefinition.getId(); - String defaultVersion = extProjectVersionMapper.getDefaultVersion(apiTestImportRequest.getProjectId()); if (CollectionUtils.isEmpty(sameRequest)) { // 没有这个接口 新增 apiDefinition.setId(UUID.randomUUID().toString()); @@ -810,7 +808,7 @@ public class ApiDefinitionService { if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) { apiDefinition.setVersionId(apiTestImportRequest.getVersionId()); } else { - apiDefinition.setVersionId(defaultVersion); + apiDefinition.setVersionId(apiTestImportRequest.getDefaultVersion()); } apiDefinition.setLatest(true); // 新增接口 latest = true // case 设置版本 @@ -834,7 +832,7 @@ public class ApiDefinitionService { } else { //如果存在则修改 if (StringUtils.isEmpty(apiTestImportRequest.getUpdateVersionId())) { - apiTestImportRequest.setUpdateVersionId(defaultVersion); + apiTestImportRequest.setUpdateVersionId(apiTestImportRequest.getDefaultVersion()); } Optional apiOp = sameRequest.stream() .filter(api -> StringUtils.equals(api.getVersionId(), apiTestImportRequest.getUpdateVersionId())) @@ -1175,6 +1173,8 @@ public class ApiDefinitionService { if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) { num = getNextNum(data.get(0).getProjectId()); } + String defaultVersion = extProjectVersionMapper.getDefaultVersion(request.getProjectId()); + request.setDefaultVersion(defaultVersion); for (int i = 0; i < data.size(); i++) { ApiDefinitionWithBLOBs item = data.get(i); this.setModule(item);