Riku
2025-07-13 37d47c6a7ab0f454b948b68c987146b261117993
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/SourceTraceController.kt
@@ -2,14 +2,14 @@
import com.flightfeather.uav.biz.FactorFilter
import com.flightfeather.uav.biz.dataanalysis.BaseExceptionAnalysis
import com.flightfeather.uav.biz.sourcetrace.RealTimeAnalysisConfig
import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig
import com.flightfeather.uav.biz.sourcetrace.exceptiontype.*
import com.flightfeather.uav.biz.sourcetrace.model.AnalysisResult
import com.flightfeather.uav.biz.sourcetrace.model.PollutedClue
import com.flightfeather.uav.biz.sourcetrace.model.PollutedSummary
import com.flightfeather.uav.common.utils.GsonUtils
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.domain.repository.SceneInfoRep
import com.flightfeather.uav.domain.repository.SourceTraceRep
import com.flightfeather.uav.socket.eunm.FactorType
import com.flightfeather.uav.socket.sender.MsgType
import com.flightfeather.uav.socket.sender.UnderwayWebSocketSender
@@ -28,33 +28,38 @@
     * 每一刻钟对历史线索进行统计,提出会商建议(离污染源较远、污染源数量、出现次数)、走航路线调整建议(离污染源较近、走航轨迹未接近溯源场景)
     */
    constructor(sceneInfoRep: SceneInfoRep, factorFilter: FactorFilter?) {
    constructor(sceneInfoRep: SceneInfoRep, sourceTraceRep: SourceTraceRep, factorFilter: FactorFilter?) {
        this.sceneInfoRep = sceneInfoRep
        this.config = if (factorFilter != null)
            RTExcWindLevelConfig(factorFilter)
        else
        this.sourceTraceRep = sourceTraceRep
        this.config = if (factorFilter != null) {
            RTExcWindLevelConfig(factorFilter, emptyList())
        } else {
            RTExcWindLevelConfig(
                FactorFilter.builder()
//                    .withMain(FactorType.NO2)
//                    .withMain(FactorType.CO)
                    .withMain(FactorType.NO2)
                    .withMain(FactorType.CO)
//                    .withMain(FactorType.H2S)
//                    .withMain(FactorType.SO2)
//                    .withMain(FactorType.O3)
                    .withMain(FactorType.O3)
                    .withMain(FactorType.PM25)
                    .withMain(FactorType.PM10)
                    .withMain(FactorType.VOC)
                    .create()
                    .create(),
                listOf(
                    listOf(FactorType.PM25, FactorType.PM10),
                    listOf(FactorType.VOC, FactorType.CO),
                )
            )
        }
        pollutedSummary = PollutedSummary(config) { summaryCallback(it) }
        newTask()
    }
    constructor(sceneInfoRep: SceneInfoRep) : this(sceneInfoRep, null)
    constructor(sceneInfoRep: SceneInfoRep, sourceTraceRep: SourceTraceRep) : this(sceneInfoRep, sourceTraceRep, null)
    private val pollutedSummary: PollutedSummary
    private val sceneInfoRep: SceneInfoRep
    private val sourceTraceRep: SourceTraceRep
    private val config: RTExcWindLevelConfig
    private val taskList = mutableListOf<BaseExceptionAnalysis<RTExcWindLevelConfig, PollutedClue>>()
@@ -71,8 +76,13 @@
            add(RTExcWindLevel1_1(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcWindLevel4(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcWindLevel6(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcChangeRate(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcChangeRate1(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcChangeRate4(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcChangeRate6(config) { exceptionCallback(it) }.also { it.init() })
            add(RTWarnChangeRate(config) { dataChangeCallback(it) }.also { it.init() })
            add(RTWarnChangeRate2(config) { dataChangeCallback(it) }.also { it.init() })
        }
    }
@@ -100,28 +110,38 @@
    }
    // 数据突变异常回调
    private fun exceptionCallback(ex: PollutedClue) {
        // 溯源污染源信息
        ex.searchScenes(sceneInfoRep)
    private fun exceptionCallback(ex: List<PollutedClue>) {
        ex.forEach {
            // 溯源污染源信息
            it.searchScenes(sceneInfoRep)
            it.msgType = MsgType.PolClue.value
        }
        // 广播污染溯源异常结果
        UnderwayWebSocketSender.broadcast(MsgType.PolClue.value, ex)
        sourceTraceRep.insertList(MsgType.PolClue, ex)
        // 记录污染线索
        pollutedSummary.addClue(ex)
        pollutedSummary.addClueList(ex)
    }
    // 数据变化提醒回调
    private fun dataChangeCallback(ex: PollutedClue) {
        // 溯源污染源信息
        ex.searchScenes(sceneInfoRep)
    private fun dataChangeCallback(ex: List<PollutedClue>) {
        ex.forEach {
            // 溯源污染源信息
            it.searchScenes(sceneInfoRep)
            it.msgType = MsgType.DataChange.value
        }
        // 广播数据变化提醒
        UnderwayWebSocketSender.broadcast(MsgType.DataChange.value, ex)
        sourceTraceRep.insertList(MsgType.DataChange, ex)
    }
    private fun summaryCallback(ex: PollutedSummary.AnalysisResult) {
    private fun summaryCallback(ex: AnalysisResult) {
        ex.msgType = MsgType.AnaResult.value
        // 广播污染溯源异常结果
        UnderwayWebSocketSender.broadcast(MsgType.AnaResult.value, ex)
        sourceTraceRep.insert(ex)
    }
}