From 594de76ed51fd49fb79b912212bb0052a63e7671 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 09 四月 2026 16:10:45 +0800
Subject: [PATCH] 2026.4.9

---
 src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/DataAnalysisServiceImpl.kt |  156 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 112 insertions(+), 44 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 efb1451..b7fcaf3 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
@@ -15,13 +15,16 @@
 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.DataHead
 import com.flightfeather.uav.lightshare.bean.GridDataDetailMixVo
+import com.flightfeather.uav.lightshare.bean.SourceTraceMsgVo
 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 com.github.pagehelper.PageHelper
 import org.springframework.stereotype.Service
 import java.util.*
 
@@ -77,14 +80,19 @@
      * 鑾峰彇鍘嗗彶姹℃煋婧簮缁撴灉
      * 鏌ヨ鎸囧畾浠诲姟鐨勫巻鍙叉薄鏌撴函婧愮粨鏋滃苟搴忓垪鍖栦负JSON瀛楃涓�
      * @param missionCode 璧拌埅浠诲姟缂栫爜
+     * @param minPer 鏈�灏忔薄鏌撶櫨鍒嗘瘮锛岀敤浜庣瓫閫夊紓甯告暟鎹偣锛堝彲閫夛級
      * @return 鍘嗗彶姹℃煋婧簮缁撴灉鐨凧SON瀛楃涓诧紝鍏蜂綋鏍煎紡鐢眘ourceTraceRep瀹炵幇鍐冲畾
      * @throws BizException 褰撹蛋鑸换鍔′笉瀛樺湪鏃舵姏鍑�
      */
