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/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt  |    4 +-
 src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt                |   22 +++++++---
 src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcChangeRate.kt |    2 
 src/test/kotlin/com/flightfeather/uav/socket/UnderwayProcessorTest.kt                      |   19 ++++++++-
 src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt                             |    9 ++++
 src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt    |    2 
 src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt                             |    2 
 src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt                    |    6 --
 8 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcChangeRate.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcChangeRate.kt
index 81cb8a6..24a584d 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcChangeRate.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcChangeRate.kt
@@ -66,7 +66,7 @@
                 // 璁$畻鍚庝竴涓暟鎹浉姣斾簬鍓嶄竴涓暟鎹殑鍙樺寲閫熺巼
                 val v = (nValue - pValue)
                 val b1 = v in rate.mutationRate.first..rate.mutationRate.second
-                println("鍥犲瓙锛�${f.des}锛岄�熺巼锛�${v}锛�${b1}")
+//                println("鍥犲瓙锛�${f.des}锛岄�熺巼锛�${v}锛�${b1}")
                 res[f] = b1
             } else {
                 res[f] = false
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt
index 13b0f3d..898b806 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/exceptiontype/BaseRTExcWindLevel.kt
@@ -66,13 +66,13 @@
             val con = windLevelCondition
 
             if (n.windSpeed!! in con.windSpeed.first..con.windSpeed.second) {
-                println("椋庨�燂細${n.windSpeed}锛孾${con.windSpeed.first} - ${con.windSpeed.second}]")
+//                println("椋庨�燂細${n.windSpeed}锛孾${con.windSpeed.first} - ${con.windSpeed.second}]")
                 val pValue = p.getByFactorType(f)!!
                 val nValue = n.getByFactorType(f)!!
                 // 璁$畻鍚庝竴涓暟鎹浉姣斾簬鍓嶄竴涓暟鎹殑鍙樺寲鐜�
                 val r = (nValue - pValue) / pValue
                 val b1 = r >= con.mutationRate.first && r < con.mutationRate.second
-                println("鍥犲瓙锛�${f.des}锛屽箙搴︼細${r}锛岄檺瀹氾細${con.mutationRate.first}锛�${b1}")
+//                println("鍥犲瓙锛�${f.des}锛屽箙搴︼細${r}锛岄檺瀹氾細${con.mutationRate.first}锛�${b1}")
                 res[f] = b1
             } else {
                 res[f] = false
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 a474c2e..cf997f7 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/utils/FileUtil.kt
@@ -80,7 +80,7 @@
         }
 
 //        readyToShutDownStream(bw, fw)
-        println("----鍐欏叆瀹屾垚")
+//        println("----鍐欏叆瀹屾垚")
 
     }
 
diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
index 92cca2d..16c508f 100644
--- a/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
+++ b/src/main/kotlin/com/flightfeather/uav/model/epw/EPWDataPrep.kt
@@ -137,7 +137,14 @@
      */
     fun mDataPrep2(dataPackage: AirDataPackage): List<DataVo> {
         val vo = dataPackage.toDataVo()
-        return mDataPrep2(listOf(vo))
+        return mDataPrep2(vo)
+    }
+
+    /**
+     * 瀹炴椂鏁版嵁骞虫粦澶勭悊
+     */
+    fun mDataPrep2(dataVo: DataVo): List<DataVo> {
+        return mDataPrep2(listOf(dataVo))
     }
 
     /**
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
index 2961874..5b454b2 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
@@ -27,11 +27,7 @@
                 resultList.add(AirTypeData(f))
             }
         }
-        if (!types.containsKey(deviceCode)) {
-            types[deviceCode] = mutableListOf()
-        }
-        types[deviceCode]?.clear()
-        types[deviceCode]?.addAll(resultList)
+        types[deviceCode] = resultList
 
         return resultList
     }
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt b/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
index 0058d2b..48bee10 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
@@ -6,14 +6,18 @@
 import com.flightfeather.uav.domain.repository.AirDataRep
 import com.flightfeather.uav.domain.repository.SceneInfoRep
 import com.flightfeather.uav.domain.repository.SourceTraceRep
+import com.flightfeather.uav.lightshare.bean.DataVo
 import com.flightfeather.uav.socket.bean.AirDataPackage
 import com.flightfeather.uav.socket.decoder.AirDataDecoder
 import com.flightfeather.uav.socket.decoder.DataPackageDecoder
 import com.flightfeather.uav.socket.eunm.AirCommandUnit
 import com.flightfeather.uav.socket.eunm.UWDeviceType
 import io.netty.channel.ChannelHandlerContext
+import org.springframework.format.annotation.DateTimeFormat
 import org.springframework.stereotype.Component
 import java.text.SimpleDateFormat
+import java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
 import java.util.*
 
 /**
@@ -52,15 +56,17 @@
             //淇濆瓨
             deviceSession.saveDevice(packageData.deviceCode, ctx)
             saveToTxt(msg)
-            saveToDataBase(packageData)?.takeIf { it.isNotEmpty() }?.get(0)?.let {
+            val res = saveToDataBase(packageData)
+            println("----鍐欏叆瀹屾垚")
+            res?.takeIf { it.isNotEmpty() }?.get(0)?.let {
                 // 姣忓彴璁惧鏈夊悇鑷崟鐙殑寮傚父鏁版嵁澶勭悊鍣�
                 if (!sourceTraceMap.containsKey(it.deviceCode)) {
                     sourceTraceMap[it.deviceCode] = SourceTraceController(sceneInfoRep, sourceTraceRep)
                 }
                 // 灏嗚蛋鑸暟鎹紶鍏ュ紓甯稿鐞嗗櫒
                 sourceTraceMap[it.deviceCode]?.addOneData(it)
+                println("----鍔ㄦ�佹函婧愬畬鎴�")
             }
-
         } else {
             println("------${TAG}鏁版嵁BCC鏍¢獙澶辫触锛岃垗寮� [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]")
         }
@@ -72,8 +78,9 @@
     fun saveToDataBase(dataPackage: AirDataPackage): List<BaseRealTimeData>? {
         when (dataPackage.commandUnit) {
             AirCommandUnit.AirData.value -> {
+                val dataVo = dataPackage.toDataVo()
                 // 瀛樺偍鍓嶅垽鏂暟鎹槸鍚︽湁鏁�
-                if (!isValid(dataPackage)) return null
+                if (!isValid(dataVo)) return null
                 // 浠son鏍煎紡瀛樺偍鍘熷鏁版嵁
                 airDataRep.saveAirData(dataPackage)
                 // 杩涜棰勫鐞嗗悗锛屽瓨鍌ㄨ嚦瀵瑰簲鏁版嵁琛�
@@ -82,7 +89,7 @@
                     dataProcessMap[dataPackage.deviceCode] = EPWDataPrep(UWDeviceType.getType(dataPackage.deviceCode))
                 }
                 return dataProcessMap[dataPackage.deviceCode]?.run {
-                    val list = this.mDataPrep2(dataPackage)// 鏁版嵁骞虫粦澶勭悊
+                    val list = this.mDataPrep2(dataVo)// 鏁版嵁骞虫粦澶勭悊
                     airDataRep.savePrepData2(list)// 鎸夌収璁惧绫诲瀷瀛樺偍鑷冲搴旀暟鎹〃
                 }
             }
@@ -151,9 +158,10 @@
     /**
      * 鏁版嵁鏈夋晥鎬у垽鏂�
      */
