feiyu02
2025-07-04 9c797fa0d704ef8ffb65cd1716b8eb694b4c46c3
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt
@@ -1,14 +1,19 @@
package com.flightfeather.uav.biz.sourcetrace.model
import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig
import com.flightfeather.uav.common.net.AMapService
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.common.utils.MapUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.entity.SceneInfo
import java.math.BigDecimal
import java.time.LocalDateTime
import java.util.Date
import java.util.Timer
import java.util.TimerTask
// 异常数据生成回调类
typealias NewPolluteSummaryCallback = (ex: PollutedSummary.AnalysisResult) -> Unit
typealias NewPolluteSummaryCallback = (ex: AnalysisResult) -> Unit
/**
 * 污染情况汇总
@@ -23,14 +28,6 @@
     * 5. 污染源的被扫描次数
     * 每一刻钟对历史线索进行统计,提出会商建议(离污染源较远、污染源数量、出现次数)、走航路线调整建议(离污染源较近、走航轨迹未接近溯源场景)
     */
    /**
     * 分析结果
     */
    inner class AnalysisResult{
        // 按照被扫描次数降序排列的污染源列表
        var sortedSceneList: List<Pair<SceneInfo?, Int>>? = null
    }
    /**
     * 实时统计
@@ -53,7 +50,7 @@
    private var analysisTimer: Timer? = null
    // 定时污染分析任务
    private var lastAnalysisOnTimeTask:TimerTask? = null
    private var lastAnalysisOnTimeTask: TimerTask? = null
    // 定时污染分析任务运行状态
    private var analysisTaskIsRunning = false
@@ -121,8 +118,8 @@
        val statistic = AnalysisStatistic()
        // 共有多少相关污染源,哪些污染源被扫描次数较多
        val sceneMap = mutableMapOf<String?, Pair<SceneInfo?, Int>>()
        clueList.forEach {c->
            c.pollutedSource?.sceneList?.forEach { s->
        clueList.forEach { c ->
            c.pollutedSource?.sceneList?.forEach { s ->
                if (!sceneMap.containsKey(s?.guid)) {
                    sceneMap[s?.guid] = s to 1
                } else {
@@ -138,11 +135,12 @@
     * 线索分析
     */
    private fun analysis() {
        val result = AnalysisResult()
        if (clueList.isEmpty()) return
        val result = AnalysisResult().apply { deviceCode = clueList.first().deviceCode }
        // 共有多少相关污染源,哪些污染源被扫描次数较多
        val sceneMap = mutableMapOf<String?, Pair<SceneInfo?, Int>>()
        clueList.forEach {c->
            c.pollutedSource?.sceneList?.forEach { s->
        clueList.forEach { c ->
            c.pollutedSource?.sceneList?.forEach { s ->
                if (!sceneMap.containsKey(s?.guid)) {
                    sceneMap[s?.guid] = s to 1
                } else {
@@ -150,18 +148,41 @@
                }
            }
        }
        val res = sceneMap.entries.sortedBy { it.value.second }
        val res = sceneMap.entries.sortedByDescending { it.value.second }
        result.sortedSceneList = res.map { it.value }
        // 当前的走航数据的定位和污染源距离是否是逐渐接近,若走航远离了主要污染源,提示用户调整走航路线
        if (!result.sortedSceneList.isNullOrEmpty()) {
            val sT = DateUtil.instance.dateToString(clueList.first().pollutedData?.startTime, DateUtil.DateStyle.HH_MM_SS)
            val eT = DateUtil.instance.dateToString(clueList.last().pollutedData?.endTime, DateUtil.DateStyle.HH_MM_SS)
            val closetScene = result.sortedSceneList?.first()
            // 走航路线调整建议
            result.advice =
                "根据${sT}至${eT}的${clueList.size}条溯源切片,风险源【" +
                        "${closetScene?.first?.name}】被多次溯源,具有较高污染风险,现提供新的走航推荐路线,可经过该污染源。"
            val lastP = realTimeDataList.last()
            // 建议对应的数据采样时间
            result.time = lastP.dataTime
            if (lastP.longitude != null && lastP.latitude != null &&
                lastP.longitude!! > BigDecimal.ZERO && lastP.latitude!! > BigDecimal.ZERO
                && closetScene?.first?.longitude != null && closetScene.first?.latitude != null &&
                closetScene.first?.longitude!! > BigDecimal.ZERO && closetScene.first?.latitude!! > BigDecimal.ZERO
            ) {
        // 线索分析完成后,移动至历史线索列表
        historyClueList.addAll(clueList)
        clueList.clear()
        realTimeDataList.clear()
                val origin = MapUtil.wgs84ToGcj02(lastP.longitude!!.toDouble() to lastP.latitude!!.toDouble())
                val destination = closetScene.first!!.longitude.toDouble() to closetScene.first!!.latitude.toDouble()
        callback(result)
                // 建议的走航路线
                result.direction = AMapService.directionDriving(origin, destination)
            }
            // 线索分析完成后,移动至历史线索列表
            historyClueList.addAll(clueList)
            clueList.clear()
            realTimeDataList.clear()
            callback(result)
        }
//        TODO()
    }