|
@@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -25,9 +26,11 @@ public class FileUtils {
|
|
|
@Autowired
|
|
|
ConfigConstant configConstant;
|
|
|
|
|
|
+ // 确保同一时间上传文件的唯一性
|
|
|
+ private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger();
|
|
|
+
|
|
|
public boolean checkFile(MultipartFile file) {
|
|
|
//设置允许上传文件类型
|
|
|
-// String suffixList = ".jpg,.gif,.png,.ico,.bmp,.jpeg,.zip,.zp,.rar,.mp3,.mp4,.avi,.mov,.4dage,.wav,.wma,.m4a";
|
|
|
String suffixList = configConstant.serverFileFallow;
|
|
|
// 获取文件后缀
|
|
|
if(file == null){
|
|
@@ -68,7 +71,7 @@ public class FileUtils {
|
|
|
newName = RegexUtil.getPinyinName(fileName);
|
|
|
} else {
|
|
|
String suffix = StringUtils.substringAfterLast(fileName, ".");
|
|
|
- newName = DateUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmssSSS") + "." + suffix;
|
|
|
+ newName = DateUtils.getDateTime() + ATOMIC_INTEGER.incrementAndGet() + "." + suffix;
|
|
|
}
|
|
|
|
|
|
savePath = configConstant.serverBasePath + savePath + "/" + newName;
|