Przeglądaj źródła

feat:
批量获取文件内容

18339543638 2 lat temu
rodzic
commit
8b998e0b0b

+ 41 - 0
tr-modules-api/tr-module-system-api/src/main/java/cn/tr/module/api/sys/storage/StoragePojo.java

@@ -0,0 +1,41 @@
+package cn.tr.module.api.sys.storage;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @ClassName : StoragePojo
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年07月19日
+ */
+@Data
+public class StoragePojo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 存储记录id
+     */
+    private String id;
+
+    /**
+     * 文件名称
+     */
+    private String realName;
+
+    /**
+     * 绝对路径
+     */
+    private String absolutePath;
+
+
+    /**
+     * 文件大小(KB)
+     */
+    private Integer size;
+
+    /**
+     * 文件后缀
+     */
+    private String suffix;
+}

+ 10 - 0
tr-modules-api/tr-module-system-api/src/main/java/cn/tr/module/api/sys/storage/SysStorageApi.java

@@ -1,5 +1,8 @@
 package cn.tr.module.api.sys.storage;
 
+import java.util.Collection;
+import java.util.Map;
+
 /**
  * @ClassName : SysStorageApi
  * @Description :
@@ -28,4 +31,11 @@ public interface SysStorageApi {
      * @return
      */
     byte[] obtainContent(String recordId) throws Exception;
+
+    /**
+     * 批量查询存储文件信息
+     * @param storageIds 存储文件id集合
+     * @return
+     */
+    Map<String,StoragePojo> findStorage(Collection<String> storageIds);
 }

+ 2 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/mapper/SysStorageRecordMapper.java

@@ -1,5 +1,6 @@
 package cn.tr.module.sys.storage.mapper;
 
+import cn.tr.module.api.sys.storage.StoragePojo;
 import cn.tr.module.sys.storage.po.SysStorageRecordPO;
 import cn.tr.module.sys.storage.dto.SysStorageRecordDTO;
 import org.mapstruct.Mapper;
@@ -25,4 +26,5 @@ public interface SysStorageRecordMapper {
 
     List<SysStorageRecordPO> convertPOList(List<SysStorageRecordDTO> source);
 
+    List<StoragePojo> convertPOJOList(List<SysStorageRecordDTO> source);
 }

+ 8 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/provider/SysStorageApiProvider.java

@@ -1,11 +1,14 @@
 package cn.tr.module.sys.storage.provider;
 
+import cn.tr.module.api.sys.storage.StoragePojo;
 import cn.tr.module.api.sys.storage.SysStorageApi;
 import cn.tr.module.sys.storage.service.IStorageFileService;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Component;
 
+import java.util.Collection;
 import java.util.Collections;
+import java.util.Map;
 
 /**
  * @ClassName : SysStorageApiProvider
@@ -31,4 +34,9 @@ public class SysStorageApiProvider implements SysStorageApi {
     public byte[] obtainContent(String recordId) throws Exception {
         return storageFileService.obtainContent(recordId);
     }
+
+    @Override
+    public Map<String, StoragePojo> findStorage(Collection<String> storageIds) {
+        return storageFileService.findStorageByIds(storageIds);
+    }
 }

+ 3 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/service/IStorageFileService.java

@@ -1,6 +1,7 @@
 package cn.tr.module.sys.storage.service;
 
 
+import cn.tr.module.api.sys.storage.StoragePojo;
 import cn.tr.module.sys.storage.dto.SysStorageRecordDTO;
 
 import java.util.*;
@@ -55,4 +56,6 @@ public interface IStorageFileService {
      * @return
      */
     String obtainPreviewPath(String recordId) throws Exception;
+
+    Map<String, StoragePojo> findStorageByIds(Collection<String> storageIds);
 }

+ 15 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/service/impl/StorageFileServiceImpl.java

@@ -1,14 +1,18 @@
 package cn.tr.module.sys.storage.service.impl;
 
 import cn.hutool.core.codec.Base64;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.URLUtil;
 import cn.tr.core.utils.JsonUtils;
+import cn.tr.module.api.sys.storage.StoragePojo;
 import cn.tr.module.sys.storage.dto.SysStorageConfigDTO;
 import cn.tr.module.sys.storage.dto.SysStorageRecordDTO;
+import cn.tr.module.sys.storage.mapper.SysStorageRecordMapper;
 import cn.tr.module.sys.storage.properties.TrStorageProperties;
 import cn.tr.module.sys.storage.service.IStorageFileService;
 import cn.tr.module.sys.storage.service.ISysStorageConfigService;
@@ -127,6 +131,17 @@ public class StorageFileServiceImpl implements IStorageFileService {
         return   storageProperties.getPreviewUrl()+URLUtil.encode(Base64.encode(obtainDownloadPath(recordId)));
     }
 
+    @Override
+    public Map<String, StoragePojo> findStorageByIds(Collection<String> storageIds) {
+        List<SysStorageRecordDTO> storageRecords= this.storageRecordService.selectSysStorageRecordByIds(storageIds);
+        if (CollectionUtil.isEmpty(storageRecords)) {
+            return MapUtil.empty();
+        }
+        return SysStorageRecordMapper.INSTANCE.convertPOJOList(storageRecords)
+                .stream()
+                .collect(Collectors.groupingBy(StoragePojo::getId,Collectors.collectingAndThen(Collectors.toList(),CollectionUtil::getFirst)));
+    }
+
 
     private FileClient getClient(SysStorageConfigDTO storageConfig){
         return fileClientFactory.createOrUpdateFileClient(storageConfig.getId(), storageConfig.getType(),parseClientConfig(storageConfig.getType(), storageConfig.getConfig()));