From 5fd8f535ef44ef055d91673740491b9c9177aa89 Mon Sep 17 00:00:00 2001 From: seatonwan9 Date: 星期日, 24 八月 2025 20:32:01 +0800 Subject: [PATCH] 交易管理 --- 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