|
@@ -15,6 +15,7 @@ import java.io.File;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -27,9 +28,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){
|
|
@@ -41,7 +44,6 @@ public class FileUtils {
|
|
|
String suffix = fileName.substring(fileName.lastIndexOf(".")
|
|
|
+ 1, fileName.length());
|
|
|
if (suffixList.contains(suffix.trim().toLowerCase())) {
|
|
|
-// log.info("无非法参数可以放行!!!");
|
|
|
return true;
|
|
|
}
|
|
|
log.error("存在非法参数不能放行!请核对上传文件格式,重新刷新页面再次上传!");
|
|
@@ -73,7 +75,6 @@ public class FileUtils {
|
|
|
HashMap<String, Object> result = new HashMap<>();
|
|
|
result.put("fileName", file.getOriginalFilename());
|
|
|
result.put("filePath", savePath + "/" + newName);
|
|
|
-// result.put("newName", newName);
|
|
|
return result;
|
|
|
|
|
|
}
|
|
@@ -148,7 +149,6 @@ public class FileUtils {
|
|
|
// 检查非法文件上传
|
|
|
boolean checkFile = this.checkFile(file);
|
|
|
if (!checkFile) {
|
|
|
-// throw new BaseRuntimeException(3009, "上传文件格式有误, 请重新上传");
|
|
|
throw new BaseRuntimeException("上传文件格式有误, 请重新上传");
|
|
|
}
|
|
|
|
|
@@ -160,7 +160,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;
|