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 f868db1e90..3b990d587a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -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,18 +83,34 @@ public class ApiAutomationService { private ApiScenarioReportMapper apiScenarioReportMapper; public List list(ApiScenarioRequest request) { - request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); - if (request.isSelectThisWeedData()) { - Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); - Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); - if (weekFirstTime != null) { - request.setCreateTime(weekFirstTime.getTime()); - } - } + request = this.initRequest(request,true,true); List 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 weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); + if (weekFirstTime != null) { + request.setCreateTime(weekFirstTime.getTime()); + } + } + } + return request; + } + public List selectIdsNotExistsInPlan(String projectId, String planId) { return extApiScenarioMapper.selectIdsNotExistsInPlan(projectId, planId); 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 1681d96fa2..925589dd48 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -79,22 +79,35 @@ public class ApiDefinitionService { private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; public List list(ApiDefinitionRequest request) { - request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); - - //判断是否查询本周数据 - if (request.isSelectThisWeedData()) { - Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); - Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); - if (weekFirstTime != null) { - request.setCreateTime(weekFirstTime.getTime()); - } - } - + request = this.initRequest(request,true,true); List 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 weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); + if (weekFirstTime != null) { + request.setCreateTime(weekFirstTime.getTime()); + } + } + } + return request; + } + public ApiDefinition get(String id) { return apiDefinitionMapper.selectByPrimaryKey(id); } 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 c151f7c1f7..1d179da506 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -83,14 +83,8 @@ public class ApiTestCaseService { } public List listSimple(ApiTestCaseRequest request) { - request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); - if (request.isSelectThisWeedData()) { - Map weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); - Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); - if (weekFirstTime != null) { - request.setCreateTime(weekFirstTime.getTime()); - } - } + request = this.initRequest(request,true,true); + List apiTestCases = extApiTestCaseMapper.listSimple(request); if (CollectionUtils.isEmpty(apiTestCases)) { return apiTestCases; @@ -99,6 +93,29 @@ public class ApiTestCaseService { 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 weekFirstTimeAndLastTime = DateUtils.getWeedFirstTimeAndLastTime(new Date()); + Date weekFirstTime = weekFirstTimeAndLastTime.get("firstTime"); + if (weekFirstTime != null) { + request.setCreateTime(weekFirstTime.getTime()); + } + } + } + return request; + } + public void buildUserInfo(List apiTestCases) { List userIds = new ArrayList(); userIds.addAll(apiTestCases.stream().map(ApiTestCaseDTO::getCreateUserId).collect(Collectors.toList()));