From 67cbd8b0fac84231f4bf6dff6a84ad3d40b96d37 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Mon, 8 Sep 2025 14:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/NewDatasetFromGitController.java | 4 +- .../platform/service/NewDatasetService.java | 2 +- .../service/impl/NewDatasetServiceImpl.java | 53 ++++++++++--------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java index f2ffcc66..da1444f1 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java @@ -192,8 +192,8 @@ public class NewDatasetFromGitController { @GetMapping("/downloadSingleFile") @ApiOperation(value = "下载单个数据集文件", notes = "根据数据集版本表id下载单个数据集文件") - public ResponseEntity downloadDataset(@RequestParam("url") String url) throws Exception { - return newDatasetService.downloadDatasetlocal(url); + public AjaxResult downloadDataset(@RequestParam("url") String url) throws Exception { + return AjaxResult.success(newDatasetService.downloadDatasetlocal(url)); } @PostMapping("/getVersionsCompare") diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java index 61e166cc..d6dff3e6 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java @@ -27,7 +27,7 @@ public interface NewDatasetService { List> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception; - ResponseEntity downloadDatasetlocal(String filePath) throws Exception; + String downloadDatasetlocal(String filePath) throws Exception; ResponseEntity downloadAllDatasetFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws IOException, Exception; diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 2c214d81..66088eb1 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -81,6 +81,12 @@ public class NewDatasetServiceImpl implements NewDatasetService { String secretAccessKey; @Value("${minio.endpoint}") String endpoint; + @Value("${minio.endpointIp}") + String endpointIp; + @Value("${minio.dataReleaseBucketName}") + private String bucketName; + @Value("${minio.platformDataBucketName}") + private String platformDataBucketName; @Value("${git.endpoint}") String gitendpoint; @Value("${git.cloneEndpoint}") @@ -89,9 +95,6 @@ public class NewDatasetServiceImpl implements NewDatasetService { String gitCloneEndpointIp; @Value("${git.projectDatasetId}") Integer projectDatasetId; - - @Value("${minio.dataReleaseBucketName}") - private String bucketName; @Value("${git.localPath}") String localPathlocal; @@ -597,25 +600,27 @@ public class NewDatasetServiceImpl implements NewDatasetService { } @Override - public ResponseEntity downloadDatasetlocal(String filePath) throws Exception { - File file = new File(filePath); - - if (!file.exists()) { - throw new FileNotFoundException("File not found: " + filePath); - } - - InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); - - HttpHeaders headers = new HttpHeaders(); - headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName()); - headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length())); - headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); - - return ResponseEntity.ok() - .headers(headers) - .contentLength(file.length()) - .contentType(MediaType.APPLICATION_OCTET_STREAM) - .body(resource); + public String downloadDatasetlocal(String filePath) throws Exception { +// File file = new File(filePath); +// +// if (!file.exists()) { +// throw new FileNotFoundException("File not found: " + filePath); +// } +// +// InputStreamResource resource = new InputStreamResource(new FileInputStream(file)); +// +// HttpHeaders headers = new HttpHeaders(); +// headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName()); +// headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length())); +// headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); +// +// return ResponseEntity.ok() +// .headers(headers) +// .contentLength(file.length()) +// .contentType(MediaType.APPLICATION_OCTET_STREAM) +// .body(resource); + String[] split = filePath.split("/"); + return endpointIp + "/" + bucketName + "/" + platformDataBucketName + "/" + String.join("/", Arrays.copyOfRange(split, 3, split.length)); } @Override @@ -756,7 +761,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { } @Override - public void privateToPublic(NewDatasetVo newDatasetVo) throws Exception { + public void privateToPublic(NewDatasetVo newDatasetVo) throws Exception { //获取版本列表信息,每一个版本的配置文件都要更改 String token = gitService.checkoutToken(); List> brancheList = gitService.getBrancheList(token, newDatasetVo.getOwner(), newDatasetVo.getIdentifier()); @@ -781,7 +786,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { Map param = new HashMap<>(); param.put("id", projectDetail.get("project_id")); param.put("is_public", true); - gitService.updateProjectDetail(param,newDatasetVo.getOwner(),newDatasetVo.getIdentifier(),token); + gitService.updateProjectDetail(param, newDatasetVo.getOwner(), newDatasetVo.getIdentifier(), token); } /**