From 538ba7a3bbc682f4537f1dd34f93feb2cf56b08e Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 14 十月 2025 17:32:04 +0800
Subject: [PATCH] 2025.10.14 1. 新增数据统计颗粒度选项,可选秒级数据、分钟数据进行数据统计 2. 典型隐患区域统计新增按照污染溯源区域进行分类统计的功能

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt |  206 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 169 insertions(+), 37 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..52efc03 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,18 +11,18 @@
 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
-import tk.mybatis.mapper.entity.Example
 import java.util.*
 
 /**
@@ -39,7 +40,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 {
 
     /**
@@ -104,6 +107,13 @@
         return summary
     }
 
+    override fun generateMissionSummary(missionCode: String): MissionSummary.Summary {
+        val mission = missionRep.findOne(missionCode) ?: throw BizException("璧拌埅浠诲姟涓嶅瓨鍦�")
+        val clues = sourceTraceRep.fetchList(mission.deviceCode, mission.startTime, mission.endTime, MsgType.PolClue) as List<PollutedClue?>
+        val summary = MissionSummary().execute(mission.startTime, mission.endTime, listOf(mission), clues)
+        return summary
+    }
+
     /**
      * 鐢熸垚璧拌埅浠诲姟娓呭崟锛堟寜鏃堕棿鍜屽尯鍩熺瓫閫夛級
      * 鏍规嵁鏃堕棿鑼冨洿鍜岃鏀垮尯鍒掓煡璇㈣蛋鑸换鍔★紝骞跺叧鑱旀薄鏌撶嚎绱㈡暟鎹敓鎴愪换鍔″垪琛�
@@ -115,34 +125,10 @@
      * @see generateMissionList 閲嶈浇鏂规硶锛屽鐞嗗凡鍏宠仈鐨勬暟鎹
      */
     override fun generateMissionList(startTime: Date, endTime: Date, areaVo: AreaVo): List<MissionInventory.MissionInfo> {
-        val missionClues = missionRep.findByAreaAndTime(areaVo, startTime, endTime).filterNotNull().map {
-            it to sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>
-        }
-        return generateMissionList(missionClues)
-    }
-
-    /**
-     * 鐢熸垚璧拌埅浠诲姟娓呭崟锛堢洿鎺ュ鐞嗕换鍔℃暟鎹級
-     * 鎺ユ敹宸插叧鑱旂殑浠诲姟-姹℃煋绾跨储鏁版嵁瀵癸紝鐢熸垚鏍煎紡鍖栫殑浠诲姟鍒楄〃
-     * @param missionClues 浠诲姟-姹℃煋绾跨储鏁版嵁瀵瑰垪琛紝Pair.first涓轰换鍔″璞★紝Pair.second涓哄搴旀薄鏌撶嚎绱�
-     * @return 鏍囧噯鍖栫殑璧拌埅浠诲姟淇℃伅鍒楄〃锛屽寘鍚换鍔″熀鏈睘鎬у拰姹℃煋缁熻淇℃伅
-     * @see MissionInventory 浠诲姟娓呭崟鐢熸垚鍣紝灏佽鍏蜂綋鏍煎紡鍖栭�昏緫
-     */
-    override fun generateMissionList(missionClues: List<Pair<Mission, List<PollutedClue?>>>): List<MissionInventory.MissionInfo> {
-        return MissionInventory().generateMissionList(missionClues)
-    }
-
-    /**
-     * 鐢熸垚璧拌埅浠诲姟璇︽儏锛堟寜鏃堕棿鍜屽尯鍩熺瓫閫夛級
-     * 鏍规嵁鏃堕棿鑼冨洿鍜岃鏀垮尯鍒掓煡璇换鍔★紝鏁村悎瀹炴椂鐩戞祴鏁版嵁鐢熸垚璇︾粏浠诲姟鎶ュ憡
-     * @param startTime 鏌ヨ璧峰鏃堕棿锛堝寘鍚級
-     * @param endTime 鏌ヨ缁撴潫鏃堕棿锛堝寘鍚級
-     * @param areaVo 鍖哄煙鍙傛暟锛屽寘鍚渷銆佸競銆佸尯缂栫爜
-     * @return 浠诲姟璇︽儏鍒楄〃锛屾瘡涓厓绱犲寘鍚换鍔″畬鏁翠俊鎭�佹薄鏌撶嚎绱㈠強瀹炴椂鐩戞祴鏁版嵁
-     * @see MissionRep.findByAreaAndTime 鍖哄煙鏃堕棿绛涢�夋暟鎹簮
-     * @see realTimeDataRep.fetchData 瀹炴椂鏁版嵁鑾峰彇鎺ュ彛
-     */
-    override fun generateMissionDetail(startTime: Date, endTime: Date, areaVo: AreaVo): List<MissionInventory.MissionDetail> {
+//        val missionClues = missionRep.findByAreaAndTime(areaVo, startTime, endTime).filterNotNull().map {
+//            it to sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>
+//        }
+//        return generateMissionList(missionClues)
         val missionCluesData = missionRep.findByAreaAndTime(areaVo, startTime, endTime).filterNotNull().map {
             Triple(
                 it,
@@ -157,7 +143,75 @@
                 SceneType.TYPE21.value
             )
         )
-        return generateMissionDetail(keyScenes, missionCluesData)
+        return generateMissionInfo(keyScenes, missionCluesData)
+    }
+
+    /**
+     * 鐢熸垚璧拌埅浠诲姟娓呭崟锛堢洿鎺ュ鐞嗕换鍔℃暟鎹級
+     * 鎺ユ敹宸插叧鑱旂殑浠诲姟-姹℃煋绾跨储鏁版嵁瀵癸紝鐢熸垚鏍煎紡鍖栫殑浠诲姟鍒楄〃
+     * @param missionClues 浠诲姟-姹℃煋绾跨储鏁版嵁瀵瑰垪琛紝Pair.first涓轰换鍔″璞★紝Pair.second涓哄搴旀薄鏌撶嚎绱�
+     * @return 鏍囧噯鍖栫殑璧拌埅浠诲姟淇℃伅鍒楄〃锛屽寘鍚换鍔″熀鏈睘鎬у拰姹℃煋缁熻淇℃伅
+     * @see MissionInventory 浠诲姟娓呭崟鐢熸垚鍣紝灏佽鍏蜂綋鏍煎紡鍖栭�昏緫
+     */
+    override fun generateMissionList(missionClues: List<Pair<Mission, List<PollutedClue?>>>): List<MissionInventory.MissionInfo> {
+        return MissionInventory().generateMissionList(missionClues)
+    }
+
+    override fun generateMissionInfo(
+        keyScenes: List<SceneInfo?>,
+        missionCluesData: List<Triple<Mission, List<PollutedClue?>, List<BaseRealTimeData>>>,
+    ): List<MissionInventory.MissionInfo> {
+        return missionCluesData.map {
+            MissionInventory().generateMissionInfo(keyScenes, it.first, it.second, it.third)
+        }
+    }
+
+    /**
+     * 鐢熸垚璧拌埅浠诲姟璇︽儏锛堟寜鏃堕棿鍜屽尯鍩熺瓫閫夛級
+     * 鏍规嵁鏃堕棿鑼冨洿鍜岃鏀垮尯鍒掓煡璇换鍔★紝鏁村悎瀹炴椂鐩戞祴鏁版嵁鐢熸垚璇︾粏浠诲姟鎶ュ憡
+     * @param startTime 鏌ヨ璧峰鏃堕棿锛堝寘鍚級
+     * @param endTime 鏌ヨ缁撴潫鏃堕棿锛堝寘鍚級
+     * @param areaVo 鍖哄煙鍙傛暟锛屽寘鍚渷銆佸競銆佸尯缂栫爜
+     * @param granularity 鏁版嵁棰楃矑搴︼紝鍙�夊�间负SECOND, MINUTE, HOUR, 榛樿MINUTE
+     * @return 浠诲姟璇︽儏鍒楄〃锛屾瘡涓厓绱犲寘鍚换鍔″畬鏁翠俊鎭�佹薄鏌撶嚎绱㈠強瀹炴椂鐩戞祴鏁版嵁
+     * @see MissionRep.findByAreaAndTime 鍖哄煙鏃堕棿绛涢�夋暟鎹簮
+     * @see realTimeDataRep.fetchData 瀹炴椂鏁版嵁鑾峰彇鎺ュ彛
+     */
+    override fun generateMissionDetail(
+        startTime: Date,
+        endTime: Date,
+        areaVo: AreaVo,
+        granularity: String?,
+    ): List<MissionInventory.MissionDetail> {
+        val missionCluesData = missionRep.findByAreaAndTime(areaVo, startTime, endTime).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
+            )
+        )
+        return generateMissionDetail(keyScenes, missionCluesData, granularity ?: "MINUTE")
+    }
+
+    override fun generateMissionDetail(missionCode: String, granularity: String?): MissionInventory.MissionDetail {
+        val mission = missionRep.findOne(missionCode) ?: throw BizException("浠诲姟涓嶅瓨鍦�")
+        val missionClues = sourceTraceRep.fetchList(mission.deviceCode, mission.startTime, mission.endTime, MsgType.PolClue) as List<PollutedClue?>
+        val realTimeData = realTimeDataRep.fetchData(mission)
+        val keyScenes = sceneInfoRep.findBySceneTypes(
+            listOf(
+                SceneType.TYPE19.value,
+                SceneType.TYPE20.value,
+                SceneType.TYPE21.value
+            )
+        )
+        return MissionInventory().generateMissionDetail(keyScenes, mission, missionClues, realTimeData, granularity ?: "MINUTE")
     }
 
     /**
@@ -171,9 +225,10 @@
     override fun generateMissionDetail(
         keyScenes: List<SceneInfo?>,
         missionCluesData: List<Triple<Mission, List<PollutedClue?>, List<BaseRealTimeData>>>,
+        granularity: String,
     ): List<MissionInventory.MissionDetail> {
         return missionCluesData.map {
-            MissionInventory().generateMissionDetail(keyScenes, it.first, it.second, it.third)
+            MissionInventory().generateMissionDetail(keyScenes, it.first, it.second, it.third, granularity)
         }
     }
 
@@ -188,6 +243,19 @@
             val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>
             clues.addAll(clue)
         }
+//        val keyScenes = sceneInfoRep.findBySceneTypes(
+//            listOf(
+//                SceneType.TYPE19.value,
+//                SceneType.TYPE20.value,
+//                SceneType.TYPE21.value
+//            )
+//        )
+        return MissionRiskArea().generateClueByRiskArea(clues)
+    }
+
+    override fun generateClueByRiskArea(missionCode: String): List<MissionRiskArea.ClueByArea> {
+        val mission = missionRep.findOne(missionCode) ?: throw BizException("浠诲姟涓嶅瓨鍦�")
+        val pollutedClues = sourceTraceRep.fetchList(mission.deviceCode, mission.startTime, mission.endTime, MsgType.PolClue) as List<PollutedClue?>
         val keyScenes = sceneInfoRep.findBySceneTypes(
             listOf(
                 SceneType.TYPE19.value,
@@ -195,13 +263,77 @@
                 SceneType.TYPE21.value
             )
         )
-        return generateClueByRiskArea(keyScenes, clues)
+        return generateClueByRiskArea(keyScenes, pollutedClues)
     }
 
     override fun generateClueByRiskArea(
         keyScenes: List<SceneInfo?>,
         pollutedClues: List<PollutedClue?>,
     ): List<MissionRiskArea.ClueByArea> {
-        return MissionRiskArea().generateClueByRiskArea(keyScenes, pollutedClues)
+        return MissionRiskArea().generateClueByKeyRiskScene(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 missionInfos = generateMissionInfo(keyScenes, missionCluesData)
+
+            return@mapNotNull Triple(degree, missionInfos, 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.MissionInfo>, List<GridDataDetailMixVo>>>,
+    ): List<MissionGridFusion.GridFusionByAQI> {
+        return MissionGridFusion(sceneInfoRep).generateGridFusion(factorTypes, gridLen, gridCells, dataList)
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3