From 9ed0b1847912221197697791d69e01ccae17f5b9 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 27 八月 2024 17:36:11 +0800
Subject: [PATCH] 1. 新增NO监测因子 2. 新增第三方数据接口数据获取相关模块

---
 src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt |   76 +++++++++++++++++++++++++++++--------
 1 files changed, 59 insertions(+), 17 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt
index 5080123..ae45e39 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/dataanalysis/ExceptionAnalysisController.kt
@@ -10,15 +10,21 @@
 import com.flightfeather.uav.common.location.LocationRoadNearby
 import com.flightfeather.uav.domain.entity.Mission
 import com.flightfeather.uav.domain.repository.RealTimeDataRep
+import com.flightfeather.uav.domain.repository.SegmentInfoRep
+import com.flightfeather.uav.socket.eunm.UWDeviceType
 import org.springframework.stereotype.Component
+import java.time.LocalDateTime
+import java.time.ZoneId
+import java.time.format.DateTimeFormatter
 
 /**
  * 鏁版嵁寮傚父鍒嗘瀽鎺у埗鍣�
  */
 @Component
-class ExceptionAnalysisController(
+class  ExceptionAnalysisController(
     private val realTimeDataRep: RealTimeDataRep,
     private val locationRoadNearby: LocationRoadNearby,
+    private val segmentInfoRep: SegmentInfoRep,
 ) {
 
     var running = false
@@ -42,29 +48,22 @@
         val result = mutableListOf<ExceptionResult>()
         taskList.forEach { it.init() }
         // 杞鏁版嵁锛岃绠楀悇涓紓甯�
-        realTimeDataRep.fetchData(mission.deviceCode, mission.startTime, mission.endTime).forEach { d ->
+        realTimeDataRep.fetchData(UWDeviceType.fromValue(mission.deviceType),
+            mission.deviceCode,
+            mission.startTime,
+            mission.endTime
+        ).forEach { d ->
             taskList.forEach { it.onNextData(d) }
         }
         // 鍚勪釜寮傚父鍒嗘瀽鍒嗗埆缁撴潫
         taskList.forEach { it.onDone() }
 
         taskList.forEach {
-            // 鏌ヨ寮傚父鍛ㄨ竟鍙兘姹℃煋婧�
             it.resultList.forEach { r->
-                if (r.longitude != null && r.latitude != null) {
-                    val sceneList = locationRoadNearby.searchByRadius(
-                        r.longitude!!.toDouble() to r.latitude!!.toDouble(), config.radius)
-                    if (sceneList.isNotEmpty()) {
-                        val idList = mutableListOf<String>()
-                        val nameList = mutableListOf<String>()
-                        sceneList.forEach { s->
-                            idList.add(s?.guid?:"")
-                            nameList.add(s?.name ?: "")
-                        }
-                        r.relatedSceneId = idList
-                        r.relatedSceneName = nameList
-                    }
-                }
+                // 鏌ヨ寮傚父鍛ㄨ竟鍙兘姹℃煋婧�
+                nearBy(r, config)
+                // 鏌ヨ鏃舵鎵�鍦ㄨ矾娈�
+                road(r)
             }
             // 瀛樺偍鍒嗘瀽缁撴灉
             result.addAll(it.resultList)
@@ -72,4 +71,47 @@
         running = false
         return result
     }
+
+    private fun nearBy(r: ExceptionResult, config: DataAnalysisConfig) {
+        if (r.longitude != null && r.latitude != null) {
+            val sceneList = locationRoadNearby.searchByRadius(
+                r.longitude!!.toDouble() to r.latitude!!.toDouble(), config.radius)
+            if (sceneList.isNotEmpty()) {
+                val idList = mutableListOf<String>()
+                val nameList = mutableListOf<String>()
+                sceneList.forEach { s->
+                    idList.add(s?.guid?:"")
+                    nameList.add(s?.name ?: "")
+                }
+                r.relatedSceneId = idList
+                r.relatedSceneName = nameList
+            }
+        }
+    }
+
+    private fun road(r: ExceptionResult) {
+        val sT = LocalDateTime.ofInstant(r.startDate?.toInstant(), ZoneId.systemDefault())
+        val eT = LocalDateTime.ofInstant(r.endDate?.toInstant(), ZoneId.systemDefault())
+        val segments = segmentInfoRep.findPeriod(sT, eT)
+        var txt = ""
+        val size = segments.size
+        segments.forEachIndexed { i, s ->
+            txt += if (i == 0) {
+                if (size == 1) {
+                    "鍦�${s?.street}"
+                } else {
+                    "浠�${s?.street}"
+                }
+            } else if (i == size - 1 && i >= 2) {
+                "锛岃嚦${s?.street}"
+            } else {
+                if (i == 1) {
+                    "锛岀粡${s?.street}"
+                } else {
+                    "銆�${s?.street}"
+                }
+            }
+        }
+        r.road = txt
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3