From 707b00a0ca6604c249a110b376ac1e44e408e624 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 04 九月 2025 18:24:39 +0800
Subject: [PATCH] 2025.9.4 1. 新增走航任务统计功能(待完成)

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt |   76 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt
index 9826661..0dcbb4a 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt
@@ -3,6 +3,7 @@
 import com.flightfeather.uav.biz.FactorFilter
 import com.flightfeather.uav.biz.dataanalysis.ExceptionAnalysisController
 import com.flightfeather.uav.biz.dataanalysis.model.ExceptionResult
+import com.flightfeather.uav.biz.report.MissionGridFusion
 import com.flightfeather.uav.biz.report.MissionInventory
 import com.flightfeather.uav.biz.report.MissionRiskArea
 import com.flightfeather.uav.biz.report.MissionSummary
@@ -10,14 +11,15 @@
 import com.flightfeather.uav.common.exception.BizException
 import com.flightfeather.uav.common.location.LocationRoadNearby
 import com.flightfeather.uav.common.utils.GsonUtils
-import com.flightfeather.uav.domain.entity.BaseRealTimeData
-import com.flightfeather.uav.domain.entity.Mission
-import com.flightfeather.uav.domain.entity.SceneInfo
+import com.flightfeather.uav.domain.entity.*
 import com.flightfeather.uav.domain.mapper.MissionMapper
 import com.flightfeather.uav.domain.repository.*
 import com.flightfeather.uav.lightshare.bean.AreaVo
+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.lightshare.service.DataAnalysisService
+import com.flightfeather.uav.lightshare.service.SatelliteDataCalculateService
 import com.flightfeather.uav.socket.eunm.FactorType
 import com.flightfeather.uav.socket.sender.MsgType
 import org.springframework.stereotype.Service
@@ -39,7 +41,9 @@
     private val locationRoadNearby: LocationRoadNearby,
     private val segmentInfoRep: SegmentInfoRep,
     private val sourceTraceRep: SourceTraceRep,
-    private val sceneInfoRep: SceneInfoRep
+    private val sceneInfoRep: SceneInfoRep,
+    private val satelliteGridRep: SatelliteGridRep,
+    private val satelliteDataCalculateService: SatelliteDataCalculateService
 ) : DataAnalysisService {
 
     /**
@@ -204,4 +208,68 @@
     ): List<MissionRiskArea.ClueByArea> {
         return MissionRiskArea().generateClueByRiskArea(keyScenes, pollutedClues)
     }
+
+    override fun generateGridFusion(
+        factorTypes: List<FactorType>,
+        startTime: Date,
+        endTime: Date,
+        areaVo: AreaVo,
+    ): List<MissionGridFusion.GridFusionByAQI> {
+        val gridLen = 100
+        // 鏌ヨ100绫崇綉鏍肩殑鍏蜂綋缃戞牸鏁版嵁
+        val gridGroup = satelliteGridRep.fetchGridGroup(GridGroup().apply {
+            type = "sub"
+            length = gridLen.toDouble()
+            provinceCode = areaVo.provinceCode
+            cityCode = areaVo.cityCode
+            districtCode = areaVo.districtCode
+        }).firstOrNull() ?: throw BizException("鏈煡璇㈠埌100绫崇綉鏍�")
+        val gridCells = satelliteGridRep.fetchGridCell(gridGroup.id).filterNotNull()
+        // 鏌ヨ鑼冨洿鍐呯殑鎵�鏈夎蛋鑸换鍔�
+        val missions = missionRep.findByAreaAndTime(areaVo, startTime, endTime)
+        // 鏍规嵁绌烘皵璐ㄩ噺绛夌骇鍒嗙被
+        val missionGroups = missions.groupBy { PollutionDegree.getByDes(it?.pollutionDegree ?: "") }
+        // 鏌ヨ姣忎釜绛夌骇涓嬬殑璧拌埅浠诲姟瀵瑰簲鐨勭綉鏍兼暟鎹紙濡傛灉娌℃湁鏁版嵁鍒欏墧闄よ浠诲姟锛�
+        val gridDataDetailList = missionGroups.mapNotNull { (degree, missionList) ->
+            // 绛涢�夊嚭鏈夌綉鏍艰瀺鍚堟暟鎹殑璧拌埅浠诲姟(鍚屾椂鑾峰彇瀵瑰簲鐨勮瀺鍚堟暟鎹甶d鍒楄〃)
+            val gridDataIds = mutableListOf<Int>()
+            val validMissions = missionList.filter {mission ->
+                val gridData = satelliteGridRep.fetchGridData(GridData().apply { missionCode = mission?.missionCode }).firstOrNull()
+                val res = gridData != null
+                if (res) gridDataIds.add(gridData?.id ?: 0)
+                res
+            }
+            // 鍚堝苟姣忎釜绛夌骇涓嬬殑缃戞牸鏁版嵁
+            val gridDataDetailMixVos = satelliteDataCalculateService.mixUnderwayGridData(gridGroup.id, gridDataIds)
+            // 缁熻姣忎釜璧拌埅浠诲姟鐨勮蛋鑸鎯呬俊鎭�
+            val missionCluesData = validMissions.filterNotNull().map {
+                Triple(
+                    it,
+                    sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>,
+                    realTimeDataRep.fetchData(it)
+                )
+            }
+            val keyScenes = sceneInfoRep.findBySceneTypes(
+                listOf(
+                    SceneType.TYPE19.value,
+                    SceneType.TYPE20.value,
+                    SceneType.TYPE21.value
+                )
+            )
+            val missionDetails = generateMissionDetail(keyScenes, missionCluesData)
+
+            return@mapNotNull Triple(degree, missionDetails, gridDataDetailMixVos)
+        }.filter { it.second.isNotEmpty() }
+
+        return generateGridFusion(factorTypes, gridLen, gridCells, gridDataDetailList)
+    }
+
+    override fun generateGridFusion(
+        factorTypes: List<FactorType>,
+        gridLen: Int,
+        gridCells: List<GridCell>,
+        dataList: List<Triple<PollutionDegree, List<MissionInventory.MissionDetail>, List<GridDataDetailMixVo>>>,
+    ): List<MissionGridFusion.GridFusionByAQI> {
+        return MissionGridFusion(sceneInfoRep).generateGridFusion(factorTypes, gridLen, gridCells, dataList)
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3