From 8fc27dba6719041402e3e3c099e2f3e01d9d52c7 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期三, 16 七月 2025 17:30:56 +0800
Subject: [PATCH] 2025.7.16 1. 修改动态溯源异常判断逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt |  133 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 130 insertions(+), 3 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
index bcfe4e2..cd82f6c 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedArea.kt
@@ -1,18 +1,145 @@
 package com.flightfeather.uav.biz.sourcetrace.model
 
+import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig
+import com.flightfeather.uav.common.net.AMapService
+import com.flightfeather.uav.common.utils.MapUtil
+import com.flightfeather.uav.domain.entity.BaseRealTimeData
+import com.flightfeather.uav.domain.entity.avg
+import kotlin.math.PI
+
 /**
  * 鍔ㄦ�佹函婧愭薄鏌撳尯鍩�
  * 閫氳繃鍦板浘鍧愭爣鐐瑰舰鎴愬杈瑰舰鏉ユ弿杩颁竴鍧楁薄鏌撳尯鍩�
  * @date 2025/5/27
  * @author feiyu02
  */
-class PollutedArea {
+class PollutedArea() {
 
-    var name: String? = null
+    /**
+     * 婧簮瑙掑害鍙缃�
+     */
 
-    // 姹℃煋鑼冨洿鍖哄煙(缁忕含搴﹀杈瑰舰)
+    constructor(
+        historyData: List<BaseRealTimeData>,
+        exceptionData: List<BaseRealTimeData>,
+        config: RTExcWindLevelConfig,
+        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?,
+    ) : this() {
+        distanceType = windLevelCondition?.distanceType
+        windLevelCondition?.let { sourceTrace(historyData, exceptionData, config, it) }
+    }
+
+    var address: String? = null
+
+    // 姹℃煋鑼冨洿鎵囧舰鍖哄煙(缁忕含搴﹀杈瑰舰)
     var polygon: List<Pair<Double, Double>>? = null
+
+    // 杩戣窛绂绘薄鏌撳渾褰㈠尯鍩�
+    var closePolygon: List<Pair<Double, Double>>? = null
 
     // 姹℃煋鍙兘鐨勫彂鐢熻窛绂�
     var distanceType: DistanceType? = null
+
+    /**
+     * 鍙嶅悜婧簮
+     */
+    private fun sourceTrace(
+        historyData: List<BaseRealTimeData>,
+        exceptionData: List<BaseRealTimeData>,
+        config: RTExcWindLevelConfig,
+        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition,
+    ) {
+        val avgData = if (exceptionData.size == 1) {
+            exceptionData.first()
+        } else {
+            exceptionData.avg()
+        }
+
+        val pair = avgData.longitude!!.toDouble() to avgData.latitude!!.toDouble()
+
+        polygon = calSector(
+            avgData.windDirection!!.toDouble(),
+            pair,
+            windLevelCondition.distanceType.disRange,
+            config.sourceTraceDegOffset
+        ).map {
+            // 灏嗗潗鏍囪浆鎹负gcj02锛堢伀鏄熷潗鏍囩郴锛夛紝鍥犱负姹℃煋婧愬満鏅俊鎭兘涓烘鍧愭爣绯�
+            MapUtil.wgs84ToGcj02(it)
+        }
+
+        closePolygon = closeSourceTrace(historyData, pair)
+
+        try {
+            val address = AMapService.reGeo(pair)
+            this.address = address.district + address.township + address.street
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+
+    }
+
+    /**
+     * 鏍规嵁涓績鐐瑰潗鏍囥�侀鍚戝拰婧簮璺濈锛屼互鍙婄粰瀹氱殑澶硅锛岃绠椾互涓績鐐规寜鐓ч鍚戝悜澶栨墿鏁e舰鎴愮殑鎵囧舰鐨勭偣鍧愭爣
+     * @param windDir 椋庡悜锛屽崟浣嶏細搴�
+     * @param center 涓績鐐瑰潗鏍囩粡绾害
+     * @param distanceRange 婧簮璺濈鑼冨洿锛屽崟浣嶏細绫�
+     * @param defaultDegOffset 鎵╂暎鍋忕Щ瑙掑害
+     * @return 澶氳竟褰㈤《鐐瑰潗鏍囬泦鍚�
+     */
+    private fun calSector(
+        windDir: Double,
+        center: Pair<Double, Double>,
+        distanceRange: Pair<Double, Double>,
+        defaultDegOffset: Double = 60.0,
+    ): List<Pair<Double, Double>> {
+
+        val sDeg = windDir - defaultDegOffset / 2
+        val eDeg = windDir + defaultDegOffset / 2
+
+        val result = mutableListOf<Pair<Double, Double>>()
+
+        if (distanceRange.first == .0) {
+//            result.add(center)
+            var startDeg = 0
+            while (startDeg <= 360) {
+                val p = MapUtil.getPointByLen(center, distanceRange.second, startDeg * PI / 180)
+                result.add(p)
+                startDeg++
+            }
+        } else {
+            // 浠庡紑濮嬭搴﹀惊鐜绠楀潗鏍囩偣鑷崇粨鏉熻搴︼紝姝ラ暱1掳
+            var startDeg = sDeg
+            while (startDeg <= eDeg) {
+                val p = MapUtil.getPointByLen(center, distanceRange.first, startDeg * PI / 180)
+                result.add(p)
+                startDeg++
+            }
+            if (distanceRange.second > .0) {
+                // 姝ゅ闇�瑕佷粠缁撴潫瑙掑害寮�濮嬪弽鍚戝惊鐜绠楄嚦寮�濮嬭搴︼紝姝ラ暱1掳锛屼娇寰椾袱缁勫潗鏍囩偣鎸夐『搴忔帓鍒楋紝鍙粯鍒跺搴旂殑澶氳竟褰�
+                startDeg = eDeg
+                while (startDeg >= sDeg) {
+                    val p = MapUtil.getPointByLen(center, distanceRange.second, startDeg * PI / 180)
+                    result.add(p)
+                    startDeg--
+                }
+            }
+        }
+
+        return result
+    }
+
+    private fun closeSourceTrace(
+        historyData: List<BaseRealTimeData>,
+        center: Pair<Double, Double>,
+    ): List<Pair<Double, Double>> {
+        val result = mutableListOf<Pair<Double, Double>>()
+        var startDeg = 0
+        while (startDeg <= 360) {
+            val p = MapUtil.getPointByLen(center, DistanceType.TYPE1.disRange.second, startDeg * PI / 180)
+            result.add(p)
+            startDeg++
+        }
+
+        return result
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3