From e133600480d5f688a8375db7708fe531b4726f4a Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 07 二月 2025 17:38:38 +0800
Subject: [PATCH] 1. 新增卫星网格拆分、遥测数据拆分映射功能

---
 src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt |   85 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
index 783ceb6..1bfc3e9 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -1,7 +1,10 @@
 package com.flightfeather.uav.biz.satellite
 
 import com.flightfeather.uav.common.utils.MapUtil
+import com.flightfeather.uav.domain.entity.BaseRealTimeData
 import com.flightfeather.uav.domain.entity.GridCell
+import com.flightfeather.uav.domain.entity.GridData
+import com.flightfeather.uav.domain.entity.GridDataDetail
 import kotlin.math.PI
 import kotlin.math.sqrt
 
@@ -87,15 +90,15 @@
         val p2 = p.point2Lon to p.point2Lat
         val p3 = p.point3Lon to p.point3Lat
         val p4 = p.point4Lon to p.point4Lat
-        // p1銆乸3鐨勭粡绾害鍗曚綅宸��
-        val dx1 = (p3.first - p1.first) / scale.toBigDecimal()
-        val dy1 = (p3.second - p1.second) / scale.toBigDecimal()
+        // p1銆乸4鐨勭粡绾害鍗曚綅宸��
+        val dx1 = (p4.first - p1.first) / scale.toBigDecimal()
+        val dy1 = (p4.second - p1.second) / scale.toBigDecimal()
         // p1銆乸2鐨勭粡绾害鍗曚綅宸��
         val dx2 = (p2.first - p1.first) / scale.toBigDecimal()
         val dy2 = (p2.second - p1.second) / scale.toBigDecimal()
-        // p3銆乸4鐨勭粡绾害鍗曚綅宸��
-        val dx3 = (p4.first - p3.first) / scale.toBigDecimal()
-        val dy3 = (p4.second - p3.second) / scale.toBigDecimal()
+        // p4銆乸3鐨勭粡绾害鍗曚綅宸��
+        val dx3 = (p3.first - p4.first) / scale.toBigDecimal()
+        val dy3 = (p3.second - p4.second) / scale.toBigDecimal()
         // 涓績鐐瑰拰p1鐨勭粡绾害鍗曚綅宸��
         val dxC = (p.longitude - p1.first) / scale.toBigDecimal()
         val dyC = (p.latitude - p1.second) / scale.toBigDecimal()
@@ -116,14 +119,14 @@
                 newGridCell1.point1Lon = g.point1Lon + dx1 * row.toBigDecimal()
                 newGridCell1.point1Lat = g.point1Lat + dy1 * row.toBigDecimal()
                 // 宸︿笅瑙掗《鐐规牴鎹墍鍦ㄨ鏁板湪鍘熷缃戞牸椤剁偣鍩虹涓婂鍔犲亸绉婚噺锛堟瘮宸︿笂瑙掗《鐐瑰涓�涓亸绉伙級
-                newGridCell1.point3Lon = g.point1Lon + dx1 * (row + 1).toBigDecimal()
-                newGridCell1.point3Lat = g.point1Lat + dy1 * (row + 1).toBigDecimal()
+                newGridCell1.point4Lon = g.point1Lon + dx1 * (row + 1).toBigDecimal()
+                newGridCell1.point4Lat = g.point1Lat + dy1 * (row + 1).toBigDecimal()
                 // 鍙充笂瑙掗《鐐瑰湪缁嗗垎缃戞牸宸︿笂瑙掔殑鍩虹涓婂鍔犵浉搴旂殑鍋忕Щ閲�
                 newGridCell1.point2Lon = newGridCell1.point1Lon + dx2
                 newGridCell1.point2Lat = newGridCell1.point1Lat + dy2
                 // 鍙充笅瑙掗《鐐瑰湪缁嗗垎缃戞牸宸︿笅瑙掔殑鍩虹涓婂鍔犵浉搴旂殑鍋忕Щ閲�
