From 8e3d95e119d1eb2dfe0b9b6abd496e9cec4e7a8a Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 14 Jul 2022 15:16:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E8=A6=86=E7=9B=96=E5=AF=BC=E5=85=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --- .../api/service/ApiAutomationService.java | 49 ++++--------------- 1 file changed, 10 insertions(+), 39 deletions(-) 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 2c4316b3b7..59c48b9ea3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1215,12 +1215,10 @@ public class ApiAutomationService { private void _importCreate(List sameRequest, ApiScenarioMapper batchMapper, ExtApiScenarioMapper extApiScenarioMapper, ApiScenarioWithBLOBs scenarioWithBLOBs, ApiTestImportRequest apiTestImportRequest, ApiTestCaseMapper apiTestCaseMapper, ApiDefinitionMapper apiDefinitionMapper) { if (CollectionUtils.isEmpty(sameRequest)) { + // 没有这个场景 新增 scenarioWithBLOBs.setId(UUID.randomUUID().toString()); scenarioWithBLOBs.setCreateTime(System.currentTimeMillis()); - if (scenarioWithBLOBs.getVersionId() != null && !scenarioWithBLOBs.getVersionId().equals("update")) { - scenarioWithBLOBs.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); - // 导入时设置版本 - scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); + if (scenarioWithBLOBs.getVersionId() != null && scenarioWithBLOBs.getVersionId().equals("update")) { if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) { scenarioWithBLOBs.setVersionId(apiTestImportRequest.getVersionId()); } else { @@ -1228,24 +1226,17 @@ public class ApiAutomationService { } scenarioWithBLOBs.setLatest(true); } else { - if (StringUtils.isNotEmpty(apiTestImportRequest.getUpdateVersionId())) { - scenarioWithBLOBs.setVersionId(apiTestImportRequest.getUpdateVersionId()); + scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); + scenarioWithBLOBs.setLatest(true); // 新增接口 latest = true + scenarioWithBLOBs.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); + if (StringUtils.isNotEmpty(apiTestImportRequest.getVersionId())) { + scenarioWithBLOBs.setVersionId(apiTestImportRequest.getVersionId()); } else { scenarioWithBLOBs.setVersionId(apiTestImportRequest.getDefaultVersion()); } - scenarioWithBLOBs.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion())); } checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper); - if (scenarioWithBLOBs.getOrder() == null) { - scenarioWithBLOBs.setOrder(getImportNextOrder(scenarioWithBLOBs.getProjectId())); - } - if (scenarioWithBLOBs.getNum() == null) { - scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); - } - if (scenarioWithBLOBs.getRefId() == null) { - scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); - } batchMapper.insert(scenarioWithBLOBs); apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenarioWithBLOBs); extApiScenarioMapper.clearLatestVersion(scenarioWithBLOBs.getRefId()); @@ -1265,20 +1256,9 @@ public class ApiAutomationService { scenarioWithBLOBs.setCreateTime(System.currentTimeMillis()); scenarioWithBLOBs.setVersionId(apiTestImportRequest.getUpdateVersionId()); scenarioWithBLOBs.setLatest(apiTestImportRequest.getVersionId().equals(apiTestImportRequest.getDefaultVersion())); - if (scenarioWithBLOBs.getVersionId() != null && !scenarioWithBLOBs.getVersionId().equals("update")) { - scenarioWithBLOBs.setRefId(sameRequest.get(0).getRefId()); - scenarioWithBLOBs.setNum(sameRequest.get(0).getNum()); // 使用第一个num当作本次的num - scenarioWithBLOBs.setOrder(sameRequest.get(0).getOrder()); - } - if (scenarioWithBLOBs.getOrder() == null) { - scenarioWithBLOBs.setOrder(getImportNextOrder(scenarioWithBLOBs.getProjectId())); - } - if (scenarioWithBLOBs.getNum() == null) { - scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); - } - if (scenarioWithBLOBs.getRefId() == null) { - scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); - } + scenarioWithBLOBs.setRefId(sameRequest.get(0).getRefId() == null ? sameRequest.get(0).getId() : sameRequest.get(0).getRefId()); + scenarioWithBLOBs.setNum(sameRequest.get(0).getNum()); // 使用第一个num当作本次的num + scenarioWithBLOBs.setOrder(sameRequest.get(0).getOrder()); batchMapper.insert(scenarioWithBLOBs); } else { ApiScenarioWithBLOBs existScenario = scenarioOp.get(); @@ -1287,15 +1267,6 @@ public class ApiAutomationService { scenarioWithBLOBs.setVersionId(apiTestImportRequest.getUpdateVersionId()); scenarioWithBLOBs.setOrder(existScenario.getOrder()); scenarioWithBLOBs.setNum(existScenario.getNum()); - if (scenarioWithBLOBs.getOrder() == null) { - scenarioWithBLOBs.setOrder(getImportNextOrder(scenarioWithBLOBs.getProjectId())); - } - if (scenarioWithBLOBs.getNum() == null) { - scenarioWithBLOBs.setNum(getNextNum(scenarioWithBLOBs.getProjectId())); - } - if (scenarioWithBLOBs.getRefId() == null) { - scenarioWithBLOBs.setRefId(scenarioWithBLOBs.getId()); - } batchMapper.updateByPrimaryKeyWithBLOBs(scenarioWithBLOBs); } checkReferenceCase(scenarioWithBLOBs, apiTestCaseMapper, apiDefinitionMapper);