From 21de1ba11ff11ccd5bb0baf8b7e2db6928782c0c Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 25 Mar 2021 11:20:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=96=87=E4=BB=B6=E6=9B=B4=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProjectController.java | 7 ++- .../io/metersphere/service/FileService.java | 14 +++-- .../metersphere/service/ProjectService.java | 13 +++++ .../test/components/ResourceFiles.vue | 54 ++++++++++++++++++- frontend/src/i18n/en-US.js | 3 +- frontend/src/i18n/zh-CN.js | 3 +- frontend/src/i18n/zh-TW.js | 3 +- 7 files changed, 88 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/ProjectController.java b/backend/src/main/java/io/metersphere/controller/ProjectController.java index 1711633b9b..f9feec4b15 100644 --- a/backend/src/main/java/io/metersphere/controller/ProjectController.java +++ b/backend/src/main/java/io/metersphere/controller/ProjectController.java @@ -88,7 +88,12 @@ public class ProjectController { @PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"}) public List uploadFiles(@PathVariable String projectId, @RequestPart(value = "file") List files) { - return projectService.uploadFiles(projectId, files); + return projectService.uploadFiles(projectId, files); + } + + @PostMapping(value = "/update/file/{projectId}/{fileId}", consumes = {"multipart/form-data"}) + public FileMetadata updateFile(@PathVariable String projectId, @PathVariable String fileId, @RequestPart(value = "file") MultipartFile file) { + return projectService.updateFile(projectId, fileId, file); } @GetMapping(value = "delete/file/{fileId}") diff --git a/backend/src/main/java/io/metersphere/service/FileService.java b/backend/src/main/java/io/metersphere/service/FileService.java index cc2aa106c2..817ca5826d 100644 --- a/backend/src/main/java/io/metersphere/service/FileService.java +++ b/backend/src/main/java/io/metersphere/service/FileService.java @@ -73,9 +73,13 @@ public class FileService { fileContentMapper.deleteByExample(example2); } - public FileMetadata saveFile(MultipartFile file, String projectId) { + public FileMetadata saveFile(MultipartFile file, String projectId, String fileId) { final FileMetadata fileMetadata = new FileMetadata(); - fileMetadata.setId(UUID.randomUUID().toString()); + if (StringUtils.isEmpty(fileId)) { + fileMetadata.setId(UUID.randomUUID().toString()); + } else { + fileMetadata.setId(fileId); + } fileMetadata.setName(file.getOriginalFilename()); fileMetadata.setSize(file.getSize()); fileMetadata.setProjectId(projectId); @@ -97,6 +101,10 @@ public class FileService { return fileMetadata; } + public FileMetadata saveFile(MultipartFile file, String projectId) { + return saveFile(file, projectId, null); + } + public FileMetadata saveFile(MultipartFile file) { return saveFile(file, null); } @@ -205,7 +213,7 @@ public class FileService { if (!StringUtils.isEmpty(request.getName())) { criteria.andNameEqualTo(request.getName()); } - return fileMetadataMapper.selectByExample(example); + return fileMetadataMapper.selectByExample(example); } public List getFileMetadataByIds(List fileIds) { diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 4723f29dc3..7fea391b86 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -186,6 +186,18 @@ public class ProjectService { return result; } + public FileMetadata updateFile(String projectId, String fileId, MultipartFile file) { + QueryProjectFileRequest request = new QueryProjectFileRequest(); + request.setName(file.getOriginalFilename()); + if (CollectionUtils.isEmpty(fileService.getProjectFiles(projectId, request))) { + fileService.deleteFileById(fileId); + return fileService.saveFile(file, projectId); + } else { + MSException.throwException(Translator.get("project_file_already_exists")); + } + return null; + } + public void deleteFile(String fileId) { LoadTestFileExample example1 = new LoadTestFileExample(); example1.createCriteria().andFileIdEqualTo(fileId); @@ -216,4 +228,5 @@ public class ProjectService { } fileService.deleteFileById(fileId); } + } diff --git a/frontend/src/business/components/performance/test/components/ResourceFiles.vue b/frontend/src/business/components/performance/test/components/ResourceFiles.vue index 5e26e276f2..b05920888b 100644 --- a/frontend/src/business/components/performance/test/components/ResourceFiles.vue +++ b/frontend/src/business/components/performance/test/components/ResourceFiles.vue @@ -16,7 +16,7 @@ :before-upload="beforeUploadFile" :http-request="handleUpload" :on-exceed="handleExceed" - :file-list="fileList"> + > @@ -46,6 +46,23 @@