fix(文件管理): 批量下载时文件名增加唯一标识

--bug=1039607 --user=宋天阳  https://www.tapd.cn/55049933/s/1500081
This commit is contained in:
Jianguo-Genius 2024-04-17 18:14:14 +08:00 committed by 刘瑞斌
parent fa0daf63d3
commit 17cde73898
2 changed files with 8 additions and 1 deletions

View File

@ -353,7 +353,7 @@ public class FileMetadataService {
public void batchDownloadWithResponse(List<FileMetadata> fileMetadataList, HttpServletResponse response) {
Map<String, File> fileMap = new HashMap<>();
fileMetadataList.forEach(fileMetadata -> fileMap.put(FileMetadataUtils.getFileName(fileMetadata), this.getTmpFile(fileMetadata)));
fileMetadataList.forEach(fileMetadata -> fileMap.put(FileMetadataUtils.getFileNameWithId(fileMetadata), this.getTmpFile(fileMetadata)));
FileDownloadUtils.zipFilesWithResponse(fileMap, response);
}

View File

@ -34,6 +34,13 @@ public class FileMetadataUtils {
return fileMetadata.getName() + "." + fileMetadata.getType();
}
public static String getFileNameWithId(FileMetadata fileMetadata) {
if (StringUtils.isBlank(fileMetadata.getType())) {
return fileMetadata.getName() + "_" + fileMetadata.getId();
}
return fileMetadata.getName() + "_" + fileMetadata.getId() + "." + fileMetadata.getType();
}
/**
* 将空文件类型转换为unknown
*