From 8eb584869b4fd4de0f51c93f2616f12e51df9193 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 18 十二月 2025 17:48:29 +0800
Subject: [PATCH] 2025.12.18 1. 动态溯源相关分析逻辑调整; 2. 走航报告接口参数调整;

---
 src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt |  211 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 192 insertions(+), 19 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
index 2dc6b58..a6e9311 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSource.kt
@@ -1,9 +1,16 @@
 package com.flightfeather.uav.biz.sourcetrace.model
 
-import com.flightfeather.uav.biz.FactorFilter
+import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType
+import com.flightfeather.uav.common.utils.DateUtil
 import com.flightfeather.uav.common.utils.MapUtil
+import com.flightfeather.uav.domain.entity.BaseRealTimeData
 import com.flightfeather.uav.domain.entity.SceneInfo
 import com.flightfeather.uav.domain.repository.SceneInfoRep
+import com.flightfeather.uav.lightshare.bean.AreaVo
+import com.flightfeather.uav.lightshare.bean.SceneInfoVo
+import com.flightfeather.uav.lightshare.eunm.SceneType
+import com.flightfeather.uav.socket.eunm.FactorType
+import org.springframework.beans.BeanUtils
 import org.springframework.web.context.ContextLoader
 
 /**
@@ -20,38 +27,204 @@
      */
 
     // 婧簮浼佷笟
-    var sceneList:List<SceneInfo?>? = null
+    var sceneList: List<SceneInfoVo>? = null
 
