| @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*; | |||||
| import org.springframework.web.multipart.MultipartFile; | import org.springframework.web.multipart.MultipartFile; | ||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * (Dataset)表控制层 | * (Dataset)表控制层 | ||||
| @@ -195,9 +196,11 @@ public class DatasetController { | |||||
| @GetMapping("/exportDataset") | |||||
| @PostMapping("/exportDataset") | |||||
| @ApiOperation(value = "导出数据集", notes = "将流水线产物导出到数据集。") | @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)); | return AjaxResult.success(datasetService.exportDataset(path, uuid)); | ||||
| } | } | ||||
| @@ -2,6 +2,7 @@ package com.ruoyi.platform.controller.model; | |||||
| import com.ruoyi.common.core.web.controller.BaseController; | 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.core.web.domain.GenericsAjaxResult; | ||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.domain.Models; | 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)); | |||||
| } | |||||
| } | } | ||||
| @@ -81,4 +81,5 @@ public interface ModelsService { | |||||
| String readFileContent(Integer modelsId, String version) throws Exception; | String readFileContent(Integer modelsId, String version) throws Exception; | ||||
| List<Map<String, String>> exportModels(String path, String uuid) throws Exception; | |||||
| } | } | ||||
| @@ -395,21 +395,24 @@ public class DatasetServiceImpl implements DatasetService { | |||||
| String srcBucketName = path.substring(0, path.indexOf("/")); | String srcBucketName = path.substring(0, path.indexOf("/")); | ||||
| //构建目标目录路径 | //构建目标目录路径 | ||||
| String username = SecurityUtils.getLoginUser().getUsername(); | 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<Item> movedItems = minioUtil.getAllObjectsByPrefix(bucketName, targetDir, true); | List<Item> movedItems = minioUtil.getAllObjectsByPrefix(bucketName, targetDir, true); | ||||
| for (Item movedItem : movedItems) { | for (Item movedItem : movedItems) { | ||||
| Map<String, String> 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<String, String> 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; | return results; | ||||
| } | } | ||||
| @@ -14,6 +14,7 @@ import com.ruoyi.platform.utils.MinioUtil; | |||||
| import com.ruoyi.platform.vo.ModelsVo; | import com.ruoyi.platform.vo.ModelsVo; | ||||
| import com.ruoyi.platform.vo.VersionVo; | import com.ruoyi.platform.vo.VersionVo; | ||||
| import com.ruoyi.system.api.model.LoginUser; | import com.ruoyi.system.api.model.LoginUser; | ||||
| import io.minio.messages.Item; | |||||
| import io.netty.util.Version; | import io.netty.util.Version; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.core.io.InputStreamResource; | import org.springframework.core.io.InputStreamResource; | ||||
| @@ -409,6 +410,35 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| } | } | ||||
| @Override | |||||
| public List<Map<String, String>> exportModels(String path, String uuid) throws Exception { | |||||
| List<Map<String, String>> 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<Item> movedItems = minioUtil.getAllObjectsByPrefix(bucketName, targetDir, true); | |||||
| for (Item movedItem : movedItems) { | |||||
| if(!movedItem.isDir() && movedItem.size() > 0){ // 检查是否为非目录且文件大小大于0 | |||||
| Map<String, String> 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) { | private String extractFileName(String urlStr) { | ||||
| return urlStr.substring(urlStr.lastIndexOf('/') + 1); | return urlStr.substring(urlStr.lastIndexOf('/') + 1); | ||||
| } | } | ||||