From 1deed2b8a79648125b2b12fbe37f289c3acfc93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Mon, 15 Apr 2024 16:29:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=95=B0=E6=8D=AE=E9=9B=86=E3=80=81=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dataset/DatasetController.java | 7 +++-- .../controller/model/ModelsController.java | 10 +++++++ .../ruoyi/platform/service/ModelsService.java | 1 + .../service/impl/DatasetServiceImpl.java | 27 +++++++++-------- .../service/impl/ModelsServiceImpl.java | 30 +++++++++++++++++++ 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java index ef1a709f..a5fd5c53 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetController.java @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.util.Map; /** * (Dataset)表控制层 @@ -195,9 +196,11 @@ public class DatasetController { - @GetMapping("/exportDataset") + @PostMapping("/exportDataset") @ApiOperation(value = "导出数据集", notes = "将流水线产物导出到数据集。") - public AjaxResult exportDataset(@RequestParam("path") String path, @RequestParam("uuid") String uuid) throws Exception { + public AjaxResult exportDataset(@RequestBody Map map) throws Exception { + String path = (String) map.get("path"); + String uuid = (String) map.get("uuid"); return AjaxResult.success(datasetService.exportDataset(path, uuid)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java index 69188301..6d0d9f7b 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java @@ -2,6 +2,7 @@ package com.ruoyi.platform.controller.model; import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.platform.domain.Models; @@ -225,6 +226,15 @@ public class ModelsController extends BaseController { } + @GetMapping("/exportModel") + @ApiOperation(value = "导出模型", notes = "将流水线产物导出到模型。") + public AjaxResult exportModels(@RequestBody Map map) throws Exception { + String path = (String) map.get("path"); + String uuid = (String) map.get("uuid"); + return AjaxResult.success(this.modelsService.exportModels(path, uuid)); + } + + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ModelsService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ModelsService.java index 8f5bb88a..71f94cb1 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ModelsService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ModelsService.java @@ -81,4 +81,5 @@ public interface ModelsService { String readFileContent(Integer modelsId, String version) throws Exception; + List> exportModels(String path, String uuid) throws Exception; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java index 427a3def..b7f19eee 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java @@ -395,21 +395,24 @@ public class DatasetServiceImpl implements DatasetService { String srcBucketName = path.substring(0, path.indexOf("/")); //构建目标目录路径 String username = SecurityUtils.getLoginUser().getUsername(); - String targetDir = "datasets/" + username + "/" + uuid; + String srcDir = path.substring(path.indexOf("/") + 1); + String targetDir = "datasets/" + username + "/" + uuid + "/"; // 递归拷贝整个原目录到目标目录下 - minioUtil.copyDirectory(srcBucketName, path, bucketName, targetDir); + minioUtil.copyDirectory(srcBucketName, srcDir, bucketName, targetDir); List movedItems = minioUtil.getAllObjectsByPrefix(bucketName, targetDir, true); for (Item movedItem : movedItems) { - Map result = new HashMap<>(); - String url = movedItem.objectName(); - String fileName = extractFileName(url); - // 获取文件大小并转换为可读形式 - long sizeInBytes = movedItem.size(); - String formattedSize = FileUtil.formatFileSize(sizeInBytes); // 格式化文件大小 - result.put("fileName", fileName); - result.put("url", url); // objectName根据实际情况定义 - result.put("fileSize", formattedSize); - results.add(result); + if(!movedItem.isDir() && movedItem.size() > 0){ // 检查是否为非目录且文件大小大于0 + Map result = new HashMap<>(); + String url = movedItem.objectName(); + String fileName = extractFileName(url); + // 获取文件大小并转换为可读形式 + long sizeInBytes = movedItem.size(); + String formattedSize = FileUtil.formatFileSize(sizeInBytes); // 格式化文件大小 + result.put("fileName", fileName); + result.put("url", url); // objectName根据实际情况定义 + result.put("fileSize", formattedSize); + results.add(result); + } } return results; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index 52dea672..7461a1ff 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -14,6 +14,7 @@ import com.ruoyi.platform.utils.MinioUtil; import com.ruoyi.platform.vo.ModelsVo; import com.ruoyi.platform.vo.VersionVo; import com.ruoyi.system.api.model.LoginUser; +import io.minio.messages.Item; import io.netty.util.Version; import org.apache.commons.lang3.StringUtils; import org.springframework.core.io.InputStreamResource; @@ -409,6 +410,35 @@ public class ModelsServiceImpl implements ModelsService { } + @Override + public List> exportModels(String path, String uuid) throws Exception { + List> results = new ArrayList<>(); + //根据path得到源文件所在桶名 + String srcBucketName = path.substring(0, path.indexOf("/")); + //构建目标目录路径 + String username = SecurityUtils.getLoginUser().getUsername(); + String srcDir = path.substring(path.indexOf("/") + 1); + String targetDir = "models/" + username + "/" + uuid + "/"; + // 递归拷贝整个原目录到目标目录下 + minioUtil.copyDirectory(srcBucketName, srcDir, bucketName, targetDir); + List movedItems = minioUtil.getAllObjectsByPrefix(bucketName, targetDir, true); + for (Item movedItem : movedItems) { + if(!movedItem.isDir() && movedItem.size() > 0){ // 检查是否为非目录且文件大小大于0 + Map result = new HashMap<>(); + String url = movedItem.objectName(); + String fileName = extractFileName(url); + // 获取文件大小并转换为可读形式 + long sizeInBytes = movedItem.size(); + String formattedSize = FileUtil.formatFileSize(sizeInBytes); // 格式化文件大小 + result.put("fileName", fileName); + result.put("url", url); // objectName根据实际情况定义 + result.put("fileSize", formattedSize); + results.add(result); + } + } + return results; + } + private String extractFileName(String urlStr) { return urlStr.substring(urlStr.lastIndexOf('/') + 1); } From 13ec86755b7f5f2094b526f907b89f28f371bcef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Mon, 15 Apr 2024 16:31:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=B9post=E8=AF=B7?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/controller/model/ModelsController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java index 6d0d9f7b..97d0643f 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsController.java @@ -226,7 +226,7 @@ public class ModelsController extends BaseController { } - @GetMapping("/exportModel") + @PostMapping("/exportModel") @ApiOperation(value = "导出模型", notes = "将流水线产物导出到模型。") public AjaxResult exportModels(@RequestBody Map map) throws Exception { String path = (String) map.get("path");