From bd8222d68314b6e53e813935199056b32ec8ec21 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Tue, 26 Mar 2024 23:18:15 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.1.3=E3=80=91=E3=80=90file=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E6=89=B9=E9=87=8F=E8=8E=B7?= =?UTF-8?q?=E5=8F=96url=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roses/kernel/file/api/FileInfoApi.java | 10 +++++++ .../service/impl/SysFileInfoServiceImpl.java | 27 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/FileInfoApi.java b/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/FileInfoApi.java index 838f31b26..83b602403 100644 --- a/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/FileInfoApi.java +++ b/kernel-d-file/file-api/src/main/java/cn/stylefeng/roses/kernel/file/api/FileInfoApi.java @@ -80,6 +80,16 @@ public interface FileInfoApi { */ String getFileUnAuthUrl(Long fileId); + /** + * 获取文件的下载地址(不带鉴权的),生成外网地址 + * + * @param fileIdList 文件id集合 + * @return 外部系统可以直接访问的url + * @author fengshuonan + * @since 2024/3/26 22:38 + */ + List batchGetFileUnAuthUrl(List fileIdList); + /** * 获取AntdV组件格式对应的文件信息封装 * diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java index 85e5c43a7..e38efc58b 100644 --- a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileInfoServiceImpl.java @@ -514,6 +514,33 @@ public class SysFileInfoServiceImpl extends ServiceImpl batchGetFileUnAuthUrl(List fileIdList) { + if (ObjectUtil.isEmpty(fileIdList)) { + return new ArrayList<>(); + } + LambdaQueryWrapper sysFileInfoLambdaQueryWrapper = new LambdaQueryWrapper<>(); + sysFileInfoLambdaQueryWrapper.in(SysFileInfo::getFileId, fileIdList); + sysFileInfoLambdaQueryWrapper.select(SysFileInfo::getFileId, SysFileInfo::getFileLocation, SysFileInfo::getFileBucket, SysFileInfo::getFileObjectName); + List list = this.list(sysFileInfoLambdaQueryWrapper); + if (ObjectUtil.isEmpty(list)) { + return new ArrayList<>(); + } + + ArrayList urlList = new ArrayList<>(); + for (SysFileInfo sysFileInfo : list) { + String url; + if (sysFileInfo.getFileLocation().equals(FileLocationEnum.DB.getCode())) { + url = this.sysFileStorageService.getFileUnAuthUrl(String.valueOf(sysFileInfo.getFileId())); + } else { + // 返回第三方存储文件url + url = fileOperatorApi.getFileUnAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName()); + } + urlList.add(url); + } + return urlList; + } + @Override public AntdvFileInfo buildAntdvFileInfo(Long fileId) { AntdvFileInfo antdvFileInfo = new AntdvFileInfo();