From f1ea263462d1f3f10a886fb083536a38b03a1ceb Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 14 五月 2025 17:33:04 +0800
Subject: [PATCH] 1. 新增动态污染溯源的数据异常判断逻辑 2. 新增动态污染溯源websocket连接功能

---
 src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt |   60 ++++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 44 insertions(+), 16 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 7df1965..6c5f374 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/processor/UnderwayProcessor.kt
@@ -1,11 +1,21 @@
 package com.flightfeather.uav.socket.processor
 
-import com.flightfeather.uav.repository.AirDataRepository
+import com.flightfeather.uav.biz.FactorFilter
+import com.flightfeather.uav.biz.sourcetrace.RealTimeExceptionAnalysisController
+import com.flightfeather.uav.common.location.LocationRoadNearby
+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.SceneInfoRep
+import com.flightfeather.uav.domain.repository.SegmentInfoRep
 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.stereotype.Component
@@ -20,24 +30,23 @@
  */
 
 @Component
-class UnderwayProcessor : BaseProcessor() {
+class UnderwayProcessor(
+    private val airDataRep: AirDataRep,
+    private val sceneInfoRep: SceneInfoRep,
+) : BaseProcessor() {
 
     companion object {
-        private lateinit var instance: UnderwayProcessor
-
         private const val TAG = "UAV"
     }
 
-    @Autowired
-    lateinit var airDataRepository: AirDataRepository
+    private val airDataDecoder = AirDataDecoder.instance
+    private val dataPackageDecoder = DataPackageDecoder()
 
-    val airDataDecoder = AirDataDecoder.instance
-    val dataPackageDecoder = DataPackageDecoder()
+    // 鏁版嵁棰勫鐞嗗嚱鏁�
+    private val dataProcessMap = mutableMapOf<String?, EPWDataPrep>()
 
-    @PostConstruct
-    fun init() {
-        instance = this
-    }
+    // 瀹炴椂璧拌埅姹℃煋婧簮澶勭悊鍣�
+    private val realTimeExceptionAnalysisMap = mutableMapOf<String?, RealTimeExceptionAnalysisController>()
 
     override var tag: String = "璧拌埅鐩戞祴"
 
@@ -49,7 +58,15 @@
             //淇濆瓨
             deviceSession.saveDevice(packageData.deviceCode, ctx)
             saveToTxt(msg)
-            saveToDataBase(packageData)
+            saveToDataBase(packageData)?.takeIf { it.isNotEmpty() }?.get(0)?.let {
+                // 姣忓彴璁惧鏈夊悇鑷崟鐙殑寮傚父鏁版嵁澶勭悊鍣�
+                if (!realTimeExceptionAnalysisMap.containsKey(it.deviceCode)) {
+                    realTimeExceptionAnalysisMap[it.deviceCode] = RealTimeExceptionAnalysisController(sceneInfoRep)
+                }
+                // 灏嗚蛋鑸暟鎹紶鍏ュ紓甯稿鐞嗗櫒
+                realTimeExceptionAnalysisMap[it.deviceCode]?.addOneData(it)
+            }
+
         } else {
             println("------${TAG}鏁版嵁BCC鏍¢獙澶辫触锛岃垗寮� [${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}]")
         }
@@ -58,12 +75,23 @@
     /**
      * 淇濆瓨鑷虫暟鎹簱
      */
-    fun saveToDataBase(dataPackage: AirDataPackage) {
+    fun saveToDataBase(dataPackage: AirDataPackage): List<BaseRealTimeData>? {
         when (dataPackage.commandUnit) {
             AirCommandUnit.AirData.value -> {
                 // 浠son鏍煎紡瀛樺偍鍘熷鏁版嵁
-                instance.airDataRepository.saveAirData(dataPackage)
+                airDataRep.saveAirData(dataPackage)
+                // 杩涜棰勫鐞嗗悗锛屽瓨鍌ㄨ嚦瀵瑰簲鏁版嵁琛�
+                if (!dataProcessMap.containsKey(dataPackage.deviceCode)) {
+                    // 姣忓彴璁惧鏈夊崟鐙殑鏁版嵁棰勫鐞嗗璞�
+                    dataProcessMap[dataPackage.deviceCode] = EPWDataPrep(UWDeviceType.getType(dataPackage.deviceCode))
+                }
+                return dataProcessMap[dataPackage.deviceCode]?.run {
+                    val list = this.mDataPrep2(dataPackage)// 鏁版嵁骞虫粦澶勭悊
+                    airDataRep.savePrepData2(list)// 鎸夌収璁惧绫诲瀷瀛樺偍鑷冲搴旀暟鎹〃
+                }
             }
+
+            else -> return emptyList()
         }
     }
 
@@ -95,7 +123,7 @@
     fun encodeToBytes(msg: String): ByteArray {
         val list = msg.split(" ")
         val bytes = ByteArray(list.size)
-        for (i in 0 until list.size) {
+        for (i in list.indices) {
             bytes[i] = list[i].toInt(16).toByte()
         }
 

--
Gitblit v1.9.3