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/lightshare/service/impl/DataAnalysisServiceImpl.kt | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 302 insertions(+), 22 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 3982b5c..bb19140 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
@@ -1,32 +1,34 @@
package com.flightfeather.uav.lightshare.service.impl
import com.flightfeather.uav.biz.FactorFilter
-import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult
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
-import com.flightfeather.uav.biz.sourcetrace.model.BasePollutedMsg
import com.flightfeather.uav.biz.sourcetrace.model.PollutedClue
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.Mission
+import com.flightfeather.uav.domain.entity.*
import com.flightfeather.uav.domain.mapper.MissionMapper
-import com.flightfeather.uav.domain.repository.MissionRep
-import com.flightfeather.uav.domain.repository.RealTimeDataRep
-import com.flightfeather.uav.domain.repository.SegmentInfoRep
-import com.flightfeather.uav.domain.repository.SourceTraceRep
+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.time.LocalDateTime
-import java.time.ZoneId
import java.util.*
/**
- *
+ * 鏁版嵁鍒嗘瀽鏈嶅姟鎺ュ彛瀹炵幇绫�
+ * 鎻愪緵璧拌埅浠诲姟鏁版嵁鐨勭粺璁″垎鏋愩�佹薄鏌撴函婧愩�佷换鍔℃竻鍗曞強璇︽儏鐢熸垚绛夋牳蹇冧笟鍔″姛鑳�
+ * 鏁村悎澶氭暟鎹簮瀹屾垚鏁版嵁鑱氬悎涓庡垎鏋愶紝涓哄墠绔彁渚涙爣鍑嗗寲鐨勭粺璁$粨鏋�
* @date 2025/5/8
* @author feiyu02
*/
@@ -37,9 +39,20 @@
private val realTimeDataRep: RealTimeDataRep,
private val locationRoadNearby: LocationRoadNearby,
private val segmentInfoRep: SegmentInfoRep,
- private val sourceTraceRep: SourceTraceRep
+ private val sourceTraceRep: SourceTraceRep,
+ private val sceneInfoRep: SceneInfoRep,
+ private val satelliteGridRep: SatelliteGridRep,
+ private val satelliteDataCalculateService: SatelliteDataCalculateService,
) : DataAnalysisService {
+ /**
+ * 姹℃煋婧簮鍒嗘瀽
+ * 瀵规寚瀹氳蛋鑸换鍔¤繘琛屽鍥犲瓙姹℃煋鏁版嵁鍒嗘瀽锛岃瘑鍒紓甯告暟鎹偣鍜屾綔鍦ㄦ薄鏌撴簮
+ * @param missionCode 璧拌埅浠诲姟缂栫爜锛堜富閿級
+ * @return 寮傚父缁撴灉鍒楄〃锛屽寘鍚紓甯哥被鍨嬨�佷綅缃�佹祿搴﹀�肩瓑璇︾粏淇℃伅
+ * @throws BizException 褰撹蛋鑸换鍔′笉瀛樺湪鏃舵姏鍑�
+ * @see ExceptionAnalysisController 寮傚父鍒嗘瀽鎺у埗鍣紝澶勭悊鍏蜂綋鐨勬暟鎹垎鏋愰�昏緫
+ */
override fun pollutionTrace(missionCode: String): List<ExceptionResult> {
val mission = missionRep.findOne(missionCode) ?: throw BizException("璧拌埅浠诲姟涓嶅瓨鍦�")
@@ -60,6 +73,13 @@
)
}
+ /**
+ * 鑾峰彇鍘嗗彶姹℃煋婧簮缁撴灉
+ * 鏌ヨ鎸囧畾浠诲姟鐨勫巻鍙叉薄鏌撴函婧愮粨鏋滃苟搴忓垪鍖栦负JSON瀛楃涓�
+ * @param missionCode 璧拌埅浠诲姟缂栫爜
+ * @return 鍘嗗彶姹℃煋婧簮缁撴灉鐨凧SON瀛楃涓诧紝鍏蜂綋鏍煎紡鐢眘ourceTraceRep瀹炵幇鍐冲畾
+ * @throws BizException 褰撹蛋鑸换鍔′笉瀛樺湪鏃舵姏鍑�
+ */
override fun fetchHistory(missionCode: String): String {
val mission = missionRep.findOne(missionCode) ?: throw BizException("璧拌埅浠诲姟涓嶅瓨鍦�")
@@ -67,21 +87,281 @@
return GsonUtils.gson.toJson(res)
}
- override fun missionSummary(startTime: Date, endTime: Date, areaVo: AreaVo): MissionSummary.Summary {
+ /**
+ * 鐢熸垚璧拌埅浠诲姟姹囨�荤粺璁�
+ * 鎸夋椂闂磋寖鍥村拰琛屾斂鍖哄垝缁熻璧拌埅浠诲姟鐨勫叧閿寚鏍囷紙浠诲姟鏁伴噺銆佸紓甯哥巼銆佸钩鍧囬噷绋嬬瓑锛�
+ * @param startTime 缁熻璧峰鏃堕棿锛堝寘鍚級
+ * @param endTime 缁熻缁撴潫鏃堕棿锛堝寘鍚級
+ * @param areaVo 鍖哄煙鍙傛暟锛屽寘鍚渷銆佸競銆佸尯涓夌骇琛屾斂鍖哄垝缂栫爜
+ * @return 姹囨�荤粺璁″璞★紝鍖呭惈浠诲姟鎬绘暟銆佸紓甯哥偣鏁伴噺銆佸钩鍧囬噷绋嬬瓑鏍稿績鎸囨爣
+ * @see MissionSummary 姹囨�荤粺璁″鐞嗗櫒锛屽皝瑁呭叿浣撶殑缁熻閫昏緫瀹炵幇
+ */
+ override fun generateMissionSummary(startTime: Date, endTime: Date, areaVo: AreaVo): MissionSummary.Summary {
val clues = mutableListOf<PollutedClue?>()
- val missions = missionMapper.selectByExample(Example(Mission::class.java).apply {
- createCriteria().andBetween("startTime", startTime, endTime)
- .andEqualTo("provinceCode", areaVo.provinceCode)
- .andEqualTo("cityCode", areaVo.cityCode)
- .andEqualTo("districtCode", areaVo.districtCode)
- .andIsNotNull("kilometres")
- .andNotEqualTo("kilometres", 0)
- }).onEach {
+ val missions = missionRep.findByAreaAndTime(areaVo, startTime, endTime).onEach {
it ?: return@onEach
- val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime).filterIsInstance<PollutedClue?>()
+ val clue = sourceTraceRep.fetchList(it.deviceCode, it.startTime, it.endTime, MsgType.PolClue) as List<PollutedClue?>
clues.addAll(clue)
}
val summary = MissionSummary().execute(startTime, endTime, missions, clues)
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
+ }
+
+ /**
+ * 鐢熸垚璧拌埅浠诲姟娓呭崟锛堟寜鏃堕棿鍜屽尯鍩熺瓫閫夛級
+ * 鏍规嵁鏃堕棿鑼冨洿鍜岃鏀垮尯鍒掓煡璇㈣蛋鑸换鍔★紝骞跺叧鑱旀薄鏌撶嚎绱㈡暟鎹敓鎴愪换鍔″垪琛�
+ * @param startTime 鏌ヨ璧峰鏃堕棿锛堝寘鍚級
+ * @param endTime 鏌ヨ缁撴潫鏃堕棿锛堝寘鍚級
+ * @param areaVo 鍖哄煙鍙傛暟锛屽寘鍚渷銆佸競銆佸尯缂栫爜
+ * @return 璧拌埅浠诲姟淇℃伅鍒楄〃锛屾瘡涓厓绱犲寘鍚换鍔″熀鏈俊鎭拰鍏宠仈鐨勬薄鏌撶嚎绱�
+ * @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)
+ 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 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")
+ }
+
+ /**
+ * 鐢熸垚璧拌埅浠诲姟璇︽儏锛堢洿鎺ュ鐞嗕换鍔℃暟鎹級
+ * 鎺ユ敹宸插叧鑱旂殑浠诲姟-姹℃煋绾跨储-瀹炴椂鏁版嵁涓夊厓缁勶紝鐢熸垚璇︾粏浠诲姟鎶ュ憡
+ * @param keyScenes 鍏抽敭鍦烘櫙鍒楄〃锛岀敤浜庡垎鏋愯蛋鑸槸鍚︾粡杩囪鍖哄煙
+ * @param missionCluesData 浠诲姟鏁版嵁涓夊厓缁勫垪琛紝Triple鍒嗗埆涓轰换鍔″璞°�佹薄鏌撶嚎绱㈠垪琛ㄣ�佸疄鏃舵暟鎹垪琛�
+ * @return 鏍囧噯鍖栫殑浠诲姟璇︽儏鍒楄〃锛屽寘鍚畬鏁寸殑浠诲姟灞炴�с�佹薄鏌撳垎鏋愬拰鐩戞祴鏁版嵁缁熻
+ * @see MissionInventory.generateMissionDetail 璇︽儏鐢熸垚鏍稿績閫昏緫
+ */
+ 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, granularity)
+ }
+ }
+
+ override fun generateClueByRiskArea(
+ startTime: Date,
+ endTime: Date,
+ areaVo: AreaVo,
+ removeOtherDistrict: Boolean,
+ removeNoPollutedSource: Boolean,
+ ): 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?>
+ 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() }
+ }
+// 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,
+ SceneType.TYPE20.value,
+ SceneType.TYPE21.value
+ )
+ )
+ return generateClueByRiskArea(keyScenes, pollutedClues)
+ }
+
+ override fun generateClueByRiskArea(
+ keyScenes: List<SceneInfo?>,
+ pollutedClues: List<PollutedClue?>,
+ ): List<MissionRiskArea.ClueByArea> {
+ 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