refactor: 代码重构-通用代码块提取

代码重构-通用代码块提取
This commit is contained in:
song.tianyang 2021-01-20 10:55:12 +08:00
parent 66c14eea89
commit d99fa9b568
3 changed files with 73 additions and 30 deletions

View File

@ -50,9 +50,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@ -86,7 +83,23 @@ public class ApiAutomationService {
private ApiScenarioReportMapper apiScenarioReportMapper;
public List<ApiScenarioDTO> list(ApiScenarioRequest request) {
request = this.initRequest(request,true,true);
List<ApiScenarioDTO> list = extApiScenarioMapper.list(request);
return list;
}
/**
* 初始化部分参数
* @param request
* @param setDefultOrders
* @param checkThisWeekData
* @return
*/
private ApiScenarioRequest initRequest(ApiScenarioRequest request,boolean setDefultOrders, boolean checkThisWeekData) {
if(setDefultOrders){
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
}
if(checkThisWeekData){
if (request.isSelectThisWeedData()) {
Map<String, Date> weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date());
Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime");
@ -94,8 +107,8 @@ public class ApiAutomationService {
request.setCreateTime(weekFirstTime.getTime());
}
}
List<ApiScenarioDTO> list = extApiScenarioMapper.list(request);
return list;
}
return request;
}

View File

@ -79,9 +79,24 @@ public class ApiDefinitionService {
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
request = this.initRequest(request,true,true);
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
calculateResult(resList);
return resList;
}
//判断是否查询本周数据
/**
* 初始化部分参数
* @param request
* @param setDefultOrders
* @param checkThisWeekData
* @return
*/
private ApiDefinitionRequest initRequest(ApiDefinitionRequest request,boolean setDefultOrders, boolean checkThisWeekData) {
if(setDefultOrders){
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
}
if(checkThisWeekData){
if (request.isSelectThisWeedData()) {
Map<String, Date> weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date());
Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime");
@ -89,10 +104,8 @@ public class ApiDefinitionService {
request.setCreateTime(weekFirstTime.getTime());
}
}
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
calculateResult(resList);
return resList;
}
return request;
}
public ApiDefinition get(String id) {

View File

@ -83,7 +83,28 @@ public class ApiTestCaseService {
}
public List<ApiTestCaseDTO> listSimple(ApiTestCaseRequest request) {
request = this.initRequest(request,true,true);
List<ApiTestCaseDTO> apiTestCases = extApiTestCaseMapper.listSimple(request);
if (CollectionUtils.isEmpty(apiTestCases)) {
return apiTestCases;
}
buildUserInfo(apiTestCases);
return apiTestCases;
}
/**
* 初始化部分参数
* @param request
* @param setDefultOrders
* @param checkThisWeekData
* @return
*/
private ApiTestCaseRequest initRequest(ApiTestCaseRequest request, boolean setDefultOrders, boolean checkThisWeekData) {
if(setDefultOrders){
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
}
if(checkThisWeekData){
if (request.isSelectThisWeedData()) {
Map<String, Date> weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date());
Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime");
@ -91,12 +112,8 @@ public class ApiTestCaseService {
request.setCreateTime(weekFirstTime.getTime());
}
}
List<ApiTestCaseDTO> apiTestCases = extApiTestCaseMapper.listSimple(request);
if (CollectionUtils.isEmpty(apiTestCases)) {
return apiTestCases;
}
buildUserInfo(apiTestCases);
return apiTestCases;
return request;
}
public void buildUserInfo(List<? extends ApiTestCaseDTO> apiTestCases) {