From bde043c8fd1a076f44c402dd56c62d401afbfb16 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 27 三月 2025 17:29:48 +0800
Subject: [PATCH] 1. 新增卫星遥测网格热力图计算逻辑

---
 src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt |   94 ++++++++++++++++++++++++++++++++++------------
 1 files changed, 69 insertions(+), 25 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 36c85c7..c201a99 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/satellite/SatelliteGridManage.kt
@@ -2,6 +2,11 @@
 
 import com.flightfeather.uav.common.utils.MapUtil
 import com.flightfeather.uav.domain.entity.*
+import com.flightfeather.uav.model.underwaygrid.GridCellAndData
+import com.flightfeather.uav.model.underwaygrid.GridCellSop
+import com.flightfeather.uav.model.underwaygrid.UnderwayGridModel
+import com.flightfeather.uav.socket.eunm.FactorType
+import org.springframework.beans.BeanUtils
 import kotlin.math.PI
 import kotlin.math.sqrt
 
@@ -229,7 +234,7 @@
      */
     fun dataFusion(
         realTimeDataList: List<BaseRealTimeData>,
-        gridData: GridData,
+        gridData: GridData?,
         gridCellList: List<GridCell?>,
     ): List<GridDataDetail> {
         // 閬嶅巻璧拌埅鐩戞祴鏁版嵁锛岃绠楁瘡涓偣鎵�鍦ㄧ綉鏍�
@@ -237,12 +242,13 @@
         realTimeDataList.forEach {
             if (it.longitude == null || it.latitude == null) return@forEach
 
-            searchGirdIn(it.longitude!!.toDouble() to it.latitude!!.toDouble(), gridCellList)?.let { cell ->
-                if (!dataMap.containsKey(cell)) {
-                    dataMap[cell] = mutableListOf()
+            SatelliteGridUtil.searchGirdIn(it.longitude!!.toDouble() to it.latitude!!.toDouble(), gridCellList)
+                ?.let { cell ->
+                    if (!dataMap.containsKey(cell)) {
+                        dataMap[cell] = mutableListOf()
+                    }
+                    dataMap[cell]?.add(it)
                 }
-                dataMap[cell]?.add(it)
-            }
         }
 
         // 缁熻姣忎釜缃戞牸涓殑鍧囧��
@@ -250,40 +256,78 @@
         val gridDataDetailList = mutableListOf<GridDataDetail>()
         dataMap.forEach { (k, v) ->
             val avgData = v.avg()
-            val dataDetail = GridDataDetail().apply {
-                dataId = gridData.id
+            val dataDetail = GridDataDetail()
+            BeanUtils.copyProperties(avgData, dataDetail)
+            dataDetail.apply {
+                dataId = gridData?.id
                 groupId = k.groupId
                 cellId = k.cellIndex
-                pm25 = avgData.pm25
                 rank
             }
             gridDataDetailList.add(dataDetail)
         }
 
+        gridDataDetailList.sortBy { it.pm25 }
+        gridDataDetailList.forEachIndexed { index, d ->
+            d.rank = index + 1
+        }
+        gridDataDetailList.sortBy { it.cellId }
+
         return gridDataDetailList
     }
 
     /**
-     * 璁$畻鍧愭爣鐐瑰湪鍝釜鍗槦缃戞牸鍐�
-     * @date 2025.2.14
-     * @param point 鍧愭爣鐐�
-     * @param gridCellList 鍗槦缃戞牸
+     * 璁$畻鐑姏鍥剧綉鏍硷紝鍗崇綉鏍煎懆杈规墿鏁e奖鍝嶆潈閲嶈绠�
+     * @param gridDataDetail 缃戞牸鐩戞祴鏁版嵁
+     * @param gridCellList 鍖哄煙缃戞牸鏁扮粍
+     * @param option 鍖哄煙缃戞牸鍙傛暟淇℃伅
+     * @param searchLength 璁$畻鍛ㄨ竟鍏柟鍚戯紙涓婁笅宸﹀彸鍙婂洓涓瑙掞級缃戞牸鐨勯暱搴�
+     * @return 鍛ㄨ竟缃戞牸鍙婂搴旂殑鐩戞祴鏁版嵁缁撴灉
      */
-    fun searchGirdIn(point: Pair<Double, Double>, gridCellList: List<GridCell?>): GridCell? {
-        for (i in gridCellList.indices) {
-            val gridCell = gridCellList[i] ?: continue
-            val polygon = listOf(
-                gridCell.point1Lon.toDouble() to gridCell.point1Lat.toDouble(),
-                gridCell.point2Lon.toDouble() to gridCell.point2Lat.toDouble(),
-                gridCell.point3Lon.toDouble() to gridCell.point3Lat.toDouble(),
-                gridCell.point4Lon.toDouble() to gridCell.point4Lat.toDouble(),
-            )
-            if (MapUtil.isPointInPolygon(point, polygon)) {
-                return gridCell
+    fun heatMap(
+        gridDataDetail: GridDataDetail, gridCellList: List<GridCell?>,
+        option: GridGroupOption, searchLength: Int,
+    ): List<GridDataDetail> {
+        // 鎵惧埌缃戞牸鏁版嵁瀵瑰簲鐨勭綉鏍间俊鎭�
+        val gridCell = gridCellList.find { it?.cellIndex == gridDataDetail.cellId }
+            ?: throw IllegalArgumentException("缃戞牸鏁版嵁鍜岀粰瀹氱殑鍖哄煙缃戞牸涓嶅尮閰�")
+
+        // 鑾峰彇鍛ㄨ竟缃戞牸
+        val surroundGridCellList =
+            SatelliteGridUtil.searchDiffuseGrid(gridDataDetail.cellId, gridCellList, option, searchLength)
+
+        // 浣跨敤璧拌埅缃戞牸鏉冮噸妯″瀷锛岃绠楀懆杈圭綉鏍肩殑鐩戞祴鏁版嵁鍊�
+        val underwayGridModel = UnderwayGridModel()
+        val dataList = listOf(GridCellAndData(gridCell, gridDataDetail))
+        val gridCellSopList = surroundGridCellList.map {
+            GridCellSop(
+                it,
+                it.id.toString(),
+                it.cellIndex.toString(),
+                it.cellIndex.toString()
+            ) }
+        underwayGridModel.execute(dataList, gridCellSopList)
+        val resMap = underwayGridModel.outputResult()
+
+        // 鏍煎紡鍖栫粨鏋滃苟杩斿洖
+        val result = mutableListOf<GridDataDetail>()
+        gridCellSopList.forEach {
+            val resGridDataDetail = GridDataDetail().apply {
+                dataId = gridDataDetail.dataId
+                groupId = gridDataDetail.groupId
+                cellId = it.gridCell.cellIndex
             }
+
+            val key = "${it.sourceName};${it.index}"
+            val d = resMap[key]
+            d?.forEach { (t, u) ->
+                val avg = u["缁煎悎(${t})"]?.average ?: .0
+                resGridDataDetail.setFactorValue(FactorType.getByName(t), avg.toFloat())
+            }
+            result.add(resGridDataDetail)
         }
 
-        return null
+        return result
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.3