From bc00242ee0410684eb9f4c5fe0aa486dfebb3162 Mon Sep 17 00:00:00 2001
From: lead <lead@local>
Date: 星期二, 03 十一月 2026 10:09:31 +0800
Subject: [PATCH] fix(api): 修复全量接口扫描发现的 500 —— 由 70 个降到 0 个

---
 yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
index ca7db64..19e4e15 100644
--- a/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
+++ b/yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
@@ -1,15 +1,18 @@
 package cn.iocoder.yudao.module.infra.controller.admin.file;
 
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.core.util.URLUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
 import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.*;
 import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
 import cn.iocoder.yudao.module.infra.service.file.FileService;
+import com.google.common.cache.CacheLoader;
+import com.google.common.util.concurrent.UncheckedExecutionException;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.Parameters;
@@ -27,7 +30,6 @@
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -111,19 +113,34 @@
         if (StrUtil.isEmpty(path)) {
             throw new IllegalArgumentException("缁撳熬鐨� path 璺緞蹇呴』浼犻��");
         }
-        // 瑙g爜锛岃В鍐充腑鏂囪矾寰勭殑闂
+        // 瑙g爜锛岃В鍐充腑鏂囥��%銆�+ 绛夌壒娈婂瓧绗﹁矾寰勭殑闂
         // https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
         // https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1432/
-        path = URLUtil.decode(path, StandardCharsets.UTF_8, false);
+        path = HttpUtils.decodeUrlPath(path);
 
         // 璇诲彇鍐呭
-        byte[] content = fileService.getFileContent(configId, path);
+        byte[] content;
+        try {
+            content = fileService.getFileContent(configId, path);
+        } catch (IllegalArgumentException | UncheckedExecutionException ex) {
+            // 鏂囦欢閰嶇疆涓嶅瓨鍦紙濡� configId 鏃犳晥锛夋椂锛屾寜璧勬簮涓嶅瓨鍦ㄨ繑鍥� 404锛岃�屼笉鏄� 500
+            log.warn("[getFileContent][configId({}) path({}) 鏂囦欢閰嶇疆涓嶅瓨鍦╙", configId, path);
+            response.setStatus(HttpStatus.NOT_FOUND.value());
+            return;
+        } catch (CacheLoader.InvalidCacheLoadException ex) {
+            // LoadingCache 鐨� load 杩斿洖 null 鏃舵姏鍑猴紙渚嬪鍘嗗彶鏂囦欢璁板綍鐨� configId 宸茶鍒犻櫎锛夛紝鍚屾牱鎸夎祫婧愪笉瀛樺湪澶勭悊
+            log.warn("[getFileContent][configId({}) path({}) 鏂囦欢閰嶇疆涓嶅瓨鍦╙", configId, path);
+            response.setStatus(HttpStatus.NOT_FOUND.value());
+            return;
+        }
         if (content == null) {
             log.warn("[getFileContent][configId({}) path({}) 鏂囦欢涓嶅瓨鍦╙", configId, path);
             response.setStatus(HttpStatus.NOT_FOUND.value());
             return;
         }
-        writeAttachment(response, path, content);
+        FileDO file = fileService.getFileByConfigIdAndPath(configId, path);
+        String filename = file != null && StrUtil.isNotEmpty(file.getName()) ? file.getName() : FileUtil.getName(path);
+        writeAttachment(response, filename, content);
     }
 
     @GetMapping("/page")

--
Gitblit v1.9.3