diff --git a/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java b/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java index acdd872aab..6ebfbf5220 100644 --- a/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/QueryAPIReportRequest.java @@ -1,8 +1,12 @@ package io.metersphere.api.dto; +import io.metersphere.controller.request.OrderRequest; import lombok.Getter; import lombok.Setter; +import java.util.List; +import java.util.Map; + @Getter @Setter public class QueryAPIReportRequest { @@ -12,5 +16,6 @@ public class QueryAPIReportRequest { private String name; private String workspaceId; private boolean recent = false; - + private List orders; + private Map> filters; } diff --git a/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java b/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java index 88bbd2b3f8..9c7daa2fdb 100644 --- a/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java @@ -1,8 +1,12 @@ package io.metersphere.api.dto; +import io.metersphere.controller.request.OrderRequest; import lombok.Getter; import lombok.Setter; +import java.util.List; +import java.util.Map; + @Getter @Setter public class QueryAPITestRequest { @@ -12,5 +16,7 @@ public class QueryAPITestRequest { private String name; private String workspaceId; private boolean recent = false; - + private List orders; + private Map> filters; + } diff --git a/backend/src/main/java/io/metersphere/api/service/APIReportService.java b/backend/src/main/java/io/metersphere/api/service/APIReportService.java index 56916e1bbe..3fbd7c11e2 100644 --- a/backend/src/main/java/io/metersphere/api/service/APIReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/APIReportService.java @@ -11,12 +11,14 @@ import io.metersphere.base.mapper.ApiTestReportMapper; import io.metersphere.base.mapper.ext.ExtApiTestReportMapper; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.DashboardTestDTO; import io.metersphere.i18n.Translator; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -24,8 +26,6 @@ import java.util.List; import java.util.Objects; import java.util.UUID; -import javax.annotation.Resource; - @Service @Transactional(rollbackFor = Exception.class) public class APIReportService { @@ -38,6 +38,7 @@ public class APIReportService { private ExtApiTestReportMapper extApiTestReportMapper; public List list(QueryAPIReportRequest request) { + request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); return extApiTestReportMapper.list(request); } 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 a9a4952f03..306fd61c94 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -1,7 +1,6 @@ package io.metersphere.api.service; import io.metersphere.api.dto.APITestResult; -import io.metersphere.api.dto.DeleteAPITestRequest; import io.metersphere.api.dto.QueryAPITestRequest; import io.metersphere.api.dto.SaveAPITestRequest; import io.metersphere.api.jmeter.JMeterService; @@ -11,6 +10,7 @@ import io.metersphere.base.mapper.ApiTestMapper; import io.metersphere.base.mapper.ext.ExtApiTestMapper; import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.i18n.Translator; import io.metersphere.service.FileService; @@ -19,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; 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; @@ -26,8 +27,6 @@ import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; -import javax.annotation.Resource; - @Service @Transactional(rollbackFor = Exception.class) public class APITestService { @@ -46,6 +45,7 @@ public class APITestService { private APIReportService apiReportService; public List list(QueryAPITestRequest request) { + request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); return extApiTestMapper.list(request); } @@ -130,10 +130,22 @@ 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()); @@ -150,10 +162,22 @@ 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); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestMapper.xml index 895d082944..1c399ac442 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestMapper.xml @@ -26,8 +26,23 @@ AND api_test.id = #{request.id} + + + + and api_test.${key} in + + #{value} + + + + - order by api_test.update_time desc + + order by + + api_test.${order.name} ${order.type} + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml index 2ccd8dede8..23ef69272d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtProjectMapper.xml @@ -15,7 +15,12 @@ and w.id = #{proRequest.workspaceId} - order by p.update_time desc + + order by + + p.${order.name} ${order.type} + +