From f0da95925bcb8ad19b0d1cc78afe4b4a4ae188a6 Mon Sep 17 00:00:00 2001
From: p-honggang.li <p-honggang.li@pcitc.com>
Date: 星期四, 28 八月 2025 09:55:51 +0800
Subject: [PATCH] Merge branch 'master' of http://xearth.cn:6600/r/web-manage/web-manage-back

---
 src/main/java/com/webmanage/controller/FileController.java |   82 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/webmanage/controller/FileController.java b/src/main/java/com/webmanage/controller/FileController.java
index c3d3292..429b28b 100644
--- a/src/main/java/com/webmanage/controller/FileController.java
+++ b/src/main/java/com/webmanage/controller/FileController.java
@@ -61,11 +61,11 @@
     }
 
     /**
-     * 涓嬭浇鏂囦欢
+     * 涓嬭浇鏂囦欢锛堣矾寰勫弬鏁版柟寮忥級
      */
     @GetMapping("/download/{fileName}")
-    @ApiOperation("涓嬭浇鏂囦欢")
-    public ResponseEntity<InputStreamResource> downloadFile(
+    @ApiOperation("涓嬭浇鏂囦欢锛堣矾寰勫弬鏁帮級")
+    public ResponseEntity<InputStreamResource> downloadFileByPath(
             @ApiParam("鏂囦欢鍚�") @PathVariable String fileName,
             @ApiParam("鍘熷鏂囦欢鍚�") @RequestParam(required = false) String originalName) {
         try {
@@ -95,11 +95,60 @@
     }
 
     /**
-     * 鑾峰彇鏂囦欢棰勮URL
+     * 涓嬭浇鏂囦欢锛堟煡璇㈠弬鏁版柟寮忥級
+     */
+    @GetMapping("/download")
+    @ApiOperation("涓嬭浇鏂囦欢锛堟煡璇㈠弬鏁帮級")
+    public ResponseEntity<InputStreamResource> downloadFile(
+            @ApiParam("鏂囦欢鍚�") @RequestParam String fileName,
+            @ApiParam("鍘熷鏂囦欢鍚�") @RequestParam(required = false) String originalName) {
+        try {
+            InputStream inputStream = minioService.downloadFile(fileName);
+            
+            // 濡傛灉娌℃湁鎻愪緵鍘熷鏂囦欢鍚嶏紝浠庤矾寰勪腑鎻愬彇
+            if (originalName == null || originalName.isEmpty()) {
+                String[] parts = fileName.split("/");
+                originalName = parts[parts.length - 1];
+            }
+            
+            // 璁剧疆鍝嶅簲澶�
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+            headers.setContentDispositionFormData("attachment", 
+                    URLEncoder.encode(originalName, StandardCharsets.UTF_8.toString()));
+            
+            InputStreamResource resource = new InputStreamResource(inputStream);
+            
+            return ResponseEntity.ok()
+                    .headers(headers)
+                    .body(resource);
+        } catch (Exception e) {
+            log.error("鏂囦欢涓嬭浇澶辫触: ", e);
+            return ResponseEntity.notFound().build();
+        }
+    }
+
+    /**
+     * 鑾峰彇鏂囦欢棰勮URL锛堣矾寰勫弬鏁版柟寮忥級
      */
     @GetMapping("/preview/{fileName}")
-    @ApiOperation("鑾峰彇鏂囦欢棰勮URL")
-    public Result<String> getPreviewUrl(@ApiParam("鏂囦欢鍚�") @PathVariable String fileName) {
+    @ApiOperation("鑾峰彇鏂囦欢棰勮URL锛堣矾寰勫弬鏁帮級")
+    public Result<String> getPreviewUrlByPath(@ApiParam("鏂囦欢鍚�") @PathVariable String fileName) {
+        try {
+            String previewUrl = minioService.getPreviewUrl(fileName);
+            return Result.success("鑾峰彇棰勮URL鎴愬姛", previewUrl);
+        } catch (Exception e) {
+            log.error("鑾峰彇棰勮URL澶辫触: ", e);
+            return Result.error("鑾峰彇棰勮URL澶辫触: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 鑾峰彇鏂囦欢棰勮URL锛堟煡璇㈠弬鏁版柟寮忥級
+     */
+    @GetMapping("/preview")
+    @ApiOperation("鑾峰彇鏂囦欢棰勮URL锛堟煡璇㈠弬鏁帮級")
+    public Result<String> getPreviewUrl(@ApiParam("鏂囦欢鍚�") @RequestParam String fileName) {
         try {
             String previewUrl = minioService.getPreviewUrl(fileName);
             return Result.success("鑾峰彇棰勮URL鎴愬姛", previewUrl);
@@ -125,11 +174,26 @@
     }
  
     /**
-     * 鍒犻櫎鏂囦欢
+     * 鍒犻櫎鏂囦欢锛堣矾寰勫弬鏁版柟寮忥級
      */
     @DeleteMapping("/delete/{fileName}")
-    @ApiOperation("鍒犻櫎鏂囦欢")
-    public Result<Boolean> deleteFile(@ApiParam("鏂囦欢鍚�") @PathVariable String fileName) {
+    @ApiOperation("鍒犻櫎鏂囦欢锛堣矾寰勫弬鏁帮級")
+    public Result<Boolean> deleteFileByPath(@ApiParam("鏂囦欢鍚�") @PathVariable String fileName) {
+        try {
+            minioService.deleteFile(fileName);
+            return Result.success("鏂囦欢鍒犻櫎鎴愬姛", true);
+        } catch (Exception e) {
+            log.error("鏂囦欢鍒犻櫎澶辫触: ", e);
+            return Result.error("鏂囦欢鍒犻櫎澶辫触: " + e.getMessage());
+        }
+    }
+
+    /**
+     * 鍒犻櫎鏂囦欢锛堟煡璇㈠弬鏁版柟寮忥級
+     */
+    @DeleteMapping("/delete")
+    @ApiOperation("鍒犻櫎鏂囦欢锛堟煡璇㈠弬鏁帮級")
+    public Result<Boolean> deleteFile(@ApiParam("鏂囦欢鍚�") @RequestParam String fileName) {
         try {
             minioService.deleteFile(fileName);
             return Result.success("鏂囦欢鍒犻櫎鎴愬姛", true);

--
Gitblit v1.8.0