-    fun searchScenes(pollutedArea: PollutedArea, factor: FactorFilter.SelectedFactor) {
+    // 婧簮鎺ㄧ悊缁撹
+    var conclusion: String? = null
+
+    fun searchScenes(pollutedArea: PollutedArea, pollutedData: PollutedData) {
         ContextLoader.getCurrentWebApplicationContext()?.getBean(SceneInfoRep::class.java)?.run {
-            searchScenes(pollutedArea, this, factor)
+            searchScenes(pollutedArea, this, pollutedData)
         }
     }
 
     /**
      * 鏌ユ壘绯荤粺鍐呴儴婧簮鑼冨洿鍐呯殑姹℃煋浼佷笟
      */
-    fun searchScenes(pollutedArea: PollutedArea, sceneInfoRep: SceneInfoRep, factor: FactorFilter.SelectedFactor) {
+    fun searchScenes(pollutedArea: PollutedArea, sceneInfoRep: SceneInfoRep, pollutedData: PollutedData) {
         // Fixme 2025.5.14: 姹℃煋婧愮殑鍧愭爣鏄珮寰峰湴鍥惧潗鏍囩郴锛堢伀鏄熷潗鏍囩郴锛夛紝鑰岃蛋鑸暟鎹槸WGS84鍧愭爣绯�
         // 鎸夌収鍖哄煙妫�绱㈠唴閮ㄦ薄鏌撴簮淇℃伅
-        // 1. 棣栧厛鎸夌収鍥涜嚦鑼冨洿浠庢暟鎹簱鍒濇绛涢�夋薄鏌撴簮锛岄渶瑕佸厛灏嗗潗鏍囪浆鎹负gcj02锛堢伀鏄熷潗鏍囩郴锛夛紝鍥犱负姹℃煋婧愬満鏅俊鎭兘涓烘鍧愭爣绯�
-        val polygonTmp = pollutedArea.polygon!!.map {
-            MapUtil.gcj02ToWgs84(it)
-        }
-        val fb = MapUtil.calFourBoundaries(polygonTmp)
-        val sceneList = sceneInfoRep.findByCoordinateRange(fb)
-        // 2. 鍐嶇簿纭垽鏂槸鍚﹀湪鍙嶅悜婧簮鍖哄煙澶氳竟褰㈠唴閮�
-        val result = mutableListOf<SceneInfo>()
-        sceneList.forEach {
-            val point = it!!.longitude.toDouble() to it.latitude.toDouble()
-            if (MapUtil.isPointInPolygon(point, polygonTmp)) {
-                result.add(it)
+        var result = mutableListOf<SceneInfo>()
+        val polygonTmp = pollutedArea.polygon
+        this.sceneList = emptyList()
+
+        if (polygonTmp != null) {
+            val fb = MapUtil.calFourBoundaries(polygonTmp)
+            // 1. 棣栧厛鎸夌収鍥涜嚦鑼冨洿浠庢暟鎹簱鍒濇绛涢�夋薄鏌撴簮锛屾澶勭殑鍖哄煙鍧愭爣宸茶浆鎹负鐏槦鍧愭爣绯�
+            val sceneList = sceneInfoRep.findByCoordinateRange(fb)
+            // 2. 鍐嶇簿纭垽鏂槸鍚﹀湪鍙嶅悜婧簮鍖哄煙澶氳竟褰㈠唴閮�
+            sceneList.forEach {
+                val point = it!!.longitude.toDouble() to it.latitude.toDouble()
+                if (MapUtil.isPointInPolygon(point, polygonTmp)) {
+                    result.add(it)
+                }
             }
+
+            // 3. 鍐嶇粺涓�妫�绱㈣繎璺濈姹℃煋鍦嗗舰鍖哄煙鍐呴儴鐨勬薄鏌撴簮
+            val closePolygonTmp = pollutedArea.closePolygon!!
+            val closeFb = MapUtil.calFourBoundaries(closePolygonTmp)
+            val closeSceneList = sceneInfoRep.findByCoordinateRange(closeFb)
+            closeSceneList.forEach {
+                val point = it!!.longitude.toDouble() to it.latitude.toDouble()
+                if (MapUtil.isPointInPolygon(point, closePolygonTmp)) {
+                    result.add(it)
+                }
+            }
+            // 4. 鍘婚噸
+            result = result.distinctBy { it.guid }.toMutableList()
+
+            // 5. 鏍规嵁姹℃煋鍥犲瓙鐨勯噺绾э紝璁$畻涓昏鐨勬薄鏌撳満鏅被鍨嬶紝绛涢�夌粨鏋�
+            val mainSceneType = calSceneType(pollutedData)
+            result = result.filter {
+                val r = mainSceneType.find { s ->
+                    s.value == it.typeId.toInt()
+                }
+                r != null
+            }.toMutableList()
+            this.sceneList = findClosestStation(sceneInfoRep, result)
         }
 
-        this.sceneList = result
+        val txt = summaryTxt(pollutedData, this.sceneList!!)
+        this.conclusion = txt
+    }
 
-        TODO("鎸夌収鎵�閫夌洃娴嬪洜瀛愮被鍨嬶紝鍖哄垎姹℃煋婧愮被鍨�")
+    /**
+     * 璁$畻鍙兘鐨勭浉鍏虫薄鏌撳満鏅被鍨嬩互鍙婃帹鐞嗙粨璁�
+     */
+    @Throws(Exception::class)
+    private fun calSceneType(pollutedData: PollutedData): List<SceneType> {
+        val sceneTypes = mutableListOf<SceneType>()
+        pollutedData.statisticMap.entries.forEach { s ->
+            val res = when (s.key) {
+                // 姘哀鍖栧悎鐗╋紝涓�鑸敱浜庢満鍔ㄨ溅灏炬皵锛屽悓姝ヨ绠桟O
+                FactorType.NO,
+                FactorType.NO2,
+                    -> {
+                    listOf(SceneType.TYPE1, SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
+                }
 
+                FactorType.CO -> listOf(SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
+                FactorType.H2S -> null
+                FactorType.SO2 -> null
+                FactorType.O3 -> null
+                FactorType.PM25,
+                FactorType.PM10,
+                    -> {
+                    listOf(
+                        SceneType.TYPE1,
+                        SceneType.TYPE2,
+                        SceneType.TYPE3,
+                        SceneType.TYPE14,
+                        SceneType.TYPE5,
+                        SceneType.TYPE18
+                    )
+                }
+
+                FactorType.VOC -> {
+                    listOf(SceneType.TYPE5, SceneType.TYPE6, SceneType.TYPE17, SceneType.TYPE12, SceneType.TYPE18)
+                }
+
+                else -> null
+            }
+            res?.let { sceneTypes.addAll(it) }
+        }
+        return sceneTypes.distinct()
+    }
+
+    /**
+     * 璁$畻鏈�杩戠殑鐩戞祴绔欑偣
+     */
+    private fun findClosestStation(sceneInfoRep: SceneInfoRep, sceneList: List<SceneInfo>): List<SceneInfoVo> {
+        val res1 = sceneInfoRep.findByArea(AreaVo().apply {
+            sceneTypeId = SceneType.TYPE19.value.toString()
+        })
+
+        val res2 = sceneInfoRep.findByArea(AreaVo().apply {
+            sceneTypeId = SceneType.TYPE20.value.toString()
+        })
+        val res = res1.toMutableList().apply { addAll(res2) }
+
+        return sceneList.map {
+            var minLen = -1.0
+            var selectedRes: SceneInfo? = null
+            res.forEach { r ->
+                val dis = MapUtil.getDistance(
+                    it.longitude.toDouble(),
+                    it.latitude.toDouble(),
+                    r!!.longitude.toDouble(),
+                    r.latitude.toDouble()
+                )
+                if (minLen < 0 || dis < minLen) {
+                    minLen = dis
+                    selectedRes = r
+                }
+            }
+            val vo = SceneInfoVo()
+            BeanUtils.copyProperties(it, vo)
+            vo.closestStation = selectedRes
+            vo.length = minLen
+
+            return@map vo
+        }
+    }
+
+    /**
+     * 婧簮瑙f瀽
+     * @param pollutedData 姹℃煋鏁版嵁
+     * @param sceneList 椋庨櫓婧愬垪琛�
+     * @return 婧簮鎻忚堪
+     */
+    private fun summaryTxt(pollutedData: PollutedData, sceneList: List<SceneInfoVo>): String {
+        val st = DateUtil.instance.getTime(pollutedData.startTime)
+        val et = DateUtil.instance.getTime(pollutedData.endTime)
+
+        // 1. 鎻忚堪寮傚父鍙戠敓鐨勬椂闂村拰寮傚父绫诲瀷
+        var txt = "鍦�${st}鑷�${et}涔嬮棿锛屽嚭鐜�${pollutedData.exception}${pollutedData.times}娆�"
+
+        // 2. 鎻忚堪寮傚父鏁版嵁鐨勫彉鍖栨儏鍐�
+        val statArr = mutableListOf<String>()
+        pollutedData.statisticMap.entries.forEach { s ->
+            val txtArr = mutableListOf<String>()
+            s.value.excGroup?.forEach exception@{ p ->
+                val preValue = p.getFirstDataValue()
+                val curValue = p.getLastDataValue()
+                val per = p.per?.times(100)
+                val rate = p.rate
+                if (preValue == null || curValue == null || per == null) return@exception
+                when (pollutedData.exceptionType) {
+                    // 閲忕骇绐佸彉
+                    ExceptionType.TYPE4.value -> {
+                        txtArr.add("浠�${preValue}渭g/m鲁绐佸彉鑷�${curValue}渭g/m鲁锛屽彉鍖栫巼涓�${per}%")
+                    }
+                    // 蹇�熶笂鍗�
+                    ExceptionType.TYPE9.value -> {
+                        txtArr.add("浠�${preValue}渭g/m鲁蹇�熶笂鍗囪嚦${curValue}渭g/m鲁锛屽彉鍖栭�熺巼涓�${rate}渭g/m鲁/绉掞紝鍙樺寲鐜囦负${per}%")
+                    }
+                }
+            }
+            statArr.add("${s.key.getTxt()}閲忕骇${txtArr.joinToString("锛�")}")
+        }
+        txt += "锛�${statArr.joinToString("锛�")}"
+
+        // 3. 鎻忚堪鍙戠幇鐨勯闄╂簮鎯呭喌
+        if (sceneList.isEmpty()) {
+            txt += ("锛屽彲鑳藉瓨鍦ㄩ殣钘忛闄╂簮銆�")
+        } else {
+            txt += ("锛屽彂鐜�${sceneList.size}涓闄╂簮锛屽寘鍚�")
+
+            val sizeMap = mutableMapOf<String, Int>()
+            sceneList.forEach {
+                if (!sizeMap.containsKey(it.type)) {
+                    sizeMap[it.type] = 0
+                }
+                sizeMap[it.type] = sizeMap[it.type]!! + 1
+            }
+            sizeMap.forEach { (t, u) ->
+                txt += ("${u}涓�${t}锛�")
+            }
+            txt = txt.replaceRange(txt.length - 1, txt.length, "銆�")
+        }
+
+        return txt
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3