From eb3dd00b0b7fcda477229d518d250f9c842b790b Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 21 十月 2025 17:45:44 +0800
Subject: [PATCH] 2025.10.21 1. 走航季度报告相关数据计算逻辑调整
---
src/main/kotlin/com/flightfeather/uav/biz/mission/MissionUtil.kt | 82 +++++++++++++++++++++++++++++++++++-----
1 files changed, 71 insertions(+), 11 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/biz/mission/MissionUtil.kt b/src/main/kotlin/com/flightfeather/uav/biz/mission/MissionUtil.kt
index b5017c7..2b49150 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/mission/MissionUtil.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/mission/MissionUtil.kt
@@ -1,7 +1,9 @@
package com.flightfeather.uav.biz.mission
+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
/**
* 璧拌埅浠诲姟璁$畻宸ュ叿
@@ -15,18 +17,76 @@
*/
fun calKilometres(data: List<BaseRealTimeData>): Double {
var distance = .0
- for (i in 1 until data.size) {
- val a = data[i - 1]
- val b = data[i]
- if (a.longitude == null || a.latitude == null || b.longitude == null || b.latitude == null) continue
+ var lastValidPoint: BaseRealTimeData? = null
- distance += MapUtil.getDistance(
- a.longitude!!.toDouble(),
- a.latitude!!.toDouble(),
- b.longitude!!.toDouble(),
- b.latitude!!.toDouble()
- )
+ for (point in data) {
+ // 璺宠繃鏃犳晥鐐�
+ if (point.longitude == null || point.latitude == null) continue
+
+ // 濡傛灉瀛樺湪涓婁竴涓湁鏁堢偣锛屽垯璁$畻璺濈
+ lastValidPoint?.let { prevPoint ->
+ distance += MapUtil.getDistance(
+ prevPoint.longitude!!.toDouble(),
+ prevPoint.latitude!!.toDouble(),
+ point.longitude!!.toDouble(),
+ point.latitude!!.toDouble()
+ )
+ }
+
+ // 鏇存柊涓婁竴涓湁鏁堢偣
+ lastValidPoint = point
}
return distance
}
-}
\ No newline at end of file
+
+ /**
+ * 鏍规嵁杞ㄨ抗鐐硅绠楁墍灞炲尯鍩燂紙涔¢晣+琛楅亾锛�
+ * @param data 璧拌埅杞ㄨ抗鐐瑰垪琛�
+ * @return 鍖哄煙鍚嶇О锛堜埂闀�+琛楅亾锛夛紝鑻ユ棤娉曡绠楀垯杩斿洖null
+ */
+ @Suppress("UNCHECKED_CAST")
+ fun calRegion(data: List<BaseRealTimeData>): String? {
+ // 璁$畻鎵�鏈夎建杩圭偣鐨勫钩鍧囧潗鏍囷紙涓績鐐癸級
+ val avgData = data.avg()
+ val pair = avgData.longitude?.toDouble() to avgData.latitude?.toDouble()
+ // 鑻ュ钩鍧囧潗鏍囨棤鏁堝垯杩斿洖null
+ if (pair.first == null || pair.second == null) return null
+ // 灏哤GS84鍧愭爣杞崲涓篏CJ02鍧愭爣鍚庤繘琛岄�嗗湴鐞嗙紪鐮佽幏鍙栧湴鍧�淇℃伅
+ val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(pair as Pair<Double, Double>))
+ // 杩斿洖涔¢晣鍜岃閬撳悕绉扮粍鍚�
+ return address.township
+ }
+
+ /**
+ * 鏁版嵁娓呮礂
+ * 1. 淇鐢变簬纭欢璁惧鍗¢】瀵艰嚧鐨勬暟鎹噰鏍锋椂闂翠笉鍙橀棶棰橈紝閲囩敤鑷姩绱姞鏁版嵁鍛ㄦ湡鐨勬柟寮忎慨鏀归噰鏍锋椂闂�
+ * @param data 鍘熷鏁版嵁鍒楄〃
+ * @param period 鏁版嵁鍛ㄦ湡锛屽崟浣嶏細绉�
+ * @return 娓呮礂鍚庨渶瑕佷慨鏀圭殑鏁版嵁鍒楄〃
+ */
+ fun dataClean(dataList: List<BaseRealTimeData>, period: Long): List<BaseRealTimeData> {
+ val cleanedData = mutableListOf<BaseRealTimeData>()
+ var errorData: BaseRealTimeData? = null
+ dataList.forEachIndexed { index, data ->
+ if (index == 0) {
+ return@forEachIndexed
+ }
+ val lastOne = dataList[index - 1]
+ if (errorData == null) {
+ if (data.dataTime!!.time == lastOne.dataTime!!.time) {
+ data.dataTime?.time = lastOne.dataTime?.time!!.plus(period * 1000)
+ cleanedData.add(data)
+ errorData = lastOne
+ }
+ } else {
+ if (data.dataTime!!.time == errorData!!.dataTime!!.time) {
+ data.dataTime?.time = lastOne.dataTime?.time!!.plus(period * 1000)
+ cleanedData.add(data)
+ } else {
+ errorData = null
+ }
+ }
+ }
+ return cleanedData
+ }
+}
--
Gitblit v1.9.3