-    private fun isValid(dataPackage: AirDataPackage): Boolean {
-        if (dataPackage.dataTime == null) return false
-        val check1 = dataPackage.dataTime!!.time < Date().time
+    private fun isValid(dataVo: DataVo): Boolean {
+        if (dataVo.time == null) return false
+        val check1 = LocalDateTime.parse(dataVo.time!!, DateTimeFormatter.ofPattern("yyy-MM-dd HH:mm:ss"))
+            .isBefore(LocalDateTime.now())
         return check1
     }
 }
\ No newline at end of file
diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt
index 0efb7d0..98d697a 100644
--- a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt
+++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/MissionServiceImplTest.kt
@@ -34,7 +34,7 @@
     @Test
     fun calMissionInfo() {
         missionMapper.selectByExample(Example(Mission::class.java).apply {
-            createCriteria().andBetween("startTime", "2026-01-29 00:00:00", "2026-12-31 23:59:59")
+            createCriteria().andBetween("startTime", "2026-02-02 00:00:00", "2026-12-31 23:59:59")
         }).forEach {mission ->
             mission?.let { missionService.calMissionInfo(it.missionCode) }
             Thread.sleep(1000)
diff --git a/src/test/kotlin/com/flightfeather/uav/socket/UnderwayProcessorTest.kt b/src/test/kotlin/com/flightfeather/uav/socket/UnderwayProcessorTest.kt
index 8c62914..b93118e 100644
--- a/src/test/kotlin/com/flightfeather/uav/socket/UnderwayProcessorTest.kt
+++ b/src/test/kotlin/com/flightfeather/uav/socket/UnderwayProcessorTest.kt
@@ -6,6 +6,9 @@
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
 import org.springframework.test.context.junit4.SpringRunner
+import java.io.File
+import java.nio.file.Files
+import java.nio.file.Paths
 
 /**
  * @author riku
@@ -20,7 +23,19 @@
 
     @Test
     fun bccCheck() {
-        val s = "23 23 2 31 37 36 39 31 35 33 31 39 30 39 31 32 30 30 30 36 1 1 0 42 13 9 f 12 34 8 2 0 8b 1c 0 d8 0 0 12 d8 9 6c 0 c8 0 b4 0 0 66 0 0 0 0 0 0 73 0 0 0 b9 4 32 0 2e d8 c4 0 0 0 0 80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 f6"
-        println(messageManager.bccCheck(s))
+        listOf(
+            "01 04 0a 00 00 00 00 01 12 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 00 0c",
+            "01 05 0a 00 00 00 00 01 52 00 05 af 00 cb f7 03 45 84 02 a1 65 00 71 92 01 ec 04 00 b7 9b 01 6e 0f 00 aa 9c 01 6b c4 00 0c 00 00 0d 00 00 1b 10 00 34 08 05 d3 1c 05 d4 7f 00 00 00 00 00 00 56 00 00 00 00 45 00 00 00 00 4e 00 00 00 50 01 06 08 0c 29 00 00 00 00 00 00 00 00 00 64"
+        ).forEach {
+            messageManager.dealStringMsg(it, null)
+        }
+//        println(messageManager.bccCheck(s))
+//        val lines = Files.readAllLines(Paths.get("C:\\Users\\feiyu\\Desktop\\data-2026-04-10-10-03-14.txt"))
+//        println("鏁版嵁閲忥細${lines.size - 1}")
+//        lines.forEach {
+//            val msg = it.split("data=> ")[1]
+//            messageManager.dealStringMsg(msg, null)
+//            Thread.sleep(4000)
+//        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3