|
@@ -3,7 +3,6 @@ package com.ruoyi.file.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.ruoyi.file.mapper.FileSequenceMapper;
|
|
|
import com.ruoyi.file.mapper.FilesMapper;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.system.model.LoginUser;
|
|
@@ -30,8 +29,6 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> impl
|
|
|
@Value("${file.prefix}")
|
|
|
private String filesPrefix;
|
|
|
|
|
|
- @Autowired
|
|
|
- private FileSequenceMapper fileSequenceMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -49,13 +46,14 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> impl
|
|
|
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
String timestamp = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
- int monthIncrement = getMonthIncrement(now.getYear(), now.getMonthValue());
|
|
|
|
|
|
|
|
|
String type = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
|
|
|
|
|
|
|
|
|
String yearMonth = now.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
|
|
+
|
|
|
+ int monthIncrement = getMonthIncrement(yearMonth);
|
|
|
|
|
|
String fileUuid = timestamp + "A" + String.format("%04d", monthIncrement) + "." + type;
|
|
|
|
|
@@ -103,22 +101,30 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, FilesUpload> impl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private int getMonthIncrement(int year, int month) {
|
|
|
-
|
|
|
- FileSequence increment = fileSequenceMapper.getByYearAndMonth(year, month);
|
|
|
- if (increment == null) {
|
|
|
-
|
|
|
- increment = new FileSequence();
|
|
|
- increment.setYear(year);
|
|
|
- increment.setMonth(month);
|
|
|
- increment.setValue(1);
|
|
|
- fileSequenceMapper.insert(increment);
|
|
|
- } else {
|
|
|
-
|
|
|
- increment.setValue(increment.getValue() + 1);
|
|
|
- fileSequenceMapper.updateById(increment);
|
|
|
+
|
|
|
+ * 获取每月递增值
|
|
|
+ * @param yearMonth 年月(格式:yyyyMM)
|
|
|
+ * @return 递增值
|
|
|
+ */
|
|
|
+ private int getMonthIncrement(String yearMonth) {
|
|
|
+
|
|
|
+ String destPath = filesUploadPath + "/" + yearMonth;
|
|
|
+ File folder = new File(destPath);
|
|
|
+
|
|
|
+
|
|
|
+ if (!folder.exists()) {
|
|
|
+ folder.mkdirs();
|
|
|
+ return 1;
|
|
|
}
|
|
|
- return increment.getValue();
|
|
|
+
|
|
|
+
|
|
|
+ File[] files = folder.listFiles();
|
|
|
+ if (files == null || files.length == 0) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return files.length + 1;
|
|
|
}
|
|
|
|
|
|
|