From a64685abdf301eeaa2a2da13729df6aff92dc46e Mon Sep 17 00:00:00 2001 From: q4speed Date: Wed, 3 Jun 2020 11:43:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E9=87=8D=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/APITestService.java | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index 306fd61c94..ec01335a93 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; + import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.List; @@ -122,7 +123,16 @@ public class APITestService { apiTestMapper.updateByPrimaryKeySelective(apiTest); } + private void checkNameExist(SaveAPITestRequest request) { + ApiTestExample example = new ApiTestExample(); + example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId()); + if (apiTestMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("load_test_already_exists")); + } + } + private ApiTestWithBLOBs updateTest(SaveAPITestRequest request) { + checkNameExist(request); final ApiTestWithBLOBs test = new ApiTestWithBLOBs(); test.setId(request.getId()); test.setName(request.getName()); @@ -130,29 +140,12 @@ public class APITestService { test.setScenarioDefinition(request.getScenarioDefinition()); test.setUpdateTime(System.currentTimeMillis()); test.setStatus(APITestStatus.Saved.name()); - checkApiTestExist(test); apiTestMapper.updateByPrimaryKeySelective(test); return test; } - private void checkApiTestExist(ApiTest apiTest) { - if (apiTest.getName() != null) { - ApiTestExample example = new ApiTestExample(); - example.createCriteria() - .andNameEqualTo(apiTest.getName()); - if (apiTestMapper.selectByExample(example).size() > 0) { - MSException.throwException(Translator.get("api_test_name_already_exists")); - } - } - } - private ApiTestWithBLOBs createTest(SaveAPITestRequest request) { - ApiTestExample example = new ApiTestExample(); - example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()); - if (apiTestMapper.countByExample(example) > 0) { - MSException.throwException(Translator.get("load_test_already_exists")); - } - + checkNameExist(request); final ApiTestWithBLOBs test = new ApiTestWithBLOBs(); test.setId(request.getId()); test.setName(request.getName()); @@ -162,22 +155,10 @@ public class APITestService { test.setUpdateTime(System.currentTimeMillis()); test.setStatus(APITestStatus.Saved.name()); test.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId()); - checkApiTestPlanExist(test); apiTestMapper.insert(test); return test; } - private void checkApiTestPlanExist(ApiTest apiTest) { - if (apiTest.getName() != null) { - ApiTestExample example = new ApiTestExample(); - example.createCriteria() - .andNameEqualTo(apiTest.getName()); - if (apiTestMapper.selectByExample(example).size() > 0) { - MSException.throwException(Translator.get("api_test_name_already_exists")); - } - } - } - private void saveFile(String testId, List files) { files.forEach(file -> { final FileMetadata fileMetadata = fileService.saveFile(file);