From 20b8d870efbbb89564b599561fc69202ba41223f Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 10 四月 2026 13:36:42 +0800
Subject: [PATCH] 2026.4.10 1. 修复采样时间超过当前时间的数据依旧能存入数据库的bug

---
 src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt
index f290f76..cf997f7 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt
@@ -13,7 +13,7 @@
 class FileUtil {
 
     private var file: File
-    private var basePath:String = "${File.separator}ObdData${File.separator}"
+    private var basePath:String = "${File.separator}UAVData${File.separator}"
     private var closeThread: Thread? = null
     private var fw: FileWriter? = null
     private var bw: BufferedWriter? = null
@@ -36,7 +36,7 @@
         }
     }
 
-    fun saveObdData(str: String) {
+    fun saveObdData(str: String, newFile: Boolean = false) {
         //妫�鏌ユ枃妗f槸鍚﹀瓨鍦�
         if (!file.exists()) {
             file.parentFile.mkdirs()
@@ -45,7 +45,7 @@
             println("----鍒涘缓鏂囦欢锛�${file.absolutePath}")
         }
         //鏂囦欢鏈�澶�512Kb,瓒呰繃鍚庢柊寤烘枃妗�
-        if (file.length() + str.toByteArray().size > 512 * 1024 || TimeUtil.isNextDay(oldTime, Date())) {
+        if (newFile || file.length() + str.toByteArray().size > 512 * 1024 || TimeUtil.isNextDay(oldTime, Date())) {
             //瓒呰繃涓�澶╁悗锛屾洿鏂板綋鍓嶆椂闂�
             oldTime = Date()
 
@@ -59,18 +59,18 @@
                 flush()
                 close()
             }
-            fw?.run {
-                flush()
-                close()
-            }
+//            fw?.run {
+//                flush()
+//                close()
+//            }
             //鏂板缓杈撳嚭娴�
             fw = FileWriter(file, true)
-            bw = BufferedWriter(fw)
+            bw = fw?.let { BufferedWriter(it) }
         }
         //绗竴娆″啓鏂囨。鏃跺垵濮嬪寲杈撳嚭娴�
         if (bw == null || fw == null) {
             fw = FileWriter(file, true)
-            bw = BufferedWriter(fw)
+            bw = fw?.let { BufferedWriter(it) }
         }
 
         bw?.run {
@@ -79,8 +79,8 @@
             flush()
         }
 
-        readyToShutDownStream(bw, fw)
-        println("----鍐欏叆瀹屾垚")
+//        readyToShutDownStream(bw, fw)
+//        println("----鍐欏叆瀹屾垚")
 
     }
 

--
Gitblit v1.9.3