|
@@ -17,7 +17,10 @@ import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import static com.zjugis.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -76,6 +79,7 @@ public class FileServiceImpl implements FileService {
|
|
|
if (StrUtil.isEmpty(name)) {
|
|
|
name = path;
|
|
|
}
|
|
|
+ path = generateUniqueFileName(path);
|
|
|
|
|
|
// 上传到文件存储器
|
|
|
FileClient client = clientId == null? fileConfigService.getMasterFileClient():fileConfigService.getFileClient(clientId);
|
|
@@ -94,6 +98,18 @@ public class FileServiceImpl implements FileService {
|
|
|
return file;
|
|
|
}
|
|
|
|
|
|
+ private static String generateUniqueFileName(String path) {
|
|
|
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
|
|
|
+ int dotIndex = path.lastIndexOf('.');
|
|
|
+ if (dotIndex != -1) {
|
|
|
+ String name = path.substring(0, dotIndex);
|
|
|
+ String extension = path.substring(dotIndex);
|
|
|
+ return name + "_" + timeStamp + extension;
|
|
|
+ } else {
|
|
|
+ return path + "_" + timeStamp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void deleteFile(Long id) throws Exception {
|
|
|
// 校验存在
|