|
@@ -1,15 +1,18 @@
|
|
|
package com.persagy.dmp.file.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.persagy.dmp.common.constant.CommonConstant;
|
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
import com.persagy.dmp.common.context.AppContext;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.common.lang.PsDate;
|
|
|
import com.persagy.dmp.common.lang.PsDateTime;
|
|
|
+import com.persagy.dmp.common.utils.ResultHelper;
|
|
|
import com.persagy.dmp.file.constant.UploadCodeEnum;
|
|
|
import com.persagy.dmp.file.model.*;
|
|
|
import com.persagy.dmp.file.service.FileMd5Service;
|
|
@@ -20,9 +23,12 @@ import com.persagy.dmp.file.constant.FileCommonConst;
|
|
|
import com.persagy.dmp.file.service.FileStorageFactory;
|
|
|
import com.persagy.dmp.file.service.IFileStorageService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -305,6 +311,44 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileInfo> implement
|
|
|
uploadMes.setUploadCode(UploadCodeEnum.CODE_200.getCode());
|
|
|
return uploadMes;
|
|
|
}
|
|
|
+ /***
|
|
|
+ * Description: 根据文件id集合批量查询文件信息
|
|
|
+ * @param fileIds : 文件id集合
|
|
|
+ * @return : java.util.Map<java.lang.String,java.lang.String>
|
|
|
+ * @author : lijie
|
|
|
+ * Update By 2021/12/23 10:29
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public Map<String, String> queryFetchUrlsByFileIds(Set<String> fileIds) {
|
|
|
+ // 1.判断必填项
|
|
|
+ if(CollUtil.isEmpty(fileIds)) {
|
|
|
+ return new HashMap<>(0);
|
|
|
+ }
|
|
|
+ List<FileInfo> fileInfos = fileMapper.getFileInfoByIds(fileIds);
|
|
|
+ if (CollUtil.isEmpty(fileInfos)){
|
|
|
+ return new HashMap<>(0);
|
|
|
+ }
|
|
|
+ List<FileInfo> filterInfos = fileInfos.stream()
|
|
|
+ .filter(fileInfo -> FileCommonConst.UPLOAD_SUCCESS.equals(fileInfo.getUploadStatus())
|
|
|
+ && (StrUtil.isNotBlank(fileInfo.getFileBucket())
|
|
|
+ && StrUtil.isNotBlank(fileInfo.getFilePath())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollUtil.isEmpty(filterInfos)){
|
|
|
+ return new HashMap<>(0);
|
|
|
+ }
|
|
|
+ Map<String, String> map = new HashMap<>(filterInfos.size());
|
|
|
+ IFileStorageService service = FileStorageFactory.getService();
|
|
|
+ for (FileInfo filterInfo : filterInfos) {
|
|
|
+ String fetchUrl = service.fetchUrl(filterInfo.getFileBucket(),
|
|
|
+ filterInfo.getFilePath(), MapUtil
|
|
|
+ .of(FileCommonConst.RESPONSE_CONTENT_DISPOSITION,StrUtil
|
|
|
+ .format(FileCommonConst.REPONSE_HEAD_CONTENT_DISPOSITION_ATTACHMENT,
|
|
|
+ URLEncoder.encode(filterInfo.getFileName(), "UTF-8"))));
|
|
|
+ map.put(filterInfo.getId(),fetchUrl);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
/***
|
|
|
* Description: 初次上传和已有文件信息但未上传任何分片的情况下则直接生成所有上传url
|