-    override fun fetchHistory(missionCode: String): String {
+    override fun fetchHistory(missionCode: String, minPer: Double?, page: Int?, perPage: Int?): Pair<DataHead, String> {
         val mission = missionRep.findOne(missionCode) ?: throw BizException("璧拌埅浠诲姟涓嶅瓨鍦�")
-
-        val res = sourceTraceRep.fetchList(mission.deviceCode, mission.startTime, mission.endTime)
-        return GsonUtils.gson.toJson(res)
+        val p = if (page != null && perPage != null) {
+            PageHelper.startPage<SourceTraceMsgVo>(page, perPage)
+        } else {
+            null
+        }
+        val res = sourceTraceRep.fetchList(mission.deviceCode, mission.startTime, mission.endTime, minPer = minPer ?: 0.5)
+        return DataHead(p?.pageNum ?: 1, p?.pages ?: 1) to GsonUtils.gson.toJson(res)
     }
 
     /**
@@ -94,26 +102,33 @@
      * @param endTime 缁熻缁撴潫鏃堕棿锛堝寘鍚級
      * @param areaVo 鍖哄煙鍙傛暟锛屽寘鍚渷銆佸競銆佸尯涓夌骇琛屾斂鍖哄垝缂栫爜
      * @return 姹囨�荤粺璁″璞★紝鍖呭惈浠诲姟鎬绘暟銆佸紓甯哥偣鏁伴噺銆佸钩鍧囬噷绋嬬瓑鏍稿績鎸囨爣
-     * @see MissionSummary 姹囨�荤粺璁″鐞嗗櫒锛屽皝瑁呭叿浣撶殑缁熻閫昏緫瀹炵幇
+     * @see MissionSummary 姹囨�荤粺璁″鐞嗗櫒锛屽皝瑁呭叿浣撶粺璁¢�昏緫鐨勫疄鐜�
      */
-    override fun generateMissionSummary(startTime: Date, endTime: Date, areaVo: AreaVo): MissionSummary.Summary {
+    override fun generateMissionSummary(
+        startTime: Date, endTime: Date, areaVo: AreaVo, removeOtherDistrict: Boolean,
+        removeNoPollutedSource: Boolean, minPer: Double?,
+    ): MissionSummary.Summary {
         val clues = mutableListOf<PollutedClue?>()
         val missions = missionRep.findByAreaAndTime(areaVo, startTime, endTime).onEach {
             it ?: return@onEach
-            val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>
+            val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue, minPer ?: 0.5) as List<PollutedClue?>
             clues.addAll(clue)
         }
+        filterClue(areaVo, clues, removeOtherDistrict, removeNoPollutedSource)
         val summary = MissionSummary().execute(startTime, endTime, missions, clues)
         return summary
     }
 
-    override fun generateMissionSummary(missionCode: String): MissionSummary.Summary {
+    override fun generateMissionSummary(
+        missionCode: String, minPer: Double?,
+    ): MissionSummary.Summary {
         val mission = missionRep.findOne(missionCode) ?: throw BizException("璧拌埅浠诲姟涓嶅瓨鍦�")
         val clues = sourceTraceRep.fetchList(
             mission.deviceCode,
             mission.startTime,
             mission.endTime,
-            MsgType.PolClue
+            MsgType.PolClue,
+            minPer ?: 0.5,
         ) as List<PollutedClue?>
         val summary = MissionSummary().execute(mission.startTime, mission.endTime, listOf(mission), clues)
         return summary
@@ -129,17 +144,20 @@
      * @see MissionRep.findByAreaAndTime 鍖哄煙鏃堕棿绛涢�夋暟鎹簮
      * @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)
+    override fun generateMissionList(
+        startTime: Date, endTime: Date, areaVo: AreaVo, removeOtherDistrict: Boolean,
+        removeNoPollutedSource: Boolean, minPer: Double?,
+    ): List<MissionInventory.MissionInfo> {
         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 clues = sourceTraceRep.fetchList(
+                it.deviceCode,
+                it.startTime,
+                it.endTime,
+                MsgType.PolClue,
+                minPer ?: 0.5
+            ) as List<PollutedClue?>
+            filterClue(areaVo, clues.toMutableList(), removeOtherDistrict, removeNoPollutedSource)
+            Triple(it, clues, realTimeDataRep.fetchData(it))
         }
         val keyScenes = sceneInfoRep.findBySceneTypes(
             listOf(
@@ -187,13 +205,20 @@
         endTime: Date,
         areaVo: AreaVo,
         granularity: String?,
+        removeOtherDistrict: Boolean,
+        removeNoPollutedSource: Boolean,
+        minPer: Double?,
     ): 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 clues = sourceTraceRep.fetchList(
+                it.deviceCode,
+                it.startTime,
+                it.endTime,
+                MsgType.PolClue,
+                minPer ?: 0.5
+            ) as List<PollutedClue?>
+            filterClue(areaVo, clues.toMutableList(), removeOtherDistrict, removeNoPollutedSource)
+            Triple(it, clues, realTimeDataRep.fetchData(it))
         }
         val keyScenes = sceneInfoRep.findBySceneTypes(
             listOf(
@@ -205,13 +230,18 @@
         return generateMissionDetail(keyScenes, missionCluesData, granularity ?: "MINUTE")
     }
 
-    override fun generateMissionDetail(missionCode: String, granularity: String?): MissionInventory.MissionDetail {
+    override fun generateMissionDetail(
+        missionCode: String,
+        granularity: String?,
+        minPer: Double?,
+    ): MissionInventory.MissionDetail {
         val mission = missionRep.findOne(missionCode) ?: throw BizException("浠诲姟涓嶅瓨鍦�")
         val missionClues = sourceTraceRep.fetchList(
             mission.deviceCode,
             mission.startTime,
             mission.endTime,
-            MsgType.PolClue
+            MsgType.PolClue,
+            minPer ?: 0.5
         ) as List<PollutedClue?>
         val realTimeData = realTimeDataRep.fetchData(mission)
         val keyScenes = sceneInfoRep.findBySceneTypes(
@@ -248,33 +278,42 @@
         areaVo: AreaVo,
         removeOtherDistrict: Boolean,
         removeNoPollutedSource: Boolean,
+        minPer: Double?,
     ): List<MissionRiskArea.ClassifyClue> {
         val clues = mutableListOf<PollutedClue?>()
         missionRep.findByAreaAndTime(areaVo, startTime, endTime).onEach {
             it ?: return@onEach
-            val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>
+            val clue = sourceTraceRep.fetchList(
+                it.deviceCode,
+                it.startTime,
+                it.endTime,
+                MsgType.PolClue,
+                minPer ?: 0.5
+            ) as List<PollutedClue?>
             clues.addAll(clue)
         }
-        if (removeOtherDistrict) {
-            clues.removeIf {
-                !areaVo.districtName.isNullOrBlank() &&
-                        (it?.pollutedArea?.address.isNullOrBlank()
-                                || !it!!.pollutedArea!!.address!!.contains(areaVo.districtName!!))
-            }
-        }
-        if (removeNoPollutedSource) {
-            clues.removeIf { it?.pollutedSource?.sceneList.isNullOrEmpty() }
-        }
+//        if (removeOtherDistrict) {
+//            clues.removeIf {
+//                !areaVo.districtName.isNullOrBlank() &&
+//                        (it?.pollutedArea?.address.isNullOrBlank()
+//                                || !it!!.pollutedArea!!.address!!.contains(areaVo.districtName!!))
+//            }
+//        }
+//        if (removeNoPollutedSource) {
+//            clues.removeIf { it?.pollutedSource?.sceneList.isNullOrEmpty() }
+//        }
+        filterClue(areaVo, clues, removeOtherDistrict, removeNoPollutedSource)
         return MissionRiskArea().generateClueByRiskArea(clues)
     }
 
-    override fun generateClueByRiskArea(missionCode: String): List<MissionRiskArea.ClueByArea> {
+    override fun generateClueByRiskArea(missionCode: String, minPer: Double?): List<MissionRiskArea.ClueByArea> {
         val mission = missionRep.findOne(missionCode) ?: throw BizException("浠诲姟涓嶅瓨鍦�")
         val pollutedClues = sourceTraceRep.fetchList(
             mission.deviceCode,
             mission.startTime,
             mission.endTime,
-            MsgType.PolClue
+            MsgType.PolClue,
+            minPer ?: 0.5
         ) as List<PollutedClue?>
         val keyScenes = sceneInfoRep.findBySceneTypes(
             listOf(
@@ -298,6 +337,9 @@
         startTime: Date,
         endTime: Date,
         areaVo: AreaVo,
+        removeOtherDistrict: Boolean,
+        removeNoPollutedSource: Boolean,
+        minPer: Double?,
     ): List<MissionGridFusion.GridFusionByAQI> {
         val gridLen = 100
         // 鏌ヨ100绫崇綉鏍肩殑鍏蜂綋缃戞牸鏁版嵁
@@ -328,11 +370,15 @@
             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 clues = sourceTraceRep.fetchList(
+                    it.deviceCode,
+                    it.startTime,
+                    it.endTime,
+                    MsgType.PolClue,
+                    minPer ?: 0.5
+                ) as List<PollutedClue?>
+                filterClue(areaVo, clues.toMutableList(), removeOtherDistrict, removeNoPollutedSource)
+                Triple(it, clues, realTimeDataRep.fetchData(it))
             }
             val keyScenes = sceneInfoRep.findBySceneTypes(
                 listOf(
@@ -357,4 +403,26 @@
     ): List<MissionGridFusion.GridFusionByAQI> {
         return MissionGridFusion(sceneInfoRep).generateGridFusion(factorTypes, gridLen, gridCells, dataList)
     }
+
+    private fun filterClue(
+        areaVo: AreaVo, clues: MutableList<PollutedClue?>, removeOtherDistrict: Boolean,
+        removeNoPollutedSource: Boolean,
+    ) {
+        if (removeOtherDistrict) {
+            clues.removeIf {
+                !areaVo.districtName.isNullOrBlank() &&
+                        (it?.pollutedArea?.address.isNullOrBlank()
+                                || !it!!.pollutedArea!!.address!!.contains(areaVo.districtName!!))
+            }
+            clues.forEach {
+                it?.pollutedSource?.sceneList = it?.pollutedSource?.sceneList?.filter { s->
+                    s.districtCode == areaVo.districtCode
+                }
+            }
+        }
+        if (removeNoPollutedSource) {
+            clues.removeIf { it?.pollutedSource?.sceneList.isNullOrEmpty() }
+        }
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3