From 7d33080998a2c5b38e8a74dbed2b0f40d39bbe47 Mon Sep 17 00:00:00 2001
From: Riku <risaku@163.com>
Date: 星期三, 04 六月 2025 23:27:26 +0800
Subject: [PATCH] 1. 新增动态污染溯源新的判定逻辑(待完成)
---
src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt | 48 ++++++++++++++++++++++++
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt | 26 +++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt
index c2c651f..5b3c06a 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt
@@ -1,9 +1,13 @@
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.SceneInfo
+import java.math.BigDecimal
import java.time.LocalDateTime
+import java.util.Date
import java.util.Timer
import java.util.TimerTask
@@ -30,6 +34,9 @@
inner class AnalysisResult{
// 鎸夌収琚壂鎻忔鏁伴檷搴忔帓鍒楃殑姹℃煋婧愬垪琛�
var sortedSceneList: List<Pair<SceneInfo?, Int>>? = null
+ var time: Date? = null
+ var advice:String?= null
+ var direction: AMapService.AMapDirection? = null
}
/**
@@ -154,8 +161,27 @@
result.sortedSceneList = res.map { it.value }
// 褰撳墠鐨勮蛋鑸暟鎹殑瀹氫綅鍜屾薄鏌撴簮璺濈鏄惁鏄�愭笎鎺ヨ繎锛岃嫢璧拌埅杩滅浜嗕富瑕佹薄鏌撴簮锛屾彁绀虹敤鎴疯皟鏁磋蛋鑸矾绾�
+ if (!result.sortedSceneList.isNullOrEmpty()) {
+ val sT = clueList.first().pollutedData?.startTime
+ val closetScene = result.sortedSceneList?.first()
+ result.advice = "鏍规嵁${sT}璧风殑${clueList.size}鏉℃渶鏂版薄鏌撶嚎绱紝姹℃煋婧怺${closetScene?.first?.name}]琚娆℃函婧愶紝鍏锋湁杈冮珮姹℃煋椋庨櫓锛岀幇鎻愪緵鏂扮殑璧拌埅鎺ㄨ崘璺嚎锛屽彲缁忚繃璇ユ薄鏌撴簮銆�"
+ val lastP = realTimeDataList.last()
+ if (lastP.longitude != null && lastP.latitude != null &&
+ lastP.longitude!! > BigDecimal.ZERO && lastP.latitude!! > BigDecimal.ZERO
+ && closetScene?.first?.longitude != null && closetScene.first?.latitude != null &&
+ closetScene.first?.longitude!! > BigDecimal.ZERO && closetScene.first?.latitude!! > BigDecimal.ZERO) {
+
+ val origin = MapUtil.wgs84ToGcj02(lastP.longitude!!.toDouble() to lastP.latitude!!.toDouble())
+ val destination = closetScene.first!!.longitude.toDouble() to closetScene.first!!.latitude.toDouble()
+
+ result.direction = AMapService.directionDriving(origin, destination)
+ }
+ }
+
+
+ result.time = realTimeDataList.last().dataTime
// 绾跨储鍒嗘瀽瀹屾垚鍚庯紝绉诲姩鑷冲巻鍙茬嚎绱㈠垪琛�
historyClueList.addAll(clueList)
clueList.clear()
diff --git a/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt b/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
index 615bc8f..52e1940 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
@@ -32,6 +32,54 @@
val street: String,
)
+ data class AMapDirection(
+ // 璺嚎绫诲瀷锛宒riving: 椹捐溅锛�
+ val type: String,
+ // 璧风偣缁忕含搴�
+ val origin: Pair<Double, Double>,
+ // 缁堢偣缁忕含搴�
+ val destination: Pair<Double, Double>,
+ // 閫斿緞璺嚎缁忕含搴︼紙涓嶅寘鎷捣鐐圭粓鐐癸級
+ val paths: List<Pair<Double, Double>>,
+ // 鏂规璺濈锛屽崟浣嶏細绫�
+ val distance: String
+ )
+
+ /**
+ * 椹捐溅璺嚎瑙勫垝
+ */
+ fun directionDriving(origin: Pair<Double, Double>, destination: Pair<Double, Double>):AMapDirection {
+ val res = httpMethod.get(
+ "/v5/direction/driving", listOf(
+ "key" to KEY,
+ "origin" to "${origin.first},${origin.second}",
+ "destination" to "${destination.first},${destination.second}",
+ "show_fields" to "polyline"
+ )
+ )
+ val obj = handleRes(res)
+ try {
+ val count = obj["count"].asString.toIntOrNull()
+ if (count != null && count > 0) {
+ val path = obj["route"].asJsonObject["paths"].asJsonArray.get(0).asJsonObject
+ val finalPaths = mutableListOf<Pair<Double,Double>>()
+ path["steps"].asJsonArray.forEach {
+ finalPaths.addAll(
+ it.asJsonObject["polyline"].asString.split(";").map { str->
+ val strArr = str.split(",")
+ strArr[0].toDouble() to strArr[1].toDouble()
+ }
+ )
+ }
+ return AMapDirection("driving", origin, destination, finalPaths, path["distance"].asString)
+ } else {
+ throw BizException("楂樺痉API椹捐溅璺嚎瑙勫垝澶辫触锛屾病鏈夋壘鍒板彲琛岀殑璺嚎")
+ }
+ } catch (e: Exception) {
+ throw BizException("楂樺痉API椹捐溅璺嚎瑙勫垝閿欒锛�${e.message}")
+ }
+ }
+
/**
* 鍦扮悊閫嗙紪鐮�
* @param location 鍧愭爣鐐�
--
Gitblit v1.9.3