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/socket/processor/UnderwayProcessor.kt |   67 ++++++++++++++++-----------------
 1 files changed, 33 insertions(+), 34 deletions(-)

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 a649598..48bee10 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
@@ -1,26 +1,24 @@
 package com.flightfeather.uav.socket.processor
 
-import com.flightfeather.uav.biz.FactorFilter
-import com.flightfeather.uav.biz.sourcetrace.RealTimeExceptionAnalysisController
-import com.flightfeather.uav.common.location.LocationRoadNearby
+import com.flightfeather.uav.biz.sourcetrace.SourceTraceController
 import com.flightfeather.uav.domain.entity.BaseRealTimeData
 import com.flightfeather.uav.model.epw.EPWDataPrep
 import com.flightfeather.uav.domain.repository.AirDataRep
-import com.flightfeather.uav.domain.repository.RealTimeDataRep
-import com.flightfeather.uav.domain.repository.SegmentInfoRep
+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.FactorType
 import com.flightfeather.uav.socket.eunm.UWDeviceType
-import com.flightfeather.uav.socket.handler.UnderwayWebSocketServerHandler
 import io.netty.channel.ChannelHandlerContext
-import org.springframework.beans.factory.annotation.Autowired
+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.*
-import javax.annotation.PostConstruct
 
 /**
  * 澶勭悊socket鎺ユ敹鐨勬秷鎭�
@@ -31,10 +29,8 @@
 @Component
 class UnderwayProcessor(
     private val airDataRep: AirDataRep,
-    private val realTimeDataRep: RealTimeDataRep,
-    private val locationRoadNearby: LocationRoadNearby,
-    private val segmentInfoRep: SegmentInfoRep,
-    private val underwayWebSocketServerHandler: UnderwayWebSocketServerHandler,
+    private val sceneInfoRep: SceneInfoRep,
+    private val sourceTraceRep: SourceTraceRep
 ) : BaseProcessor() {
 
     companion object {
@@ -48,23 +44,7 @@
     private val dataProcessMap = mutableMapOf<String?, EPWDataPrep>()
 
     // 瀹炴椂璧拌埅姹℃煋婧簮澶勭悊鍣�
-    private val realTimeExceptionAnalysisController =
-        RealTimeExceptionAnalysisController(
-            realTimeDataRep,
-            locationRoadNearby,
-            segmentInfoRep,
-            underwayWebSocketServerHandler,
-            FactorFilter.builder()
-//                .withMain(FactorType.NO2)
-                .withMain(FactorType.CO)
-//                .withMain(FactorType.H2S)
-//                .withMain(FactorType.SO2)
-//                .withMain(FactorType.O3)
-                .withMain(FactorType.PM25)
-                .withMain(FactorType.PM10)
-                .withMain(FactorType.VOC)
-                .create()
-        )
+    private val sourceTraceMap = mutableMapOf<String?, SourceTraceController>()
 
     override var tag: String = "璧拌埅鐩戞祴"
 
@@ -76,11 +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)
+                }
                 // 灏嗚蛋鑸暟鎹紶鍏ュ紓甯稿鐞嗗櫒
-                realTimeExceptionAnalysisController.addOneData(it)
+                sourceTraceMap[it.deviceCode]?.addOneData(it)
+                println("----鍔ㄦ�佹函婧愬畬鎴�")
             }
-
         } else {
             println("------${TAG}鏁版嵁BCC鏍¢獙澶辫触锛岃垗寮� [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]")
         }
@@ -92,6 +78,9 @@
     fun saveToDataBase(dataPackage: AirDataPackage): List<BaseRealTimeData>? {
         when (dataPackage.commandUnit) {
             AirCommandUnit.AirData.value -> {
+                val dataVo = dataPackage.toDataVo()
+                // 瀛樺偍鍓嶅垽鏂暟鎹槸鍚︽湁鏁�
+                if (!isValid(dataVo)) return null
                 // 浠son鏍煎紡瀛樺偍鍘熷鏁版嵁
                 airDataRep.saveAirData(dataPackage)
                 // 杩涜棰勫鐞嗗悗锛屽瓨鍌ㄨ嚦瀵瑰簲鏁版嵁琛�
@@ -100,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)// 鎸夌収璁惧绫诲瀷瀛樺偍鑷冲搴旀暟鎹〃
                 }
             }
@@ -165,4 +154,14 @@
 
         return sb.toString()
     }
+
+    /**
+     * 鏁版嵁鏈夋晥鎬у垽鏂�
+     */
+    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

--
Gitblit v1.9.3