-                newGridCell1.point4Lon = newGridCell1.point3Lon + dx3
-                newGridCell1.point4Lat = newGridCell1.point3Lat + dy3
+                newGridCell1.point3Lon = newGridCell1.point4Lon + dx3
+                newGridCell1.point3Lat = newGridCell1.point4Lat + dy3
                 // 涓績鐐瑰湪缁嗗垎缃戞牸宸︿笂瑙掔殑鍩虹涓婂鍔犲浐瀹氬亸绉婚噺
                 newGridCell1.longitude = newGridCell1.point1Lon + dxC
                 newGridCell1.latitude = newGridCell1.point1Lat + dyC
@@ -160,4 +163,66 @@
         return newGridCellList
     }
 
+    /**
+     * 鎷嗗垎鏁版嵁锛屽皢鍘熷鍗槦缃戞牸閬ユ祴鏁版嵁鏄犲皠鍒板搴旂粏鍒嗙綉鏍间笂
+     * @param subGridCellList 缁嗗垎缃戞牸, 鎸夌収
+     * @param subGridData 缁嗗垎缃戞牸瀵瑰簲鐨勬暟鎹储寮�
+     * @param originGridDataDetailList 缁嗗垎缃戞牸鎵�灞炵綉鏍肩殑鍘熷缃戞牸鏁版嵁
+     */
+    fun splitData(
+        subGridCellList: List<GridCell?>, subGridData: GridData, originGridDataDetailList: List<GridDataDetail?>
+    ): List<GridDataDetail> {
+        if (subGridCellList.isEmpty() || originGridDataDetailList.isEmpty()) return emptyList()
+
+        val result = mutableListOf<GridDataDetail>()
+
+        // 灏嗙粏鍒嗙綉鏍兼寜鐓х埗缃戞牸id鍜岃嚜韬綉鏍糹d杩涜鍗囧簭鎺掑垪
+        val _subGridCellList = subGridCellList.sortedWith(Comparator { o1, o2 ->
+            if (o1 == null && o2 == null) {
+                return@Comparator 0
+            } else if (o1 == null) {
+                return@Comparator -1
+            } else if (o2 == null) {
+                return@Comparator 1
+            } else {
+                if (o1.fatherCellIndex == o2.fatherCellIndex) {
+                    return@Comparator o1.cellIndex - o2.cellIndex
+                } else {
+                    return@Comparator o1.fatherCellIndex - o2.fatherCellIndex
+                }
+            }
+        })
+
+        // 灏嗗師濮嬬綉鏍兼暟鎹寜鐓х綉鏍糹d鍗囧簭鎺掑垪
+        val _originGridDataDetailIterator = originGridDataDetailList.sortedBy { it?.cellId }.iterator()
+        var fatherGridData = _originGridDataDetailIterator.next()
+
+        // 閬嶅巻缁嗗垎缃戞牸锛屼负姣忎釜缁嗗垎缃戞牸鐢熸垚涓�鏉$綉鏍兼暟鎹�
+        _subGridCellList.forEach {
+            while (fatherGridData?.cellId != it?.fatherCellIndex && _originGridDataDetailIterator.hasNext()) {
+                fatherGridData = _originGridDataDetailIterator.next()
+            }
+            val subGridDataDetail = GridDataDetail().apply {
+                dataId = subGridData.id
+                groupId = it?.groupId
+                cellId = it?.cellIndex
+                pm25 = fatherGridData?.pm25
+                rank = fatherGridData?.rank
+            }
+
+            result.add(subGridDataDetail)
+        }
+
+        return result
+    }
+
+    /**
+     * 鏁版嵁铻嶅悎
+     * @param realTimeDataList 寰呰瀺鍚堢殑璧拌埅鐩戞祴鏁版嵁
+     * @param gridData 铻嶅悎鍚庣殑鏁版嵁缁勭储寮�
+     * @param gridCellList 寰呰瀺鍚堢殑鍗槦缃戞牸
+     */
+    fun dataFusion(realTimeDataList:List<BaseRealTimeData>, gridData: GridData, gridCellList: List<GridCell?>) {
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3