返回文件流接口兼容fileKey值为url情况处理

This commit is contained in:
tianliyong 2022-12-21 11:10:40 +08:00
parent 735fa2c24b
commit 84ff298710
3 changed files with 18 additions and 1 deletions

View File

@ -28,4 +28,6 @@ public interface FileDao extends IService<File> {
List<File> getByFileUuids(List<String> fileKey);
List<File> getByUrlMd5s(List<String> urlMd5List);
File getByUrlMd5(String urlMd5);
}

View File

@ -53,4 +53,13 @@ public class FileDaoImpl extends ServiceImpl<FileMapper, File> implements FileDa
.eq(File::getIsDelete, TableDelete.UN_DELETED)
.list();
}
@Override
public File getByUrlMd5(String urlMd5) {
return lambdaQuery().eq(File::getUrlMd5, urlMd5)
.eq(File::getStatus, FileStatus.SUCCESS)
.eq(File::getIsDelete, TableDelete.UN_DELETED)
.last("limit 1")
.one();
}
}

View File

@ -157,8 +157,14 @@ public class FileServiceImpl implements FileService {
@Override
public ServerFileDownloadResponse download(ServerFileDownloadDto dto) {
log.info("file download dto = {}", JsonUtil.obj2Str(dto));
File file = null;
String fileKey = dto.getFileKey();
File file = fileDao.getByFileUuid(fileKey);
if (fileKey.contains(IS_URL)) {
String urlMd5 = Utility.getMd5(fileKey);
file = fileDao.getByUrlMd5(urlMd5);
} else {
file = fileDao.getByFileUuid(fileKey);
}
if (Utility.objIsNull(file)) {
log.warn("file download is null, fileKey = {}", fileKey);
BizException.error(Utility.objIsNotNull(file), CodeEnum.FILE_NOT_FOUND);