From b2174bdc2c7906b0f6fa65be7a8564e64107581f Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期二, 25 三月 2025 14:18:18 +0800
Subject: [PATCH] Merge branch 'radio_frequency' of http://114.132.189.42:9002/r/lims-ruoyi-after into radio_frequency

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java |   57 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
index cb32f2f..6378290 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
@@ -1,9 +1,13 @@
 package com.ruoyi.web.controller.common;
 
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import com.ruoyi.common.utils.file.MinioUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,7 +19,7 @@
 import org.springframework.web.multipart.MultipartFile;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.constant.Constants;
-import com.ruoyi.common.core.domain.Result;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.file.FileUtils;
@@ -28,14 +32,16 @@
  */
 @RestController
 @RequestMapping("/common")
-public class CommonController
-{
+public class CommonController {
     private static final Logger log = LoggerFactory.getLogger(CommonController.class);
 
     @Autowired
     private ServerConfig serverConfig;
 
     private static final String FILE_DELIMETER = ",";
+
+    @Resource
+    private MinioUtils minioUtils;
 
     /**
      * 閫氱敤涓嬭浇璇锋眰
@@ -73,7 +79,7 @@
      * 閫氱敤涓婁紶璇锋眰锛堝崟涓級
      */
     @PostMapping("/upload")
-    public Result uploadFile(MultipartFile file) throws Exception
+    public AjaxResult uploadFile(MultipartFile file) throws Exception
     {
         try
         {
@@ -82,7 +88,7 @@
             // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О
             String fileName = FileUploadUtils.upload(filePath, file);
             String url = serverConfig.getUrl() + fileName;
-            Result ajax = Result.success();
+            AjaxResult ajax = AjaxResult.success();
             ajax.put("url", url);
             ajax.put("fileName", fileName);
             ajax.put("newFileName", FileUtils.getName(fileName));
@@ -91,7 +97,7 @@
         }
         catch (Exception e)
         {
-            return Result.error(e.getMessage());
+            return AjaxResult.error(e.getMessage());
         }
     }
 
@@ -99,7 +105,7 @@
      * 閫氱敤涓婁紶璇锋眰锛堝涓級
      */
     @PostMapping("/uploads")
-    public Result uploadFiles(List<MultipartFile> files) throws Exception
+    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
     {
         try
         {
@@ -119,7 +125,7 @@
                 newFileNames.add(FileUtils.getName(fileName));
                 originalFilenames.add(file.getOriginalFilename());
             }
-            Result ajax = Result.success();
+            AjaxResult ajax = AjaxResult.success();
             ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
             ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
             ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
@@ -128,7 +134,7 @@
         }
         catch (Exception e)
         {
-            return Result.error(e.getMessage());
+            return AjaxResult.error(e.getMessage());
         }
     }
 
@@ -160,4 +166,37 @@
             log.error("涓嬭浇鏂囦欢澶辫触", e);
         }
     }
+
+    /**
+     * 閫氱敤鏂囦欢涓嬭浇鏂规硶
+     *
+     * @param fileUrl  Minio涓殑鏂囦欢璺緞锛堝锛歩mages/2023/report.pdf锛�
+     * @param fileName 涓嬭浇鏃舵樉绀虹殑鏂囦欢鍚嶏紙濡傦細骞村害鎶ュ憡.pdf锛�
+     * @param response HttpServletResponse瀵硅薄
+     */
+    @GetMapping("/downloadMinio")
+    public void downloadFile(String fileUrl, String fileName, HttpServletResponse response) {
+        Logger logger = LoggerFactory.getLogger(this.getClass());
+        if (StringUtils.isBlank(fileUrl) || StringUtils.isBlank(fileName)) {
+            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+            try (PrintWriter writer = response.getWriter()) {
+                writer.write("鏂囦欢璺緞鍜屾枃浠跺悕涓嶈兘涓虹┖");
+            } catch (IOException e) {
+                logger.error("璁剧疆鍝嶅簲淇℃伅鍑洪敊", e);
+            }
+            return;
+        }
+        String bucketName = "radio-frequency";
+        try {
+            minioUtils.download(bucketName, fileUrl, fileName, response);
+        } catch (Exception e) {
+            logger.error("鏂囦欢涓嬭浇澶辫触", e);
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            try (PrintWriter writer = response.getWriter()) {
+                writer.write("鏂囦欢涓嬭浇澶辫触: " + e.getMessage());
+            } catch (IOException ioException) {
+                logger.error("璁剧疆鍝嶅簲淇℃伅鍑洪敊", ioException);
+            }
+        }
+    }
 }

--
Gitblit v1.9.3