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 |  172 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 127 insertions(+), 45 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 0322e9a..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
 
@@ -64,12 +67,14 @@
     }
 
     /**
-     * 鎷嗗垎缃戞牸涓虹粏鍒嗙綉鏍�
+     * 鎷嗗垎缃戞牸涓虹粏鍒嗙綉鏍硷紝鎵�鏈夌綉鏍煎簲璇ユ槸鐩稿悓杈归暱鐨勬鏂瑰舰
      * 鏍规嵁鐩镐技鐭╁舰鐨勫師鐞嗭紝鍙互鍒嗗埆鎸夋瘮渚嬪緱鍒版瘡涓粏鍒嗙綉鏍肩殑缁忕含搴�
      * @param gridCellList 鍘熷缃戞牸鏁扮粍
      * @param scale 鎷嗗垎鐨勭郴鏁帮紝渚嬪 2锛岃〃绀哄皢鍘熸湁缃戞牸鎸夎竟闀跨殑 1/2 鎷嗗垎鎴� 2 * 2 鐨�4涓綉鏍�
+     * @param groupId 缁嗗垎鍚庣殑缃戞牸鎵�灞炵殑缃戞牸缁刬d
+     * @return
      */
-    fun splitGrid(gridCellList: List<GridCell>, scale: Int): List<GridCell> {
+    fun splitGrid(gridCellList: List<GridCell?>, scale: Int, groupId:Int): List<GridCell?> {
         if (scale <= 0) throw IllegalArgumentException("缃戞牸鎷嗗垎鐨勬暟閲忎笉鑳藉皬浜�1")
         // 鎷嗗垎绯绘暟涓�1锛屽垯琛ㄧず涓嶆媶鍒�
         if (scale == 1) return gridCellList
@@ -79,68 +84,145 @@
 
         // 鏍规嵁鍑芥暟[calGridVertex]鐢熸垚鐨勭綉鏍�4涓《鐐瑰潗鏍囷紝浠ヤ笂鍖椾笅鍗楀乏瑗垮彸涓滄柟鍚戜负鏍囧噯
         // 璁$畻棣栦釜缃戞牸涓績鍧愭爣鐐瑰垎鍒拰4涓《鐐圭殑缁忕含搴﹀樊鍊�
-        val p = gridCellList[0]
+        val p = gridCellList.find { it != null }!!
         // 锛堥�氳繃杩戜技骞抽潰鍧愭爣绯荤殑鏂瑰紡锛夋牴鎹崟涓師濮嬬綉鏍肩殑4涓《鐐瑰潗鏍囷紝鍒嗗埆纭畾浠ヤ笅涓夌粍鍧愭爣鐐逛箣闂寸殑缁忕含搴﹀崟浣嶅亸绉婚噺
         val p1 = p.point1Lon to p.point1Lat
         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()
 
-        // 缃戞牸琛屽惊鐜�
-        for (row in 0 until scale) {
-            val newGridCell1 = GridCell()
+        // 缃戞牸绱㈠紩
+        var cellIndex = 0
 
-            // 纭畾姣忎竴琛岄涓粏鍒嗙綉鏍肩殑涓績鍧愭爣鍜�4涓《鐐瑰潗鏍�
-            // 宸︿笂瑙掗《鐐规牴鎹墍鍦ㄨ鏁板湪鍘熷缃戞牸椤剁偣鍩虹涓婂鍔犲亸绉婚噺
-            newGridCell1.point1Lon = p1.first + dx1 * row.toBigDecimal()
-            newGridCell1.point1Lat = p1.second + dy1 * row.toBigDecimal()
-            // 宸︿笅瑙掗《鐐规牴鎹墍鍦ㄨ鏁板湪鍘熷缃戞牸椤剁偣鍩虹涓婂鍔犲亸绉婚噺锛堟瘮宸︿笂瑙掗《鐐瑰涓�涓亸绉伙級
-            newGridCell1.point3Lon = p1.first + dx1 * (row + 1).toBigDecimal()
-            newGridCell1.point3Lat = p1.second + 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.longitude = newGridCell1.point1Lon + dxC
-            newGridCell1.latitude = newGridCell1.point1Lat + dyC
+        // 瀵圭綉鏍肩粍鍐呯殑鎵�鏈夌綉鏍艰繘琛岀綉鏍肩粏鍒�
+        gridCellList.forEach { g ->
+            if (g == null) return@forEach
 
-            // 鍔犲叆缁撴灉闆嗗悎
-            newGridCellList.add(newGridCell1)
+            // 缃戞牸琛屽惊鐜�
+            for (row in 0 until scale) {
+                val newGridCell1 = GridCell()
 
-            // 缃戞牸鍒楀惊鐜�(浠庣2鍒楀紑濮�)
-            for (col in 1 until scale) {
-                val newGridCell = GridCell()
-                newGridCell.point1Lon = newGridCell1.point1Lon + dx2 * col.toBigDecimal()
-                newGridCell.point1Lat = newGridCell1.point1Lat + dy2 * col.toBigDecimal()
-                newGridCell.point2Lon = newGridCell1.point2Lon + dx2 * col.toBigDecimal()
-                newGridCell.point2Lat = newGridCell1.point2Lat + dy2 * col.toBigDecimal()
-                newGridCell.point3Lon = newGridCell1.point3Lon + dx3 * col.toBigDecimal()
-                newGridCell.point3Lat = newGridCell1.point3Lat + dy3 * col.toBigDecimal()
-                newGridCell.point4Lon = newGridCell1.point4Lon + dx3 * col.toBigDecimal()
-                newGridCell.point4Lat = newGridCell1.point4Lat + dy3 * col.toBigDecimal()
-                newGridCell.longitude = newGridCell.point1Lon + dxC
-                newGridCell.latitude = newGridCell.point1Lat + dyC
+                // 纭畾姣忎竴琛岄涓粏鍒嗙綉鏍肩殑涓績鍧愭爣鍜�4涓《鐐瑰潗鏍�
+                // 宸︿笂瑙掗《鐐规牴鎹墍鍦ㄨ鏁板湪鍘熷缃戞牸椤剁偣鍩虹涓婂鍔犲亸绉婚噺
+                newGridCell1.point1Lon = g.point1Lon + dx1 * row.toBigDecimal()
+                newGridCell1.point1Lat = g.point1Lat + dy1 * row.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.point3Lon = newGridCell1.point4Lon + dx3
+                newGridCell1.point3Lat = newGridCell1.point4Lat + dy3
+                // 涓績鐐瑰湪缁嗗垎缃戞牸宸︿笂瑙掔殑鍩虹涓婂鍔犲浐瀹氬亸绉婚噺
+                newGridCell1.longitude = newGridCell1.point1Lon + dxC
+                newGridCell1.latitude = newGridCell1.point1Lat + dyC
 
-                newGridCellList.add(newGridCell)
+                newGridCell1.groupId = groupId
+                newGridCell1.cellIndex = ++cellIndex
+                newGridCell1.fatherCellIndex = g.cellIndex
+
+                // 鍔犲叆缁撴灉闆嗗悎
+                newGridCellList.add(newGridCell1)
+
+                // 缃戞牸鍒楀惊鐜�(浠庣2鍒楀紑濮�)
+                for (col in 1 until scale) {
+                    val newGridCell = GridCell()
+                    newGridCell.point1Lon = newGridCell1.point1Lon + dx2 * col.toBigDecimal()
+                    newGridCell.point1Lat = newGridCell1.point1Lat + dy2 * col.toBigDecimal()
+                    newGridCell.point2Lon = newGridCell1.point2Lon + dx2 * col.toBigDecimal()
+                    newGridCell.point2Lat = newGridCell1.point2Lat + dy2 * col.toBigDecimal()
+                    newGridCell.point3Lon = newGridCell1.point3Lon + dx3 * col.toBigDecimal()
+                    newGridCell.point3Lat = newGridCell1.point3Lat + dy3 * col.toBigDecimal()
+                    newGridCell.point4Lon = newGridCell1.point4Lon + dx3 * col.toBigDecimal()
+                    newGridCell.point4Lat = newGridCell1.point4Lat + dy3 * col.toBigDecimal()
+                    newGridCell.longitude = newGridCell.point1Lon + dxC
+                    newGridCell.latitude = newGridCell.point1Lat + dyC
+
+                    newGridCell.groupId = groupId
+                    newGridCell.cellIndex = ++cellIndex
+                    newGridCell.fatherCellIndex = g.cellIndex
+
+                    newGridCellList.add(newGridCell)
+                }
             }
         }
-
         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