From fdc7db695d4a8fd65002f5d9d6dd37b0b9bd8967 Mon Sep 17 00:00:00 2001 From: q4speed Date: Wed, 15 Jul 2020 10:25:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/service/APITestService.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 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 5782b43a72..7f49463951 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -2,17 +2,15 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSONObject; import io.metersphere.api.dto.APITestResult; -import io.metersphere.api.dto.parse.ApiImport; import io.metersphere.api.dto.QueryAPITestRequest; import io.metersphere.api.dto.SaveAPITestRequest; +import io.metersphere.api.dto.parse.ApiImport; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.api.parse.ApiImportParser; import io.metersphere.api.parse.ApiImportParserFactory; -import io.metersphere.api.parse.MsParser; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiTestFileMapper; import io.metersphere.base.mapper.ApiTestMapper; -import io.metersphere.base.mapper.TestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiTestMapper; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.FileType; @@ -33,12 +31,16 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.Resource; - -import java.io.*; -import java.util.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import java.util.UUID; import java.util.stream.Collectors; +import javax.annotation.Resource; + @Service @Transactional(rollbackFor = Exception.class) public class APITestService { @@ -58,8 +60,6 @@ public class APITestService { @Resource private ScheduleService scheduleService; @Resource - private TestCaseMapper testCaseMapper; - @Resource private TestCaseService testCaseService; public List list(QueryAPITestRequest request) { @@ -176,10 +176,7 @@ public class APITestService { private Boolean isNameExist(SaveAPITestRequest request) { ApiTestExample example = new ApiTestExample(); example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId()); - if (apiTestMapper.countByExample(example) > 0) { - return true; - } - return false; + return apiTestMapper.countByExample(example) > 0; } private ApiTest updateTest(SaveAPITestRequest request) { @@ -284,7 +281,7 @@ public class APITestService { request.setName(file.getOriginalFilename()); request.setProjectId(""); request.setScenarioDefinition(apiImport.getScenarios()); - request.setUserId(SessionUtils.getUser().getId()); + request.setUserId(SessionUtils.getUserId()); request.setId(UUID.randomUUID().toString()); for (FileType fileType : FileType.values()) { String suffix = fileType.suffix(); @@ -293,7 +290,7 @@ public class APITestService { request.setName(name.substring(0, name.length() - suffix.length())); } } - ; + if (isNameExist(request)) { request.setName(request.getName() + "_" + request.getId().substring(0, 5)); }