refactor: 优化

This commit is contained in:
q4speed 2020-07-15 10:25:52 +08:00
parent c3e32f2df8
commit fdc7db695d

View File

@ -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<APITestResult> 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));
}