From 43bb8fc9f7fdcbc004e851cda0e97744d32f80f4 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Mon, 8 Sep 2025 15:52:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/NewModelFromGitController.java | 10 +- .../ruoyi/platform/service/ModelsService.java | 6 +- .../service/impl/ModelsServiceImpl.java | 100 ++++++++++++------ 3 files changed, 76 insertions(+), 40 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java index 8fbcc2c6..26ea8dd7 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/NewModelFromGitController.java @@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -72,14 +74,14 @@ public class NewModelFromGitController extends BaseController { @GetMapping("/downloadAllFiles") @ApiOperation(value = "下载同一版本下所有模型,并打包") - public ResponseEntity downloadAllDatasetFiles(@RequestParam("name") String name, @RequestParam("identifier") String identifier, @RequestParam("id") Integer id, @RequestParam("owner") String owner, @RequestParam("version") String version, @RequestParam("is_public") Boolean isPublic) throws Exception { - return modelsService.downloadAllModelFilesNew(name, identifier, id, owner, version, isPublic); + public void downloadAllDatasetFiles(HttpServletRequest req, HttpServletResponse resp, @RequestParam("name") String name, @RequestParam("identifier") String identifier, @RequestParam("id") Integer id, @RequestParam("owner") String owner, @RequestParam("version") String version, @RequestParam("is_public") Boolean isPublic) throws Exception { + modelsService.downloadAllModelFilesNew(req, resp, name, identifier, id, owner, version, isPublic); } @GetMapping("/downloadSingleFile") @ApiOperation(value = "下载单个模型文件", notes = "根据模型版本表id下载单个模型文件") - public ResponseEntity downloadDatasetlocal(@RequestParam("url") String url) throws Exception { - return modelsService.downloadDatasetlocal(url); + public AjaxResult downloadDatasetlocal(@RequestParam("url") String url) throws Exception { + return AjaxResult.success(modelsService.downloadDatasetlocal(url)); } @GetMapping("/queryModels") 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 da2d2edf..4a37396e 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 @@ -14,6 +14,8 @@ import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; import java.util.Map; @@ -72,7 +74,7 @@ public interface ModelsService { ResponseEntity downloadModels(Integer id) throws Exception; - ResponseEntity downloadDatasetlocal(String filePath) throws Exception; + String downloadDatasetlocal(String filePath) throws Exception; List> uploadModels(MultipartFile[] files, String uuid) throws Exception; @@ -98,7 +100,7 @@ public interface ModelsService { List> uploadModelLocal(MultipartFile[] files, String uuid) throws Exception; - ResponseEntity downloadAllModelFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws IOException, Exception; + void downloadAllModelFilesNew(HttpServletRequest req, HttpServletResponse resp, String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws IOException, Exception; Page newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest, String accessToken) throws Exception; 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 3d6003a8..7a3c3143 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 @@ -38,6 +38,8 @@ import org.springframework.web.multipart.MultipartFile; import redis.clients.jedis.Jedis; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Field; import java.net.URLEncoder; @@ -110,8 +112,12 @@ public class ModelsServiceImpl implements ModelsService { private RemoteInfoPublishService remoteInfoPublishService; // 固定存储桶名 + @Value("${minio.endpointIp}") + String endpointIp; @Value("${minio.dataReleaseBucketName}") private String bucketName; + @Value("${minio.platformDataBucketName}") + private String platformDataBucketName; @Resource private MinioUtil minioUtil; @@ -289,25 +295,27 @@ public class ModelsServiceImpl implements ModelsService { } @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)); } @@ -919,7 +927,7 @@ public class ModelsServiceImpl implements ModelsService { } @Override - public ResponseEntity downloadAllModelFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws Exception { + public void downloadAllModelFilesNew(HttpServletRequest req, HttpServletResponse resp, String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws Exception { // 命令行操作 git clone 项目地址 String localPath1 = localPath + owner + "/model/" + id + "/" + identifier + "/" + version; // 打包 data 文件夹 @@ -944,13 +952,32 @@ public class ModelsServiceImpl implements ModelsService { // 返回压缩文件的输入流 File zipFile = new File(zipFilePath); - InputStreamResource resource = new InputStreamResource(new FileInputStream(zipFile)); - return ResponseEntity.ok() - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + name + "_" + version + "_model.zip") - .contentType(MediaType.APPLICATION_OCTET_STREAM) - .contentLength(zipFile.length()) - .body(resource); + BufferedInputStream bis = null; + BufferedOutputStream bos = null; + OutputStream fos = null; + try { + bis = new BufferedInputStream(new FileInputStream(zipFile)); + fos = resp.getOutputStream(); + bos = new BufferedOutputStream(fos); + ServletUtils.setFileDownloadHeader(req, resp, name); + int byteRead = 0; + byte[] buffer = new byte[8192]; + while ((byteRead = bis.read(buffer, 0, 8192)) != -1) { + bos.write(buffer, 0, byteRead); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + bos.flush(); + bis.close(); + fos.close(); + bos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } } @Override @@ -979,7 +1006,8 @@ public class ModelsServiceImpl implements ModelsService { @Override - public Page newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest, String accessToken) throws Exception { + public Page newPubilcQueryByPage(ModelsVo modelsVo, PageRequest pageRequest, String accessToken) throws + Exception { String token; if (StringUtils.isNotEmpty(accessToken)) { token = accessToken; @@ -1007,7 +1035,8 @@ public class ModelsServiceImpl implements ModelsService { } @Override - public Page> queryVersions(PageRequest pageRequest, String identifier, String owner, String type) throws Exception { + public Page> queryVersions(PageRequest pageRequest, String identifier, String owner, String + type) throws Exception { String token = gitService.checkoutToken(); List> collect = gitService.getBrancheList(token, owner, identifier); List> result = collect.stream() @@ -1119,7 +1148,8 @@ public class ModelsServiceImpl implements ModelsService { } @Override - public ModelsVo getModelDetail(Integer id, String identifier, String owner, String version, Boolean isPublic) throws Exception { + public ModelsVo getModelDetail(Integer id, String identifier, String owner, String version, Boolean isPublic) throws + Exception { if (StringUtils.isEmpty(version)) { version = "origin"; } @@ -1220,7 +1250,8 @@ public class ModelsServiceImpl implements ModelsService { } @Override - public void deleteVersion(Integer repoId, String identifier, String owner, String version, String relativePath) throws Exception { + public void deleteVersion(Integer repoId, String identifier, String owner, String version, String relativePath) throws + Exception { List assetWorkflow = assetWorkflowDao.getAssetWorkflow(Long.valueOf(repoId), Constant.Asset_Type_Model, version); if (assetWorkflow != null && !assetWorkflow.isEmpty()) { String workflows = String.join(",", assetWorkflow.stream().map(AssetWorkflow::getWorkflowName).collect(Collectors.toSet())); @@ -1305,7 +1336,8 @@ public class ModelsServiceImpl implements ModelsService { } @Override - public List convert(List> lst, String modelTopic, String modelTagName, String modelTypeName) { + public List convert(List> lst, String modelTopic, String + modelTagName, String modelTypeName) { if (lst != null && lst.size() > 0) { List result = new ArrayList<>(); List newModelVos = ConvertUtil.convertListMapToObjectList(lst, ModelsVo.class); @@ -1364,7 +1396,7 @@ public class ModelsServiceImpl implements ModelsService { } @Override - public void privateToPublic(ModelsVo modelsVo) throws Exception { + public void privateToPublic(ModelsVo modelsVo) throws Exception { //获取版本列表信息,每一个版本的配置文件都要更改 String token = gitService.checkoutToken(); List> brancheList = gitService.getBrancheList(token, modelsVo.getOwner(), modelsVo.getIdentifier()); @@ -1390,7 +1422,7 @@ public class ModelsServiceImpl implements ModelsService { Map param = new HashMap<>(); param.put("id", projectDetail.get("project_id")); param.put("is_public", true); - gitService.updateProjectDetail(param,modelsVo.getOwner(),modelsVo.getIdentifier(),token); + gitService.updateProjectDetail(param, modelsVo.getOwner(), modelsVo.getIdentifier(), token); } @@ -1401,7 +1433,7 @@ public class ModelsServiceImpl implements ModelsService { //无需审批,直接通过 return "发布成功"; } - ModelsVo modelsVotDesc = getModelDetail(modelsVo.getId(), modelsVo.getIdentifier(),modelsVo.getOwner(),modelsVo.getVersion(), false); + ModelsVo modelsVotDesc = getModelDetail(modelsVo.getId(), modelsVo.getIdentifier(), modelsVo.getOwner(), modelsVo.getVersion(), false); String username = loginUser.getUsername(); Long userid = loginUser.getUserid(); ApprovalRequest approvalRequest = new ApprovalRequest();