|
@@ -45,7 +45,7 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> impl
|
|
|
|
|
|
// 获取当前日期时间
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- String timestamp = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
+// String timestamp = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
|
|
|
//文件类型
|
|
|
String type = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
|
|
@@ -55,13 +55,26 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> impl
|
|
|
// 获取每月递增值
|
|
|
int monthIncrement = getMonthIncrement(yearMonth);
|
|
|
// 新文件名格式:时间戳+每月递增值+文件类型
|
|
|
- String fileUuid = timestamp + "A" + String.format("%04d", monthIncrement) + "." + type;
|
|
|
+// String fileUuid = timestamp + "A" + String.format("%04d", monthIncrement) + "." + type;
|
|
|
|
|
|
// 将相对路径转化为绝对路径
|
|
|
String destPath = filesUploadPath + "/" + yearMonth;
|
|
|
|
|
|
// 新的文件地址,绝对路径+新的文件名称
|
|
|
- File uploadFile = new File(destPath + "/" + fileUuid);
|
|
|
+// File uploadFile = new File(destPath + "/" + fileUuid);
|
|
|
+ File uploadFile;
|
|
|
+ String fileUuid = originalFilename; // 初始使用原文件名
|
|
|
+ int count = 1; // 用于生成重复文件名的序号
|
|
|
+ while (true) {
|
|
|
+ uploadFile = new File(destPath + "/" + fileUuid);
|
|
|
+ if (!uploadFile.exists()) { // 如果文件不存在,直接使用该文件名
|
|
|
+ break;
|
|
|
+ } else { // 如果文件已存在,修改文件名
|
|
|
+ String nameWithoutType = originalFilename.substring(0, originalFilename.lastIndexOf("."));
|
|
|
+ fileUuid = nameWithoutType + "(" + count + ")." + type;
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 判断配置的文件目录是否存在,若不存在则创建一个新的文件目录
|
|
|
File parentFile = uploadFile.getParentFile();
|