From 176d7d8283e66ccf63878c9ab823e900df94b748 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 05 八月 2025 17:20:58 +0800
Subject: [PATCH] 2025.8.5 1. 动态溯源模块添加延迟数据周期异常合并功能

---
 src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

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 4ea338d..9b25bff 100644
--- a/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
+++ b/src/main/kotlin/com/flightfeather/uav/common/net/AMapService.kt
@@ -11,6 +11,7 @@
 
 /**
  * 楂樺痉鍦板浘Web鏈嶅姟API
+ * Date: 2024/07/14
  */
 object AMapService {
 
@@ -30,6 +31,54 @@
         val towncode: String,
         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}")
+        }
+    }
 
     /**
      * 鍦扮悊閫嗙紪鐮�
@@ -56,7 +105,7 @@
                 a["streetNumber"].asJsonObject["street"].asString,
             )
         } catch (e: Exception) {
-            throw BizException("楂樺痉API鍧愭爣杞崲閿欒锛�${e.message}")
+            throw BizException("楂樺痉API鍧愭爣杞崲閿欒锛�${e.message}", e.cause)
         }
     }
 

--
Gitblit v1.9.3