diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java index d9b9413239..587478b3d1 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsScenarioParser.java @@ -124,7 +124,7 @@ public class MsScenarioParser extends MsAbstractParser { parseModule(item.getModulePath(), importRequest, item); } - item.setId(UUID.randomUUID().toString()); +// item.setId(UUID.randomUUID().toString()); item.setProjectId(this.projectId); }); } 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 7f13547fb6..ed0b0f7706 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1759,9 +1759,20 @@ public class ApiAutomationService { } } - public List getWithBLOBs(ApiScenarioWithBLOBs request) { + public List getSameScenario(ApiScenarioWithBLOBs request) { ApiScenarioExample example = new ApiScenarioExample(); - example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andStatusNotEqualTo("Trash").andIdNotEqualTo(request.getId()); + ApiScenarioExample.Criteria criteria = example.createCriteria(); + criteria.andProjectIdEqualTo(request.getProjectId()) + .andStatusNotEqualTo("Trash") + .andNameEqualTo(request.getName()); + if (StringUtils.isNotBlank(request.getId())) { + // id 不为空 则判断,id一样或者名字一样则是同一个用例 + ApiScenarioExample.Criteria criteria1 = example.createCriteria(); + criteria1.andProjectIdEqualTo(request.getProjectId()) + .andStatusNotEqualTo("Trash") + .andIdEqualTo(request.getId()); + example.or(criteria1); + } return apiScenarioMapper.selectByExampleWithBLOBs(example); } @@ -1803,7 +1814,7 @@ public class ApiAutomationService { } scenarioWithBLOBs.setDescription(request.getDescription()); - List sameRequest = getWithBLOBs(scenarioWithBLOBs); + List sameRequest = getSameScenario(scenarioWithBLOBs); Boolean openCustomNum = apiTestImportRequest.getOpenCustomNum(); List list = new ArrayList<>(); @@ -1857,8 +1868,8 @@ public class ApiAutomationService { int num = 0; Project project = new Project(); if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) { - num = getNextNum(data.get(0).getProjectId()); project = projectMapper.selectByPrimaryKey(data.get(0).getProjectId()); + num = getNextNum(data.get(0).getProjectId()); request.setOpenCustomNum(project.getScenarioCustomNum()); } for (int i = 0; i < data.size(); i++) { @@ -1876,6 +1887,9 @@ public class ApiAutomationService { } } num++; + if (StringUtils.isBlank(item.getId())) { + item.setId(UUID.randomUUID().toString()); + } importCreate(item, batchMapper, request); if (i % 300 == 0) { sqlSession.flushStatements(); 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 93155591cd..a0497323d7 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -648,7 +648,8 @@ public class ApiDefinitionService { SaveApiTestCaseRequest checkRequest = new SaveApiTestCaseRequest(); checkRequest.setName(apiTestCase.getName()); checkRequest.setApiDefinitionId(apiTestCase.getApiDefinitionId()); - ApiTestCase sameCase = apiTestCaseService.getSameCase(checkRequest); + checkRequest.setId(apiTestCase.getId()); + ApiTestCase sameCase = apiTestCaseService.getImportSameCase(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 b43a5bb046..3c4e813f7f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -265,19 +265,6 @@ 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()); @@ -286,9 +273,14 @@ public class ApiTestCaseService { } List apiTestCases = apiTestCaseMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(apiTestCases)) { - return apiTestCases.get(0); + if (apiTestCases.get(0) != null) { + MSException.throwException(Translator.get("load_test_already_exists")); + }; } - return null; + } + + public ApiTestCase getImportSameCase(SaveApiTestCaseRequest request) { + return extApiTestCaseMapper.selectSameCase(request); } 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 7de06e83c8..b2e167f378 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 @@ -1,10 +1,7 @@ package io.metersphere.base.mapper.ext; import io.metersphere.api.dto.datacount.ApiDataCountResult; -import io.metersphere.api.dto.definition.ApiTestCaseDTO; -import io.metersphere.api.dto.definition.ApiTestCaseInfo; -import io.metersphere.api.dto.definition.ApiTestCaseRequest; -import io.metersphere.api.dto.definition.ApiTestCaseResult; +import io.metersphere.api.dto.definition.*; import io.metersphere.base.domain.ApiDefinition; import io.metersphere.base.domain.ApiTestCase; import io.metersphere.controller.request.BaseQueryRequest; @@ -60,4 +57,6 @@ 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 7638cb0273..cc8ffda846 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,6 +596,19 @@ order by `order` desc limit 1; + update api_test_case