wuweihao 3 gadi atpakaļ
vecāks
revīzija
8bb8a00c2e

+ 3 - 1
README.md

@@ -1,3 +1,5 @@
 # museum_capital_tts
 
-首都博物馆-无障碍系统
+首都博物馆-无障碍系统
+
+需要在jdk/bin/jacob-1.20-x64.dll 加入这个文件

+ 9 - 4
gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -1,7 +1,7 @@
 package com.gis.common.util;
 
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.gis.common.config.ConfigConstant;
 import com.gis.common.exception.BaseRuntimeException;
 import lombok.extern.slf4j.Slf4j;
@@ -10,9 +10,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,6 +25,9 @@ public class FileUtils {
     @Autowired
     ConfigConstant configConstant;
 
+    // 确保同一时间上传文件的唯一性
+    private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger();
+
     public boolean checkFile(MultipartFile file) {
         //设置允许上传文件类型
         String suffixList = configConstant.serverFileFallow;
@@ -67,7 +70,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;
@@ -75,7 +78,6 @@ public class FileUtils {
 
         try {
             FileUtil.writeFromStream(file.getInputStream(), savePath);
-
             return newName;
         } catch (Exception e) {
             e.printStackTrace();
@@ -104,6 +106,9 @@ public class FileUtils {
      * @param path 参数是相对地址
      */
     public void del(String path){
+        if (StrUtil.isBlank(path)){
+            return;
+        }
         String delPath = configConstant.serverBasePath + path;
         FileUtil.del(delPath);
         log.info("真删除文件: {}", delPath);