From b9d96cf60c6915458c3c98fa6f27824710eb0dc7 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 5 Jul 2022 19:46:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9C=AA=E9=80=89=E6=A8=A1=E5=9D=97=E4=B8=8D?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E6=97=B6=E6=8E=A5=E5=8F=A3=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E7=94=A8=E4=BE=8B=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=E4=BB=A5=E5=8F=8A=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=BC=E5=85=A5=E6=9F=A5=E8=AF=A2=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=97=B6=E6=8E=92=E9=99=A4=E5=B7=B2=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1014659 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014659 【接口测试】sql协议导入jmeter文件,接口删除后,再次导入相同的文件,提示格式错误 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014649 【接口测试】sql协议导入的文件删除后,再次导入文件导入失败 --- .../parse/ApiScenarioImportUtil.java | 2 +- .../api/service/ApiDefinitionService.java | 2 +- .../api/service/ApiTestCaseService.java | 30 +++++++++++++++---- .../mapper/ext/ExtApiDefinitionMapper.xml | 1 + 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java index 2fe45151ce..4423496a7b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/ApiScenarioImportUtil.java @@ -271,7 +271,7 @@ public class ApiScenarioImportUtil { apiTestCase.setUpdateTime(System.currentTimeMillis()); apiTestCase.setVersionId(apiDefinition.getVersionId()); apiTestCase.setPriority("P0"); - apiTestCase.setNum(testCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum() + i)); + apiTestCase.setNum(testCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum() + i, projectId)); object.put("id", apiTestCase.getId()); object.put("resourceId", apiTestCase.getId()); object.put("projectId", projectId); 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 fef6b01e15..0861af263d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -1113,7 +1113,7 @@ public class ApiDefinitionService { if (sameCase == null) { apiTestCase.setId(UUID.randomUUID().toString()); apiTestCase.setStatus(""); - apiTestCase.setNum(apiTestCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum())); + apiTestCase.setNum(apiTestCaseService.getNextNum(apiTestCase.getApiDefinitionId(), apiDefinition.getNum(), apiDefinition.getProjectId())); apiTestCase.setCreateTime(System.currentTimeMillis()); apiTestCase.setUpdateTime(System.currentTimeMillis()); apiTestCase.setCreateUserId(SessionUtils.getUserId()); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 2940421227..2d9492ebba 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -111,6 +111,8 @@ public class ApiTestCaseService { private TcpApiParamService tcpApiParamService; @Resource private ObjectMapper mapper; + @Resource + private ExtApiDefinitionMapper extApiDefinitionMapper; private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; @@ -471,25 +473,43 @@ public class ApiTestCaseService { public int getNextNum(String definitionId) { ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId); + ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(definitionId); if (apiTestCase == null) { - int n = apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum(); + int n = apiDefinitionWithBLOBs.getNum(); return n * 1000 + 1; } else { return Optional.of(apiTestCase.getNum() + 1) - .orElse(apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1); + .orElse(apiDefinitionWithBLOBs.getNum() * 1000 + 1); } } - public int getNextNum(String definitionId, Integer definitionNum) { + public int getNextNum(String definitionId, Integer definitionNum, String projectId) { ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId); + ApiDefinitionWithBLOBs apiDefinitionWithBLOBs = apiDefinitionMapper.selectByPrimaryKey(definitionId); + int apiDefinitionNum; + if (apiDefinitionWithBLOBs != null && apiDefinitionWithBLOBs.getNum() != null) { + apiDefinitionNum = apiDefinitionWithBLOBs.getNum() * 1000 + 1; + } else { + apiDefinitionNum = getNextNumByProjectId(projectId); + } if (apiTestCase == null) { if (definitionNum == null) { - return apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1; + return apiDefinitionNum; + } return definitionNum * 1000 + 1; } else { return Optional.of(apiTestCase.getNum() + 1) - .orElse(apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1); + .orElse(apiDefinitionNum); + } + } + + public int getNextNumByProjectId(String projectId) { + ApiDefinition apiDefinition = extApiDefinitionMapper.getNextNum(projectId); + if (apiDefinition == null || apiDefinition.getNum() == null) { + return 100001; + } else { + return Optional.of(apiDefinition.getNum() + 1).orElse(100001); } } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index 14a73ce78e..7371ac8e4d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -1022,6 +1022,7 @@ #{versionId} and protocol = #{protocol} + and status != 'Trash'