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/report/MissionGridFusion.kt |  169 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 147 insertions(+), 22 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt b/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt
index 710cc5f..563c22b 100644
--- a/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt
+++ b/src/main/kotlin/com/flightfeather/uav/biz/report/MissionGridFusion.kt
@@ -8,6 +8,7 @@
 import com.flightfeather.uav.domain.repository.SceneInfoRep
 import com.flightfeather.uav.lightshare.bean.GridDataDetailMixVo
 import com.flightfeather.uav.lightshare.eunm.PollutionDegree
+import com.flightfeather.uav.lightshare.eunm.SceneType
 import com.flightfeather.uav.socket.eunm.FactorType
 
 /**
@@ -16,6 +17,11 @@
  * @author feiyu02
  */
 class MissionGridFusion(private val sceneInfoRep: SceneInfoRep) {
+
+    companion object {
+        // 闇�缁熻楂橀闄╃綉鏍肩殑鏁伴噺
+        const val HIGH_RISK_GRID_NUM = 3
+    }
 
     /**
      * 鎸堿QI绛夌骇鍙犲姞缃戞牸
@@ -26,6 +32,10 @@
         var missionList: MutableList<MissionInventory.MissionInfo> = mutableListOf()
         var gridFusionList: MutableList<FusionGrid> = mutableListOf()
         var highRiskGridList: MutableList<HighRiskGridByFactor> = mutableListOf()
+        // 璧拌埅鍖哄煙鍐呯殑楂橀闄╃綉鏍�
+        var highRiskGridMap: MutableMap<FactorType, List<HighRiskGridByFactor>> = mutableMapOf()
+        // 鎶ュ憡瀵瑰簲鐨勮緰鍖哄唴鐨勯珮椋庨櫓缃戞牸
+        var highRiskGridMap2: MutableMap<FactorType, List<HighRiskGridByFactor>> = mutableMapOf()
     }
 
     /**
@@ -72,41 +82,156 @@
         gridCells: List<GridCell>,
         dataList: List<Triple<PollutionDegree, List<MissionInventory.MissionInfo>, List<GridDataDetailMixVo>>>,
     ): List<GridFusionByAQI> {
+        val polyLineJingAn = AMapService.polyLineJingAn.split(";")
+            .map {
+                val p = it.split(",")
+                Pair(p[0].toDouble(), p[1].toDouble())
+            }
+
         return dataList.map {
             GridFusionByAQI().apply {
+                // 绌烘皵璐ㄩ噺绛夌骇
                 pollutionDegree = it.first.des
+                // 缃戞牸杈归暱(绫�)
                 this.gridLen = gridLen
+                // 璧拌埅浠诲姟璇︽儏鍒楄〃
                 missionList.addAll(it.second)
+                // 缃戞牸铻嶅悎鍒楄〃
                 gridFusionList.addAll(it.third.map { gdm ->
                     val grid = gridCells.find { it.cellIndex == gdm.cellId }
                         ?: throw IllegalArgumentException("缃戞牸缁�${gdm.groupId}涓紝鍗曞厓ID: ${gdm.cellId} 涓嶅瓨鍦�")
                     FusionGrid(grid, gdm)
                 })
-                highRiskGridList.addAll(factorTypes.map { f->
-                    HighRiskGridByFactor().apply {
-                        factorType = f
-                        highRiskGrid = gridFusionList.maxByOrNull { gf->gf.data.getByFactorType(f) ?: 0f }
-                        if (highRiskGrid != null) {
-                            factorValue = highRiskGrid!!.data.getByFactorType(f)
-                            if (highRiskGrid!!.cell.longitude != null && highRiskGrid!!.cell.latitude != null) {
-                                Thread.sleep(100)
-                                val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(
-                                    highRiskGrid!!.cell.longitude.toDouble()
-                                            to highRiskGrid!!.cell.latitude.toDouble()
-                                ))
-                                town = address.township + address.address
+                // 鐩戞祴鍥犲瓙鐨勯珮椋庨櫓鍙犲姞缃戞牸鍒楄〃(姣忕鍥犲瓙鍙栧潎鍊兼渶楂樼殑缃戞牸)锛�2025.10.17 鍙栨秷姝ら�昏緫锛�
+//                highRiskGridList.addAll(factorTypes.map { f->
+//                    HighRiskGridByFactor().apply {
+//                        factorType = f
+//                        highRiskGrid = gridFusionList.maxByOrNull { gf->gf.data.getByFactorType(f) ?: 0f }
+//                        if (highRiskGrid != null) {
+//                            factorValue = highRiskGrid!!.data.getByFactorType(f)
+//                            if (highRiskGrid!!.cell.longitude != null && highRiskGrid!!.cell.latitude != null) {
+//                                Thread.sleep(100)
+//                                val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(
+//                                    highRiskGrid!!.cell.longitude.toDouble()
+//                                            to highRiskGrid!!.cell.latitude.toDouble()
+//                                ))
+//                                town = address.township + address.address
+//                            }
+//                            val polygon = listOf(
+//                                highRiskGrid!!.cell.point1Lon.toDouble() to highRiskGrid!!.cell.point1Lat.toDouble(),
+//                                highRiskGrid!!.cell.point2Lon.toDouble() to highRiskGrid!!.cell.point2Lat.toDouble(),
+//                                highRiskGrid!!.cell.point3Lon.toDouble() to highRiskGrid!!.cell.point3Lat.toDouble(),
+//                                highRiskGrid!!.cell.point4Lon.toDouble() to highRiskGrid!!.cell.point4Lat.toDouble(),
+//                            )
+//                            bounds = MapUtil.calFourBoundaries(polygon)
+//                            highRiskScenes = sceneInfoRep.findByPolygon(polygon)
+//                        }
+//                    }
+//                })
+                // 鐩戞祴鍥犲瓙鐨勯珮椋庨櫓鍙犲姞缃戞牸鍒楄〃(姣忕鍥犲瓙鍙栧潎鍊兼渶楂樼殑3涓綉鏍�)锛�2025.10.17 鏂板姝ら�昏緫锛�
+                factorTypes.forEach { f->
+                    gridFusionList.sortByDescending { gf->gf.data.getByFactorType(f) ?: 0f }
+                    val takeList = mutableListOf<HighRiskGridByFactor>()
+                    val takeList2 = mutableListOf<HighRiskGridByFactor>()
+                    for (i in gridFusionList.indices) {
+                        val gf = gridFusionList[i]
+                        var highRiskGridByFactor: HighRiskGridByFactor? = null
+                        if (takeList2.size < HIGH_RISK_GRID_NUM) {
+                            highRiskGridByFactor = HighRiskGridByFactor().apply {
+                                factorType = f
+                                highRiskGrid = gf
+                                factorValue = gf.data.getByFactorType(f)
+                                if (gf.cell.longitude != null && gf.cell.latitude != null) {
+                                    Thread.sleep(500)
+                                    val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(
+                                        gf.cell.longitude.toDouble() to gf.cell.latitude.toDouble()
+                                    ))
+                                    town = if (address.address.contains(address.streetNumber)) {
+                                        address.address
+                                    } else {
+                                        address.address + "锛�" + address.street + address.streetNumber + "锛�"
+                                    }
+                                }
+                                val polygon = listOf(
+                                    gf.cell.point1Lon.toDouble() to gf.cell.point1Lat.toDouble(),
+                                    gf.cell.point2Lon.toDouble() to gf.cell.point2Lat.toDouble(),
+                                    gf.cell.point3Lon.toDouble() to gf.cell.point3Lat.toDouble(),
+                                    gf.cell.point4Lon.toDouble() to gf.cell.point4Lat.toDouble(),
+                                )
+                                bounds = MapUtil.calFourBoundaries(polygon)
+                                highRiskScenes =
+                                    sceneInfoRep.findByPolygon(polygon, listOf(SceneType.TYPE19, SceneType.TYPE20, SceneType.TYPE21))
                             }
-                            val polygon = listOf(
-                                highRiskGrid!!.cell.point1Lon.toDouble() to highRiskGrid!!.cell.point1Lat.toDouble(),
-                                highRiskGrid!!.cell.point2Lon.toDouble() to highRiskGrid!!.cell.point2Lat.toDouble(),
-                                highRiskGrid!!.cell.point3Lon.toDouble() to highRiskGrid!!.cell.point3Lat.toDouble(),
-                                highRiskGrid!!.cell.point4Lon.toDouble() to highRiskGrid!!.cell.point4Lat.toDouble(),
-                            )
-                            bounds = MapUtil.calFourBoundaries(polygon)
-                            highRiskScenes = sceneInfoRep.findByPolygon(polygon)
+                            takeList2.add(highRiskGridByFactor)
                         }
+                        //
+                        if (takeList.size >= HIGH_RISK_GRID_NUM) break
+
+                        // fixme 2025.10.20 涓存椂娣诲姞绛涢�夊湪闈欏畨鍖哄唴閮ㄧ殑缃戞牸
+                        val check = if (it.second[0].districtCode == "310106") {
+                            MapUtil.isPointInPolygon(
+                                    Pair(gf.cell.longitude.toDouble(), gf.cell.latitude.toDouble()),
+                                    polyLineJingAn
+                                )
+                        } else {
+                            true
+                        }
+                        if (check) {
+                            takeList.add(highRiskGridByFactor ?: HighRiskGridByFactor().apply {
+                                factorType = f
+                                highRiskGrid = gf
+                                factorValue = gf.data.getByFactorType(f)
+                                if (gf.cell.longitude != null && gf.cell.latitude != null) {
+                                    Thread.sleep(100)
+                                    val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(
+                                        gf.cell.longitude.toDouble() to gf.cell.latitude.toDouble()
+                                    ))
+                                    town = if (address.address.contains(address.streetNumber)) {
+                                        address.address
+                                    } else {
+                                        address.address + address.street + address.streetNumber
+                                    }
+                                }
+                                val polygon = listOf(
+                                    gf.cell.point1Lon.toDouble() to gf.cell.point1Lat.toDouble(),
+                                    gf.cell.point2Lon.toDouble() to gf.cell.point2Lat.toDouble(),
+                                    gf.cell.point3Lon.toDouble() to gf.cell.point3Lat.toDouble(),
+                                    gf.cell.point4Lon.toDouble() to gf.cell.point4Lat.toDouble(),
+                                )
+                                bounds = MapUtil.calFourBoundaries(polygon)
+                                highRiskScenes =
+                                    sceneInfoRep.findByPolygon(polygon, listOf(SceneType.TYPE19, SceneType.TYPE20, SceneType.TYPE21))
+                            })
+                        }
+
                     }
-                })
+                    highRiskGridMap[f] = takeList
+                    highRiskGridMap2[f] = takeList2
+
+//                    highRiskGridMap[f] = gridFusionList.take(HIGH_RISK_GRID_NUM).map { gf->
+//                        HighRiskGridByFactor().apply {
+//                            factorType = f
+//                            highRiskGrid = gf
+//                            factorValue = gf.data.getByFactorType(f)
+//                            if (gf.cell.longitude != null && gf.cell.latitude != null) {
+//                                Thread.sleep(100)
+//                                val address = AMapService.reGeo(MapUtil.wgs84ToGcj02(
+//                                    gf.cell.longitude.toDouble() to gf.cell.latitude.toDouble()
+//                                ))
+//                                town = address.address + address.street + address.streetNumber
+//                            }
+//                            val polygon = listOf(
+//                                gf.cell.point1Lon.toDouble() to gf.cell.point1Lat.toDouble(),
+//                                gf.cell.point2Lon.toDouble() to gf.cell.point2Lat.toDouble(),
+//                                gf.cell.point3Lon.toDouble() to gf.cell.point3Lat.toDouble(),
+//                                gf.cell.point4Lon.toDouble() to gf.cell.point4Lat.toDouble(),
+//                            )
+//                            bounds = MapUtil.calFourBoundaries(polygon)
+//                            highRiskScenes =
+//                                sceneInfoRep.findByPolygon(polygon, listOf(SceneType.TYPE19, SceneType.TYPE20, SceneType.TYPE21))
+//                        }
+//                    }
+                }
             }
         }
     }

--
Gitblit v1.9.3