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 |  169 ++++++++++++++-----------------------------------------
 1 files changed, 44 insertions(+), 125 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 706622c..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
@@ -12,7 +12,6 @@
 import com.flightfeather.uav.socket.eunm.FactorType
 import org.springframework.beans.BeanUtils
 import org.springframework.web.context.ContextLoader
-import kotlin.math.round
 
 /**
  * 姹℃煋鏉ユ簮
@@ -46,12 +45,12 @@
         // Fixme 2025.5.14: 姹℃煋婧愮殑鍧愭爣鏄珮寰峰湴鍥惧潗鏍囩郴锛堢伀鏄熷潗鏍囩郴锛夛紝鑰岃蛋鑸暟鎹槸WGS84鍧愭爣绯�
         // 鎸夌収鍖哄煙妫�绱㈠唴閮ㄦ薄鏌撴簮淇℃伅
         var result = mutableListOf<SceneInfo>()
-        // 1. 棣栧厛鎸夌収鍥涜嚦鑼冨洿浠庢暟鎹簱鍒濇绛涢�夋薄鏌撴簮锛屾澶勭殑鍖哄煙鍧愭爣宸茶浆鎹负鐏槦鍧愭爣绯�
         val polygonTmp = pollutedArea.polygon
         this.sceneList = emptyList()
 
         if (polygonTmp != null) {
             val fb = MapUtil.calFourBoundaries(polygonTmp)
+            // 1. 棣栧厛鎸夌収鍥涜嚦鑼冨洿浠庢暟鎹簱鍒濇绛涢�夋薄鏌撴簮锛屾澶勭殑鍖哄煙鍧愭爣宸茶浆鎹负鐏槦鍧愭爣绯�
             val sceneList = sceneInfoRep.findByCoordinateRange(fb)
             // 2. 鍐嶇簿纭垽鏂槸鍚﹀湪鍙嶅悜婧簮鍖哄煙澶氳竟褰㈠唴閮�
             sceneList.forEach {
@@ -61,6 +60,7 @@
                 }
             }
 
+            // 3. 鍐嶇粺涓�妫�绱㈣繎璺濈姹℃煋鍦嗗舰鍖哄煙鍐呴儴鐨勬薄鏌撴簮
             val closePolygonTmp = pollutedArea.closePolygon!!
             val closeFb = MapUtil.calFourBoundaries(closePolygonTmp)
             val closeSceneList = sceneInfoRep.findByCoordinateRange(closeFb)
@@ -70,20 +70,17 @@
                     result.add(it)
                 }
             }
-            // 鍘婚噸
+            // 4. 鍘婚噸
             result = result.distinctBy { it.guid }.toMutableList()
 
-            // 鏍规嵁姹℃煋鍥犲瓙鐨勯噺绾э紝璁$畻涓昏鐨勬薄鏌撳満鏅被鍨嬶紝绛涢�夌粨鏋�
+            // 5. 鏍规嵁姹℃煋鍥犲瓙鐨勯噺绾э紝璁$畻涓昏鐨勬薄鏌撳満鏅被鍨嬶紝绛涢�夌粨鏋�
             val mainSceneType = calSceneType(pollutedData)
-            if (mainSceneType != null) {
-//            this.conclusion = mainSceneType.first
-                result = result.filter {
-                    val r = mainSceneType.second.find { s ->
-                        s.value == it.typeId.toInt()
-                    }
-                    r != null
-                }.toMutableList()
-            }
+            result = result.filter {
+                val r = mainSceneType.find { s ->
+                    s.value == it.typeId.toInt()
+                }
+                r != null
+            }.toMutableList()
             this.sceneList = findClosestStation(sceneInfoRep, result)
         }
 
@@ -95,8 +92,7 @@
      * 璁$畻鍙兘鐨勭浉鍏虫薄鏌撳満鏅被鍨嬩互鍙婃帹鐞嗙粨璁�
      */
     @Throws(Exception::class)
