From c33863e02157e3312b4cc2739dedb0604767b7a9 Mon Sep 17 00:00:00 2001 From: metersphere-bot <78466014+metersphere-bot@users.noreply.github.com> Date: Wed, 22 Sep 2021 21:03:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9D=9Ehttp=E6=8E=A5=E5=8F=A3=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=8A=A5=E9=94=99=20(#6371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: chenjianxing --- .../api/service/ApiDefinitionService.java | 42 ++++++++++++------- .../api/service/ApiTestCaseService.java | 33 ++++++++++++--- .../base/mapper/ext/ExtApiTestCaseMapper.java | 2 - .../base/mapper/ext/ExtApiTestCaseMapper.xml | 14 ------- .../api/definition/components/ApiConfig.vue | 6 ++- 5 files changed, 61 insertions(+), 36 deletions(-) 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 a0497323d7..716ec384f4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -346,13 +346,22 @@ public class ApiDefinitionService { private List getSameRequestWithName(SaveApiDefinitionRequest request) { ApiDefinitionExample example = new ApiDefinitionExample(); - example.createCriteria() - .andMethodEqualTo(request.getMethod()) - .andStatusNotEqualTo("Trash") - .andPathEqualTo(request.getPath()) - .andNameEqualTo(request.getName()) - .andProjectIdEqualTo(request.getProjectId()) - .andIdNotEqualTo(request.getId()); + if (request.getProtocol().equals(RequestType.HTTP)) { + example.createCriteria() + .andMethodEqualTo(request.getMethod()) + .andStatusNotEqualTo("Trash") + .andPathEqualTo(request.getPath()) + .andNameEqualTo(request.getName()) + .andProjectIdEqualTo(request.getProjectId()) + .andIdNotEqualTo(request.getId()); + } else { + example.createCriteria() + .andStatusNotEqualTo("Trash") + .andNameEqualTo(request.getName()) + .andProjectIdEqualTo(request.getProjectId()) + .andIdNotEqualTo(request.getId()); + } + return apiDefinitionMapper.selectByExample(example); } @@ -489,9 +498,12 @@ public class ApiDefinitionService { } else if (StringUtils.equals("incrementalMerge", apiTestImportRequest.getModeId())) { if (CollectionUtils.isEmpty(sameRequest)) { //postman 可能含有前置脚本,接口定义去掉脚本 - String requestStr = setImportHashTree(apiDefinition); apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); batchMapper.insert(apiDefinition); + String originId = apiDefinition.getId(); + apiDefinition.setId(UUID.randomUUID().toString()); + String requestStr = setImportHashTree(apiDefinition); + reSetImportCasesApiId(cases, originId, apiDefinition.getId()); apiDefinition.setRequest(requestStr); importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true); } @@ -526,19 +538,18 @@ public class ApiDefinitionService { ApiTestCaseMapper apiTestCaseMapper, ApiTestImportRequest apiTestImportRequest, List cases) { String originId = apiDefinition.getId(); if (CollectionUtils.isEmpty(sameRequest)) { + apiDefinition.setId(UUID.randomUUID().toString()); + apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); + reSetImportCasesApiId(cases, originId, apiDefinition.getId()); if (StringUtils.equalsIgnoreCase(apiDefinition.getProtocol(), RequestType.HTTP)) { - String request = setImportHashTree(apiDefinition); - apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); - apiDefinition.setId(UUID.randomUUID().toString()); - reSetImportCasesApiId(cases, originId, apiDefinition.getId()); batchMapper.insert(apiDefinition); + String request = setImportHashTree(apiDefinition); apiDefinition.setRequest(request); importApiCase(apiDefinition, apiTestCaseMapper, apiTestImportRequest, true); } else { if (StringUtils.equalsAnyIgnoreCase(apiDefinition.getProtocol(), RequestType.TCP)) { setImportTCPHashTree(apiDefinition); } - apiDefinition.setOrder(getImportNextOrder(apiTestImportRequest.getProjectId())); batchMapper.insert(apiDefinition); } @@ -649,7 +660,10 @@ public class ApiDefinitionService { checkRequest.setName(apiTestCase.getName()); checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId()); checkRequest.setId(apiTestCase.getId()); - ApiTestCase sameCase = apiTestCaseService.getImportSameCase(checkRequest); + ApiTestCase sameCase = apiTestCaseService.getSameCase(checkRequest); + if (sameCase == null) { + sameCase = apiTestCaseService.getSameCaseById(checkRequest); + } apiTestCase.setUpdateUserId(SessionUtils.getUserId()); if (sameCase == null) { apiTestCase.setId(UUID.randomUUID().toString()); 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 5e77219593..1e99bd08b3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -279,6 +279,19 @@ public class ApiTestCaseService { } public void checkNameExist(SaveApiTestCaseRequest request) { + if (hasSameCase(request)) { + MSException.throwException(Translator.get("load_test_already_exists")); + } + } + + public Boolean hasSameCase(SaveApiTestCaseRequest request) { + if (getSameCase(request) != null) { + return true; + } + return false; + } + + public ApiTestCase getSameCase(SaveApiTestCaseRequest request) { ApiTestCaseExample example = new ApiTestCaseExample(); ApiTestCaseExample.Criteria criteria = example.createCriteria(); criteria.andStatusNotEqualTo("Trash").andNameEqualTo(request.getName()).andApiDefinitionIdEqualTo(request.getApiDefinitionId()); @@ -287,14 +300,24 @@ public class ApiTestCaseService { } List apiTestCases = apiTestCaseMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(apiTestCases)) { - if (apiTestCases.get(0) != null) { - MSException.throwException(Translator.get("load_test_already_exists")); - }; + return apiTestCases.get(0); } + return null; } - public ApiTestCase getImportSameCase(SaveApiTestCaseRequest request) { - return extApiTestCaseMapper.selectSameCase(request); + public ApiTestCase getSameCaseById(SaveApiTestCaseRequest request) { + if (StringUtils.isNotBlank(request.getId())) { + ApiTestCaseExample example = new ApiTestCaseExample(); + ApiTestCaseExample.Criteria criteria = example.createCriteria(); + criteria.andStatusNotEqualTo("Trash") + .andApiDefinitionIdEqualTo(request.getApiDefinitionId()); + criteria.andIdEqualTo(request.getId()); + List apiTestCases = apiTestCaseMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(apiTestCases)) { + return apiTestCases.get(0); + } + } + return null; } private ApiTestCase updateTest(SaveApiTestCaseRequest request) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java index b2e167f378..1933160b42 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java @@ -57,6 +57,4 @@ public interface ExtApiTestCaseMapper { Long getPreOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder); Long getLastOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder); - - ApiTestCase selectSameCase(@Param("request") SaveApiTestCaseRequest request); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index 093f52ed06..18a4ece5b8 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -596,20 +596,6 @@ order by `order` desc limit 1; - - update api_test_case set original_status=status, diff --git a/frontend/src/business/components/api/definition/components/ApiConfig.vue b/frontend/src/business/components/api/definition/components/ApiConfig.vue index 6cc5ce1934..4036b23882 100644 --- a/frontend/src/business/components/api/definition/components/ApiConfig.vue +++ b/frontend/src/business/components/api/definition/components/ApiConfig.vue @@ -248,7 +248,11 @@ if (data.isCopy) { data.id = getUUID(); } else { - data.id = data.request.id; + if (data.id) { + data.request.id = data.id; + } else { + data.id = data.request.id; + } } if (!data.method) {