From ac93c3a1bc1e759d4f40566fc2201ce7c480ee96 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 18 十月 2022 12:02:50 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/helper/PathHelper.java |   78 +++++++++++++++++++++++++++++++++++----
 1 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/lf/server/helper/PathHelper.java b/src/main/java/com/lf/server/helper/PathHelper.java
index fe2eaca..e0f964a 100644
--- a/src/main/java/com/lf/server/helper/PathHelper.java
+++ b/src/main/java/com/lf/server/helper/PathHelper.java
@@ -2,10 +2,13 @@
 
 import com.lf.server.config.PropertiesConfig;
 import com.lf.server.entity.all.SettingData;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.io.File;
+import java.util.Date;
 
 /**
  * 璺緞甯姪绫�
@@ -23,6 +26,10 @@
     private static int uploadPath = 1;
 
     private static int sharePath = 1;
+
+    private final static double D92 = 92;
+
+    private final static Log log = LogFactory.getLog(PathHelper.class);
 
     public PropertiesConfig getConfig() {
         return config;
@@ -75,8 +82,6 @@
 
     /**
      * 鑾峰彇瀵煎叆鐩綍
-     *
-     * @return
      */
     public String getImportFullPath() {
         importPath = getSubPath(config.getImportPath(), importPath);
@@ -86,8 +91,6 @@
 
     /**
      * 鑾峰彇鍑哄浘鐩綍
-     *
-     * @return
      */
     public String getExportFullPath() {
         exportPath = getSubPath(config.getExportPath(), exportPath);
@@ -97,8 +100,6 @@
 
     /**
      * 鑾峰彇涓婁紶鐩綍
-     *
-     * @return
      */
     public String getUploadFullPath() {
         uploadPath = getSubPath(config.getUploadPath(), uploadPath);
@@ -108,12 +109,73 @@
 
     /**
      * 鑾峰彇鍏变韩鐩綍
-     *
-     * @return
      */
     public String getShareFullPath() {
         sharePath = getSubPath(config.getSharePath(), sharePath);
 
         return config.getSharePath() + File.separator + sharePath;
     }
+
+    /**
+     * 鑾峰彇涓存椂璺緞
+     */
+    public String getTempPath() {
+        String tempName = FileHelper.getTempPath();
+        String tempPath = config.getTempPath();
+        String path = tempPath + File.separator + tempName;
+
+        File file = new File(path);
+        if (!file.exists() && !file.isDirectory()) {
+            file.mkdirs();
+        }
+
+        double ran = Math.random() * 99;
+        if (ran > D92) {
+            deleteOldPath(tempPath);
+        }
+
+        return path;
+    }
+
+    /**
+     * 鍒犻櫎鏃ц矾寰�
+     */
+    public void deleteOldPath(String tempPath) {
+        try {
+            File file = new File(tempPath);
+            String str = StringHelper.YMD__FORMAT.format(new Date());
+
+            File[] files = file.listFiles();
+            for (File f : files) {
+                if (f.getPath().indexOf(str) > -1) {
+                    continue;
+                }
+
+                deleteFiles(f);
+            }
+        } catch (Exception ex) {
+            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
+        }
+    }
+
+    /**
+     * 绾ц仈鍒犻櫎鏂囦欢
+     */
+    public void deleteFiles(File file) {
+        if (file == null || !file.exists()) {
+            return;
+        }
+
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            for (File f : files) {
+                if (f.isDirectory()) {
+                    deleteFiles(f);
+                } else {
+                    f.delete();
+                }
+            }
+        }
+        file.delete();
+    }
 }

--
Gitblit v1.9.3