feat(file):优化文件上传逻辑并解决中文乱码问题

- 引入 Hutool 工具类处理文件名唯一性和扩展名提取
- 使用 UUID 重命名文件,避免信创环境下的中文乱码问题- 调整租户、日期和用户路径结构以支持更细粒度的文件管理
- 统一代码格式,增强可读性与维护性
-修复潜在空指针异常风险点- 完善接口文档描述信息一致性
This commit is contained in:
2025-10-21 16:55:00 +08:00
parent 07b9e113ad
commit 636a1491bb

View File

@@ -1,7 +1,9 @@
package com.jeelowcode.service.infra.controller; package com.jeelowcode.service.infra.controller;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import com.jeelowcode.service.infra.controller.vo.file.*; import com.jeelowcode.service.infra.controller.vo.file.*;
@@ -9,6 +11,7 @@ import com.jeelowcode.service.infra.entity.FileDO;
import com.jeelowcode.service.infra.service.IFileService; import com.jeelowcode.service.infra.service.IFileService;
import com.jeelowcode.tool.framework.common.pojo.CommonResult; import com.jeelowcode.tool.framework.common.pojo.CommonResult;
import com.jeelowcode.tool.framework.common.pojo.PageResult; import com.jeelowcode.tool.framework.common.pojo.PageResult;
import com.jeelowcode.tool.framework.common.util.io.FileUtils;
import com.jeelowcode.tool.framework.common.util.object.BeanUtils; import com.jeelowcode.tool.framework.common.util.object.BeanUtils;
import com.jeelowcode.tool.framework.common.util.servlet.ServletUtils; import com.jeelowcode.tool.framework.common.util.servlet.ServletUtils;
import com.jeelowcode.tool.framework.operatelog.core.annotations.OperateLog; import com.jeelowcode.tool.framework.operatelog.core.annotations.OperateLog;
@@ -89,7 +92,8 @@ public class FileController {
String path = publicPath + fileName; String path = publicPath + fileName;
fileName = fileService.getUniqueFileName(fileName, path); fileName = fileService.getUniqueFileName(fileName, path);
path=publicPath+fileName; // 解决信创环境下文件名中文乱码导致附件错乱的问题
path = publicPath + IdUtil.simpleUUID() + (StrUtil.isEmpty(FileUtil.extName(fileName)) ? "" : ("." + FileUtil.extName(fileName)));
String fileUrl = fileService.createFile(fileName, path, IoUtil.readBytes(file.getInputStream())); String fileUrl = fileService.createFile(fileName, path, IoUtil.readBytes(file.getInputStream()));
@@ -99,7 +103,6 @@ public class FileController {
} }
@GetMapping("/presigned-url") @GetMapping("/presigned-url")
@Operation(tags = "文件管理", summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器") @Operation(tags = "文件管理", summary = "获取文件预签名地址", description = "模式二:前端上传文件:用于前端直接上传七牛、阿里云 OSS 等文件存储器")
public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(@RequestParam("path") String path) throws Exception { public CommonResult<FilePresignedUrlRespVO> getFilePresignedUrl(@RequestParam("path") String path) throws Exception {