|
@@ -1,6 +1,5 @@
|
|
|
package com.gis.common.util;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
@@ -10,9 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
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 +24,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){
|
|
@@ -70,7 +71,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;
|
|
|
|
|
|
}
|
|
@@ -87,7 +87,6 @@ public class FileUtils {
|
|
|
// 检查非法文件上传
|
|
|
boolean checkFile = this.checkFile(file);
|
|
|
if (!checkFile) {
|
|
|
-// throw new BaseRuntimeException(3009, "上传文件格式有误, 请重新上传");
|
|
|
throw new BaseRuntimeException("上传文件格式有误, 请重新上传");
|
|
|
}
|
|
|
|
|
@@ -99,7 +98,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;
|