riku
2025-08-25 2de612e9b260df2e76d4dd620ca739aa3b6e8c57
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/SourceTraceController.kt
@@ -28,7 +28,12 @@
     * 每一刻钟对历史线索进行统计,提出会商建议(离污染源较远、污染源数量、出现次数)、走航路线调整建议(离污染源较近、走航轨迹未接近溯源场景)
     */
    constructor(sceneInfoRep: SceneInfoRep, sourceTraceRep: SourceTraceRep, factorFilter: FactorFilter?) {
    constructor(
        sceneInfoRep: SceneInfoRep,
        sourceTraceRep: SourceTraceRep,
        factorFilter: FactorFilter?,
        isSearchAddress: Boolean,
    ) {
        this.sceneInfoRep = sceneInfoRep
        this.sourceTraceRep = sourceTraceRep
        this.config = if (factorFilter != null) {
@@ -53,16 +58,21 @@
                    .create()
            )
        }
        this.config.isSearchAddress = isSearchAddress
        pollutedSummary = PollutedSummary(config) { summaryCallback(it) }
        newTask()
    }
    constructor(sceneInfoRep: SceneInfoRep, sourceTraceRep: SourceTraceRep) : this(sceneInfoRep, sourceTraceRep, null)
    constructor(sceneInfoRep: SceneInfoRep, sourceTraceRep: SourceTraceRep, isSearchAddress: Boolean = true)
            : this(sceneInfoRep, sourceTraceRep, null, isSearchAddress)
    private val pollutedSummary: PollutedSummary
    private val sceneInfoRep: SceneInfoRep
    private val sourceTraceRep: SourceTraceRep
    private val config: RTExcWindLevelConfig
    private val timer = Timer()
    private var timerTask: TimerTask? = null
    private val taskList = mutableListOf<BaseExceptionAnalysis<RTExcWindLevelConfig, PollutedClue>>()
@@ -74,6 +84,7 @@
    private fun newTask() {
        taskList.apply {
//            add(RTExcSlideAverage(config) { dataChangeCallback(it) }.also { it.init() })
            add(RTExcWindLevel1(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcWindLevel1_1(config) { exceptionCallback(it) }.also { it.init() })
            add(RTExcWindLevel4(config) { exceptionCallback(it) }.also { it.init() })
@@ -92,23 +103,37 @@
     * 计算新的一条实时走航数据
     */
    fun addOneData(data: BaseRealTimeData) {
//        println("====================>")
        // 计算异常
        taskList.forEach { it.onNextData(data) }
        pollutedSummary.refreshLatestMonitorData(data)
        // 限定时间内没有新数据传入,则结束当前的计算
        dealOnTimeout()
    }
    fun addDataList(dataList: List<BaseRealTimeData>) {
        // 计算异常
        dataList.forEach { data ->
            taskList.forEach { it.onNextData(data) }
            pollutedSummary.refreshLatestMonitorData(data)
        }
        // 限定时间内没有新数据传入,则结束当前的计算
        dealOnTimeout()
    }
    /**
     * 超时处理,较长时间没有新数据进入,进行初始化操作
     */
    private fun dealOnTimeout() {
        val timer = Timer(true)
        timer.schedule(object : TimerTask() {
//        val timer = Timer()
        timerTask?.cancel()
        timer.purge()
        timerTask = object : TimerTask() {
            override fun run() {
                TODO("Not yet implemented")
                initTask()
            }
        }, 60 * 1000)
        timer.cancel()
        }
        timer.schedule(timerTask, 2 * 60 * 60 * 1000)
    }
    // 数据突变异常回调