From 8fe70457a57a3d17a9e0f1a97f2f63cea5a24be6 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Mon, 22 Mar 2021 16:47:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=8A=A0=E8=BD=BD=E5=B7=B2=E6=9C=89=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtLoadTestMapper.java | 4 +- .../base/mapper/ext/ExtLoadTestMapper.xml | 3 + .../controller/PerformanceTestController.java | 7 +- .../request/QueryProjectFileRequest.java | 2 +- .../service/PerformanceTestService.java | 18 +++-- .../io/metersphere/service/FileService.java | 4 +- .../metersphere/service/ProjectService.java | 2 +- .../test/components/ExistFiles.vue | 78 ++++++++++--------- .../components/PerformanceBasicConfig.vue | 6 +- .../test/components/ResourceFiles.vue | 42 +++++----- 10 files changed, 92 insertions(+), 74 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java index c95006f3b8..a6c67b6c5b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.java @@ -3,6 +3,7 @@ package io.metersphere.base.mapper.ext; import io.metersphere.base.domain.FileMetadata; import io.metersphere.base.domain.LoadTest; import io.metersphere.dto.LoadTestDTO; +import io.metersphere.performance.request.QueryProjectFileRequest; import io.metersphere.performance.request.QueryTestPlanRequest; import org.apache.ibatis.annotations.Param; @@ -18,6 +19,7 @@ public interface ExtLoadTestMapper { LoadTest getNextNum(@Param("projectId") String projectId); - List getProjectFiles(@Param("projectId") String projectId, @Param("loadTypes") List loadType); + List getProjectFiles(@Param("projectId") String projectId, @Param("loadTypes") List loadType, + @Param("request") QueryProjectFileRequest request); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml index 6e77469707..8580002eff 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml @@ -145,5 +145,8 @@ #{id} AND project_id = #{projectId,jdbcType=VARCHAR} + + AND file_metadata.name LIKE CONCAT('%', #{request.name}, '%') + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java index da19e2da3c..21f845385d 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java @@ -120,12 +120,13 @@ public class PerformanceTestController { return performanceTestService.exportJmx(fileIds); } - @GetMapping("/project/{loadType}/{projectId}/{goPage}/{pageSize}") + @PostMapping("/project/{loadType}/{projectId}/{goPage}/{pageSize}") public Pager> getProjectFiles(@PathVariable String projectId, @PathVariable String loadType, - @PathVariable int goPage, @PathVariable int pageSize) { + @PathVariable int goPage, @PathVariable int pageSize, + @RequestBody QueryProjectFileRequest request) { checkPermissionService.checkProjectOwner(projectId); Page page = PageHelper.startPage(goPage, pageSize, true); - return PageUtils.setPageInfo(page, performanceTestService.getProjectFiles(projectId, loadType)); + return PageUtils.setPageInfo(page, performanceTestService.getProjectFiles(projectId, loadType, request)); } @PostMapping("/delete") diff --git a/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java b/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java index 90c71dcb8a..a8808c1c8c 100644 --- a/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java +++ b/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java @@ -4,5 +4,5 @@ import lombok.Data; @Data public class QueryProjectFileRequest { - private String filename; + private String name; } diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 6a73af82b5..8e33726a6f 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -561,19 +561,23 @@ public class PerformanceTestService { } } - public List getProjectFiles(String projectId, String loadType) { + public List getProjectFiles(String projectId, String loadType, QueryProjectFileRequest request) { List loadTypes = new ArrayList<>(); loadTypes.add(StringUtils.upperCase(loadType)); if (StringUtils.equalsIgnoreCase(loadType, "resource")) { - loadTypes.add(FileType.CSV.name()); - loadTypes.add(FileType.JAR.name()); + List fileTypes = Arrays.stream(FileType.values()) + .filter(fileType -> !fileType.equals(FileType.JMX)) + .map(FileType::name) + .collect(Collectors.toList()); + loadTypes.addAll(fileTypes); } if (StringUtils.equalsIgnoreCase(loadType, "all")) { - loadTypes.add(FileType.CSV.name()); - loadTypes.add(FileType.JAR.name()); - loadTypes.add(FileType.JMX.name()); + List fileTypes = Arrays.stream(FileType.values()) + .map(FileType::name) + .collect(Collectors.toList()); + loadTypes.addAll(fileTypes); } - return extLoadTestMapper.getProjectFiles(projectId, loadTypes); + return extLoadTestMapper.getProjectFiles(projectId, loadTypes, request); } public List exportJmx(List fileIds) { diff --git a/backend/src/main/java/io/metersphere/service/FileService.java b/backend/src/main/java/io/metersphere/service/FileService.java index e1d7b3ffd1..cc2aa106c2 100644 --- a/backend/src/main/java/io/metersphere/service/FileService.java +++ b/backend/src/main/java/io/metersphere/service/FileService.java @@ -202,8 +202,8 @@ public class FileService { FileMetadataExample example = new FileMetadataExample(); FileMetadataExample.Criteria criteria = example.createCriteria(); criteria.andProjectIdEqualTo(projectId); - if (!StringUtils.isEmpty(request.getFilename())) { - criteria.andNameEqualTo(request.getFilename()); + if (!StringUtils.isEmpty(request.getName())) { + criteria.andNameEqualTo(request.getName()); } return fileMetadataMapper.selectByExample(example); } diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 77a218d37e..d0b601c31c 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -173,7 +173,7 @@ public class ProjectService { if (files != null) { for (MultipartFile file : files) { QueryProjectFileRequest request = new QueryProjectFileRequest(); - request.setFilename(file.getOriginalFilename()); + request.setName(file.getOriginalFilename()); if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) { fileService.saveFile(file, projectId); } else { diff --git a/frontend/src/business/components/performance/test/components/ExistFiles.vue b/frontend/src/business/components/performance/test/components/ExistFiles.vue index b605c0a58e..e62d21ca7a 100644 --- a/frontend/src/business/components/performance/test/components/ExistFiles.vue +++ b/frontend/src/business/components/performance/test/components/ExistFiles.vue @@ -3,42 +3,42 @@ :destroy-on-close="true" :title="$t('load_test.exist_jmx')" width="70%" :visible.sync="loadFileVisible"> - - - - - - - - - - + + + { + this.projectLoadingResult = this.$post('/performance/project/' + this.loadType + '/' + getCurrentProjectID() + "/" + this.currentPage + "/" + this.pageSize, this.condition, res => { let data = res.data; this.total = data.itemCount; this.existFiles = data.listObject; diff --git a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue index 349ab2d841..7cf3d68831 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceBasicConfig.vue @@ -329,10 +329,10 @@ export default { } return true; }, - beforeUploadJmx(file){ + beforeUploadJmx(file) { this.$refs.existFiles.beforeUploadFile(file); }, - handleUpload(file){ + handleUpload(file) { this.$refs.existFiles.handleUpload(file); }, }, @@ -341,7 +341,7 @@ export default {