feiyu02
2025-08-14 b10c22af595bd995e56946bff63b8f2f984b13e8
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedSummary.kt
@@ -2,6 +2,7 @@
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
@@ -12,7 +13,7 @@
import java.util.TimerTask
// 异常数据生成回调类
typealias NewPolluteSummaryCallback = (ex: PollutedSummary.AnalysisResult) -> Unit
typealias NewPolluteSummaryCallback = (ex: AnalysisResult) -> Unit
/**
 * 污染情况汇总
@@ -27,17 +28,6 @@
     * 5. 污染源的被扫描次数
     * 每一刻钟对历史线索进行统计,提出会商建议(离污染源较远、污染源数量、出现次数)、走航路线调整建议(离污染源较近、走航轨迹未接近溯源场景)
     */
    /**
     * 分析结果
     */
    inner class AnalysisResult{
        // 按照被扫描次数降序排列的污染源列表
        var sortedSceneList: List<Pair<SceneInfo?, Int>>? = null
        var time: Date? = null
        var advice:String?= null
        var direction: AMapService.AMapDirection? = null
    }
    /**
     * 实时统计
@@ -60,7 +50,7 @@
    private var analysisTimer: Timer? = null
    // 定时污染分析任务
    private var lastAnalysisOnTimeTask:TimerTask? = null
    private var lastAnalysisOnTimeTask: TimerTask? = null
    // 定时污染分析任务运行状态
    private var analysisTaskIsRunning = false
@@ -74,9 +64,16 @@
    // 新增一条污染线索
    fun addClue(pollutedClue: PollutedClue) {
        clueList.add(pollutedClue)
        // 当溯源未找到风险源时,此次溯源信息不作为线索统计项
        if (pollutedClue.pollutedSource?.sceneList?.isNotEmpty() == true)
            clueList.add(pollutedClue)
//        realTimeSummary()
        analysisOnClueCount()
    }
    // 新增一条污染线索
    fun addClueList(pollutedClues: List<PollutedClue>) {
        pollutedClues.forEach { addClue(it) }
    }
    // 刷新当前最新的走航监测数据
@@ -128,8 +125,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 {
@@ -145,11 +142,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 {
@@ -157,37 +155,44 @@
                }
            }
        }
        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 = clueList.first().pollutedData?.startTime
            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}起的${clueList.size}条最新污染线索,污染源[${closetScene?.first?.name}]被多次溯源,具有较高污染风险,现提供新的走航推荐路线,可经过该污染源。"
            // 走航路线调整建议
            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) {
                closetScene.first?.longitude!! > BigDecimal.ZERO && closetScene.first?.latitude!! > BigDecimal.ZERO
            ) {
                val origin = MapUtil.wgs84ToGcj02(lastP.longitude!!.toDouble() to lastP.latitude!!.toDouble())
                val destination = closetScene.first!!.longitude.toDouble() to closetScene.first!!.latitude.toDouble()
                result.direction = AMapService.directionDriving(origin, destination)
                if (config.isSearchAddress) {
                    // 建议的走航路线
                    result.direction = AMapService.directionDriving(origin, destination)
                }
            }
            // 线索分析完成后,移动至历史线索列表
            historyClueList.addAll(clueList)
            clueList.clear()
            realTimeDataList.clear()
            callback(result)
        }
        result.time = realTimeDataList.last().dataTime
        // 线索分析完成后,移动至历史线索列表
        historyClueList.addAll(clueList)
        clueList.clear()
        realTimeDataList.clear()
        callback(result)
//        TODO()
    }