From b6b0cb226fcf184525ee7b36af3a09471e9c0057 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 25 三月 2024 11:29:33 +0800
Subject: [PATCH] 修改数据统计的查询条件

---
 src/main/java/com/lf/server/helper/FileHelper.java |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 102 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/lf/server/helper/FileHelper.java b/src/main/java/com/lf/server/helper/FileHelper.java
index 80ce585..c9a5294 100644
--- a/src/main/java/com/lf/server/helper/FileHelper.java
+++ b/src/main/java/com/lf/server/helper/FileHelper.java
@@ -7,9 +7,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.*;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.StandardCharsets;
@@ -26,9 +24,6 @@
 
     /**
      * 鑾峰彇鏂囦欢鍚�
-     *
-     * @param file
-     * @return
      */
     public static String getFileName(String file) {
         int idx = file.lastIndexOf(File.separator);
@@ -37,6 +32,19 @@
         }
 
         return "";
+    }
+
+    /**
+     * 鑾峰彇鏂囦欢鍚嶇О
+     */
+    public static String getName(String file) {
+        String fileName = getFileName(file);
+        int idx = fileName.lastIndexOf(".");
+        if (idx > -1) {
+            return fileName.substring(0, idx);
+        }
+
+        return fileName;
     }
 
     /**
@@ -49,7 +57,7 @@
 
         String fileName = file.getName().toLowerCase();
 
-        int idx = fileName.lastIndexOf(StaticData.POINT);
+        int idx = fileName.indexOf(StaticData.POINT);
         if (idx == -1) {
             return "";
         }
@@ -75,9 +83,6 @@
 
     /**
      * 鑾峰彇澶氱敤閫斾簰鑱旂綉閭欢鎵╁睍绫诲瀷
-     *
-     * @param ext 鏂囦欢鎵╁睍鍚�
-     * @return
      */
     public static String getMime(String ext) {
         switch (ext) {
@@ -185,6 +190,37 @@
     }
 
     /**
+     * 鑾峰彇鏂囦欢澶у皬
+     */
+    public static String getSizes(double mbNumber) {
+        if (mbNumber < StaticData.D1024) {
+            return new DecimalFormat("#.##MB").format(mbNumber);
+        }
+
+        double gbNumber = mbNumber / StaticData.D1024;
+        if (gbNumber < StaticData.D1024) {
+            return new DecimalFormat("#.##GB").format(gbNumber);
+        }
+
+        double tbNumber = gbNumber / StaticData.D1024;
+
+        return new DecimalFormat("#.##TB").format(tbNumber);
+    }
+
+    /**
+     * 鑾峰彇骞虫柟绫�
+     */
+    public static String getSquareMeter(double num) {
+        if (num < StaticData.I1000000) {
+            return new DecimalFormat("#.##骞虫柟绫�").format(num);
+        }
+
+        double knum = num / StaticData.I1000000;
+
+        return new DecimalFormat("#.##骞虫柟鍗冪背").format(knum);
+    }
+
+    /**
      * byte杞琈B
      */
     public static double sizeToMb(long size) {
@@ -253,17 +289,19 @@
      * @param file 鏂囦欢
      */
     public static void deleteFiles(File file) {
-        if (file == null || !file.exists()) {
+        if (null == file || !file.exists()) {
             return;
         }
 
         if (file.isDirectory()) {
             File[] files = file.listFiles();
-            for (File f : files) {
-                if (f.isDirectory()) {
-                    deleteFiles(f);
-                } else {
-                    f.delete();
+            if (null != files && files.length > 0) {
+                for (File f : files) {
+                    if (f.isDirectory()) {
+                        deleteFiles(f);
+                    } else {
+                        f.delete();
+                    }
                 }
             }
         }
@@ -379,4 +417,52 @@
 
         return builder.toString();
     }
+
+    /**
+     * 鏍规嵁璺緞鑾峰彇鏂囦欢
+     */
+    public static void getFilesByPath(List<String> list, String path) {
+        File file = new File(path);
+        if (file.isDirectory()) {
+            File[] files = file.listFiles();
+            if (null == files) {
+                return;
+            }
+
+            for (File f : files) {
+                if (f.isDirectory()) {
+                    getFilesByPath(list, f.getPath());
+                } else {
+                    list.add(f.getPath());
+                }
+            }
+        } else {
+            list.add(file.getPath());
+        }
+    }
+
+    /**
+     * 澶嶅埗鏂囦欢
+     *
+     * @param src  婧愭枃浠�
+     * @param dest 鐩綍鏂囦欢
+     */
+    public static void copyFile(File src, File dest) throws IOException {
+        InputStream is = null;
+        OutputStream os = null;
+        try {
+            is = new FileInputStream(src);
+            os = new FileOutputStream(dest);
+
+            byte[] buffer = new byte[1024];
+
+            int length;
+            while ((length = is.read(buffer)) > 0) {
+                os.write(buffer, 0, length);
+            }
+        } finally {
+            os.close();
+            is.close();
+        }
+    }
 }

--
Gitblit v1.9.3