-    private fun calSceneType(pollutedData: PollutedData): Pair<String, List<SceneType>>? {
-        var des: String? = null
+    private fun calSceneType(pollutedData: PollutedData): List<SceneType> {
         val sceneTypes = mutableListOf<SceneType>()
         pollutedData.statisticMap.entries.forEach { s ->
             val res = when (s.key) {
@@ -104,85 +100,35 @@
                 FactorType.NO,
                 FactorType.NO2,
                     -> {
-//                    val coAvg = round(pollutedData.dataList.map { it.co!! }.average()) / 1000
-                    val coAvg = round(pollutedData.statisticMap[FactorType.CO]?.avg ?: .0) / 1000
-                    "姘哀鍖栧悎鐗╁亸楂橈紝CO鐨勯噺绾т负${coAvg}mg/m鲁锛屼竴鑸敱浜庢満鍔ㄨ溅灏炬皵閫犳垚锛屾薄鏌撴簮浠ユ苯淇�佸姞娌圭珯涓轰富" to
-                            listOf(SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
+                    listOf(SceneType.TYPE1, SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
                 }
 
-                FactorType.CO -> "" to listOf(SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
-
+                FactorType.CO -> listOf(SceneType.TYPE6, SceneType.TYPE10, SceneType.TYPE17)
                 FactorType.H2S -> null
-
                 FactorType.SO2 -> null
-
                 FactorType.O3 -> null
-                // a) pm2.5銆乸m10鐗瑰埆楂橈紝涓よ�呭湪鍚勬儏鍐典笅鍚屾灞曠ず锛宲m2.5鍗爌m10鐨勬瘮閲嶅彉鍖栵紝姣旈噸瓒婇珮锛岃秺鏈夊彲鑳芥槸椁愰ギ
-                // b) pm10鐗瑰埆楂樸�乸m2.5杈冮珮锛屽ぇ棰楃矑鎵皹姹℃煋锛屽彧灞曠ずpm10锛宲m2.5鍗爌m10鐨勬瘮閲嶅彉鍖栵紝宸ュ湴涓轰富
                 FactorType.PM25,
                 FactorType.PM10,
                     -> {
-//                    val pm25Avg = round(pollutedData.dataList.map { it.pm25!! }.average() * 10) / 10
-//                    val pm10Avg = round(pollutedData.dataList.map { it.pm10!! }.average() * 10) / 10
-                    val pm25Avg = round((pollutedData.statisticMap[FactorType.PM25]?.avg ?: .0) * 10) / 10
-                    val pm10Avg = round((pollutedData.statisticMap[FactorType.PM10]?.avg ?: .0) * 10) / 10
-                    // 璁$畻寮傚父鏁版嵁鐨刾m2.5鍗爌m10姣旈噸鐨勫潎鍊�
-                    val percentageAvg = pollutedData.dataList.map {
-                        it.pm25!! / it.pm10!!
-                    }.average()
-                    val str =
-                        "PM2.5閲忕骇涓�${pm25Avg}渭g/m鲁锛孭M10閲忕骇涓�${pm10Avg}渭g/m鲁锛孭M2.5鍗燩M10鐨勬瘮閲嶄负${round(percentageAvg * 100)}%"
-                    if (percentageAvg > 0.666) {
-                        "${str}锛屾瘮閲嶈緝澶э紝姹℃煋婧愪互椁愰ギ涓轰富锛屽伐鍦版涔�" to
-                                listOf(
-                                    SceneType.TYPE1,
-                                    SceneType.TYPE2,
-                                    SceneType.TYPE3,
-                                    SceneType.TYPE14,
-                                    SceneType.TYPE5,
-                                    SceneType.TYPE18
-                                )
-                    } else if (percentageAvg < 0.333) {
-                        "${str}锛屾瘮閲嶈緝灏忥紝灞炰簬澶ч绮掓壃灏樻薄鏌擄紝姹℃煋婧愪互宸ュ湴涓轰富" to
-                                listOf(
-                                    SceneType.TYPE1,
-                                    SceneType.TYPE2,
-                                    SceneType.TYPE3,
-                                    SceneType.TYPE14,
-                                    SceneType.TYPE5,
-                                    SceneType.TYPE18
-                                )
-                    } else {
-                        "${str}锛屾薄鏌撴簮浠ラ楗�佸伐鍦颁负涓�" to
-                                listOf(
-                                    SceneType.TYPE1,
-                                    SceneType.TYPE2,
-                                    SceneType.TYPE3,
-                                    SceneType.TYPE14,
-                                    SceneType.TYPE5,
-                                    SceneType.TYPE18
-                                )
-                    }
+                    listOf(
+                        SceneType.TYPE1,
+                        SceneType.TYPE2,
+                        SceneType.TYPE3,
+                        SceneType.TYPE14,
+                        SceneType.TYPE5,
+                        SceneType.TYPE18
+                    )
                 }
-                // c) VOC杈冮珮锛屽悓姣旇绠梡m2.5鐨勯噺绾э紝鍙兘瀛樺湪鍚屾鍋忛珮锛堟苯淇�佸姞娌圭珯锛�, 鍚屾璁$畻O3鏄惁鏈夐珮鍊�
-                // d) VOC杈冮珮锛屽浜庡姞娌圭珯锛堣溅杈嗘嫢鍫垫儏鍐碉級锛孋O涓�鑸緝楂�, 鍚屾璁$畻O3鏄惁鏈夐珮鍊�
+
                 FactorType.VOC -> {
-//                    val pm25Avg = round(pollutedData.dataList.map { it.pm25!! }.average() * 10) / 10
-//                    val coAvg = round(pollutedData.dataList.map { it.co!! }.average()) / 1000
-//                    val o3Avg = round(pollutedData.dataList.map { it.o3!! }.average() * 10) / 10
-                    val pm25Avg = round((pollutedData.statisticMap[FactorType.PM25]?.avg ?: .0)) / 10
-                    val coAvg = round((pollutedData.statisticMap[FactorType.CO]?.avg ?: .0)) / 1000
-                    val o3Avg = round((pollutedData.statisticMap[FactorType.O3]?.avg ?: .0)) / 10
-                    "VOC鍋忛珮锛屽悓鏃禤M2.5閲忕骇涓�${pm25Avg}渭g/m鲁锛孋O閲忕骇涓�${coAvg}mg/m鲁锛孫3閲忕骇涓�${o3Avg}渭g/m鲁锛屾薄鏌撴簮浠ユ苯淇�佸姞娌圭珯涓轰富" to
-                            listOf(SceneType.TYPE5, SceneType.TYPE6, SceneType.TYPE17, SceneType.TYPE12, SceneType.TYPE18)
+                    listOf(SceneType.TYPE5, SceneType.TYPE6, SceneType.TYPE17, SceneType.TYPE12, SceneType.TYPE18)
                 }
 
                 else -> null
             }
-            des = res?.first
-            res?.second?.let { sceneTypes.addAll(it) }
+            res?.let { sceneTypes.addAll(it) }
         }
-        return (des ?: "") to sceneTypes
+        return sceneTypes.distinct()
     }
 
     /**
@@ -229,63 +175,36 @@
      * @return 婧簮鎻忚堪
      */
     private fun summaryTxt(pollutedData: PollutedData, sceneList: List<SceneInfoVo>): String {
-//        pollutedData.exception
-//        pollutedData.selectedFactor?.main
-
         val st = DateUtil.instance.getTime(pollutedData.startTime)
         val et = DateUtil.instance.getTime(pollutedData.endTime)
 
         // 1. 鎻忚堪寮傚父鍙戠敓鐨勬椂闂村拰寮傚父绫诲瀷
-        var txt = "鍦�${st}鑷�${et}涔嬮棿锛屽嚭鐜�${pollutedData.exception}"
+        var txt = "鍦�${st}鑷�${et}涔嬮棿锛屽嚭鐜�${pollutedData.exception}${pollutedData.times}娆�"
 
         // 2. 鎻忚堪寮傚父鏁版嵁鐨勫彉鍖栨儏鍐�
-        // 寮傚父鏁版嵁闀垮害搴旇澶т簬1锛岄涓�兼槸寮傚父寮�濮嬫暟鎹殑鍓嶄竴涓甯稿��,鍚庣画涓哄紓甯告暟鎹�硷紙浣嗕笉涓�瀹氭椂闂磋繛缁級
-        if (pollutedData.dataList.size > 1) {
-            val historyDataList = pollutedData.historyDataList.map { it.toBaseRealTimeData(BaseRealTimeData::class.java) }
-            when (pollutedData.exceptionType) {
-                // 閲忕骇绐佸彉
-                ExceptionType.TYPE4.value -> {
-                    val exceptionPair = mutableListOf<Pair<BaseRealTimeData, BaseRealTimeData>>()
-                    pollutedData.dataList.forEachIndexed { index, baseRealTimeData ->
-                        if (index == 0) return@forEachIndexed
-                        val preIndex = historyDataList.indexOfFirst {
-                            it.dataTime == baseRealTimeData.dataTime
-                        }
-                        exceptionPair.add(
-                            (if (preIndex - 1 < 0) historyDataList[0] else historyDataList[preIndex - 1])
-                                    to baseRealTimeData
-                        )
+        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}%")
                     }
-                    val statArr = mutableListOf<String>()
-                    pollutedData.statisticMap.entries.forEach { s ->
-                        val txtArr = mutableListOf<String>()
-                        exceptionPair.forEach exception@{ p ->
-                            val preValue = p.first.getByFactorType(s.key)
-                            val curValue = p.second.getByFactorType(s.key)
-                            if (preValue == null || curValue == null) return@exception
-                            val r = round((curValue - preValue) / preValue * 100)
-                            txtArr.add("浠�${preValue}渭g/m鲁绐佸彉鑷�${curValue}渭g/m鲁锛屽彉鍖栫巼涓�${r}%")
-                        }
-                        statArr.add("${s.key.getTxt()}閲忕骇${txtArr.joinToString("锛�")}")
-                    }
-                    txt += "锛�${statArr.joinToString("锛�")}"
-                }
-                // 蹇�熶笂鍗�
-                ExceptionType.TYPE9.value -> {
-                    pollutedData.statisticMap.entries.forEach { s ->
-                        val preValue = pollutedData.dataList.first().getByFactorType(s.key)
-                        val curValue = pollutedData.dataList.last().getByFactorType(s.key)
-                        if (preValue == null || curValue == null) return@forEach
-                        val r = round((curValue - preValue) / preValue * 100)
-                        txt += "锛屼粠${preValue}渭g/m鲁蹇�熶笂鍗囪嚦${curValue}渭g/m鲁锛屽彉鍖栫巼涓�${r}%"
+                    // 蹇�熶笂鍗�
+                    ExceptionType.TYPE9.value -> {
+                        txtArr.add("浠�${preValue}渭g/m鲁蹇�熶笂鍗囪嚦${curValue}渭g/m鲁锛屽彉鍖栭�熺巼涓�${rate}渭g/m鲁/绉掞紝鍙樺寲鐜囦负${per}%")
                     }
                 }
             }
-        } else {
-            pollutedData.statisticMap.entries.forEach { s ->
-                txt += "锛�${s.key.des}鏈�浣庡�间负${s.value.min}渭g/m鲁锛屾渶楂樺�间负${s.value.max}渭g/m鲁锛屽潎鍊间负${s.value.avg}渭g/m鲁"
-            }
+            statArr.add("${s.key.getTxt()}閲忕骇${txtArr.joinToString("锛�")}")
         }
+        txt += "锛�${statArr.joinToString("锛�")}"
 
         // 3. 鎻忚堪鍙戠幇鐨勯闄╂簮鎯呭喌
         if (sceneList.isEmpty()) {

--
Gitblit v1.9.3