From 6a26b1d539576a556d0f8682af7ae4317de78c7a Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期二, 02 四月 2024 13:35:35 +0800
Subject: [PATCH] 修复相机密码脱敏导致的bug

---
 ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java |   94 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java b/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java
index 674b0de..ff87625 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/tools/ArdTool.java
@@ -2,6 +2,7 @@
 
 import lombok.extern.slf4j.Slf4j;
 
+import java.io.*;
 import java.lang.reflect.Field;
 import java.text.DecimalFormat;
 import java.time.LocalTime;
@@ -20,7 +21,7 @@
     /**
      * @鎻忚堪 瀹炰綋瀵硅薄杞琈ap
      * @鍙傛暟 [entity]
-     * @杩斿洖鍊� java.util.Map<java.lang.String,java.lang.Object>
+     * @杩斿洖鍊� java.util.Map<java.lang.String, java.lang.Object>
      * @鍒涘缓浜� 鍒樿嫃涔�
      * @鍒涘缓鏃堕棿 2023/6/2 14:35
      * @淇敼浜哄拰鍏跺畠淇℃伅
@@ -39,6 +40,7 @@
         }
         return map;
     }
+
     /**
      * 姹侻ap<K,V>涓渶灏� Value 瀵瑰簲鐨凨ey鍊�
      *
@@ -46,13 +48,14 @@
      * @return
      */
     public static String getKeyByMinValue(Map<String, Double> map) {
-        if (map == null||map.size()==0) return null;
+        if (map == null || map.size() == 0) return null;
         List<Map.Entry<String, Double>> list = new ArrayList(map.entrySet());
         Collections.sort(list, (o1, o2) -> (o1.getValue().intValue() - o2.getValue().intValue()));
         String min = list.get(0).getKey();
 //        String max = list.get(list.size() - 1).getKey();
         return min;
     }
+
     /**
      * @鎻忚堪 閫氳繃鏃ュ鍒囨崲鏃堕棿鍒ゆ柇褰撳墠浣跨敤閫氶亾鍙�
      * @鍙傛暟 []
@@ -61,8 +64,7 @@
      * @鍒涘缓鏃堕棿 2023/6/17 13:50
      * @淇敼浜哄拰鍏跺畠淇℃伅
      */
-    public static Integer getChannelBydayNightTime(String dayNightTime)
-    {
+    public static Integer getChannelBydayNightTime(String dayNightTime) {
         try {
             // 鑾峰彇褰撳墠鏃堕棿
             LocalTime currentTime = LocalTime.now();
@@ -79,16 +81,16 @@
             } else {
                 return 2;
             }
-        }
-        catch (Exception ex)
-        {
-            log.error("鍏夌數鍒囨崲鑾峰彇閫氶亾寮傚父锛�"+ex.getMessage());
+        } catch (Exception ex) {
+            log.error("鍏夌數鍒囨崲鑾峰彇閫氶亾寮傚父锛�" + ex.getMessage());
             return 1;
         }
     }
+
     /**
      * 鏂囦欢澶у皬鏅鸿兘杞崲
      * 浼氬皢鏂囦欢澶у皬杞崲涓烘渶澶ф弧瓒冲崟浣�
+     *
      * @param size锛堟枃浠跺ぇ灏忥紝鍗曚綅涓築锛�
      * @return 鏂囦欢澶у皬
      */
@@ -105,11 +107,13 @@
         }
         return sizeName;
     }
+
     /**
      * 鏂囦欢澶у皬鏅鸿兘杞崲
      * 浼氬皢鏂囦欢澶у皬杞崲涓烘渶澶ф弧瓒冲崟浣�
+     *
      * @param size锛堟枃浠跺ぇ灏忥紝鍗曚綅涓築锛�
-     * @return	鏂囦欢澶у皬
+     * @return 鏂囦欢澶у皬
      */
     public static String readableFileSize(long size) {
         if (size <= 0) {
@@ -124,6 +128,7 @@
      * byte鏁扮粍杞瓧绗︿覆
      * 鍒樿嫃涔�
      * 2023/10/18 8:42:59
+     *
      * @param byteArray
      */
     public static String byteArrayToString(byte[] byteArray) {
@@ -133,4 +138,75 @@
         }
         return stringBuilder.toString();
     }
+
+    /**
+     * 灏嗘暟鎹啓鍏xt鏂囦欢
+     * 鍒樿嫃涔�
+     * 2024/3/8 12:58:39
+     */
+    public static void writeStringToFile(String data, String fileName) {
+
+        try {
+            File file = new File(fileName);
+            File parentDir = file.getParentFile();
+            if (!parentDir.exists()) {
+                parentDir.mkdirs(); // 鍒涘缓鏂囦欢鎵�鍦ㄧ殑鐩綍锛屽寘鎷埗鐩綍
+            }
+            boolean fileExists = file.exists();
+            boolean dataExists = false;
+            if(fileExists) {
+                // 璇诲彇鏂囦欢鍐呭
+                BufferedReader reader = new BufferedReader(new FileReader(fileName));
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    if (line.equals(data)) {
+                        dataExists = true;
+                        break;
+                    }
+                }
+                reader.close();
+            }
+
+            // 濡傛灉鏂囦欢涓嶅瓨鍦ㄦ垨鏁版嵁涓嶅瓨鍦紝鍒欒拷鍔犲埌鏂囦欢
+            if (!fileExists || !dataExists) {
+                FileWriter writer = new FileWriter(fileName, true);
+                writer.write(data + System.lineSeparator());
+                writer.close();
+                if (!fileExists) {
+                    log.debug("File created and data has been appended.");
+                } else {
+                    log.debug("Data has been appended to the file.");
+                }
+            } else {
+                log.debug("Data already exists in the file. Not appending.");
+            }
+        } catch (IOException e) {
+            log.error("An error occurred.");
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *  閫氳繃鍙嶅皠瀵硅薄濉厖
+     * 鍒樿嫃涔�
+     * 2024/4/2 11:50:57
+     */
+    public static void fillNullFields(Object source, Object target) {
+        if (source == null || target == null) {
+            return;
+        }
+        Field[] fields = source.getClass().getDeclaredFields();
+        for (Field field : fields) {
+            field.setAccessible(true);
+            try {
+                Object sourceValue = field.get(source);
+                Object targetValue = field.get(target);
+                if (targetValue == null && sourceValue != null) {
+                    field.set(target, sourceValue);
+                }
+            } catch (IllegalAccessException e) {
+                e.printStackTrace();
+            }
+        }
+    }
 }

--
Gitblit v1.9.3