feiyu02
昨天 e923f06d572c9a0e3b1eb2c54471af02c9d95bcf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.flightfeather.uav.biz.sourcetrace.model
 
import com.flightfeather.uav.biz.FactorFilter
import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionTag
import com.flightfeather.uav.biz.dataanalysis.model.ExceptionType
import com.flightfeather.uav.biz.sourcetrace.config.RTExcWindLevelConfig
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 com.flightfeather.uav.domain.repository.SceneInfoRep
import com.flightfeather.uav.socket.sender.MsgType
 
/**
 * 污染线索
 * 通过污染数据[PollutedData],污染区域[PollutedArea],污染来源[PollutedSource],形成一条污染溯源线索
 * @date 2025/5/27
 * @author feiyu02
 */
class PollutedClue() : BaseExceptionResult() {
 
    constructor(
        exceptions: List<Pair<FactorFilter.SelectedFactor, ExceptionTag>>,
        eType: ExceptionType,
        config: RTExcWindLevelConfig,
        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?,
    ) : this() {
        if (exceptions.isEmpty() || exceptions[0].second.exceptionData.isEmpty()) return
        deviceCode = exceptions[0].second.startData?.deviceCode
        var startData: BaseRealTimeData? = null
        var endData: BaseRealTimeData? = null
        var exceptionData = mutableListOf<BaseRealTimeData>()
        var historyData = mutableListOf<BaseRealTimeData>()
        exceptions.forEach { e ->
            // 将采样时间最早的作为开始数据
            if (startData == null) {
                startData = e.second.startData
            } else {
                if (e.second.startData?.dataTime!! < startData!!.dataTime) {
                    startData = e.second.startData
                }
            }
 
            // 将采样时间最晚的作为结束数据
            if (endData == null) {
                endData = e.second.endData
            } else {
                if (e.second.endData?.dataTime!! > endData!!.dataTime) {
                    endData = e.second.endData
                }
            }
 
            // 将所有异常数据去重合并
            if (exceptionData.isEmpty()) {
                exceptionData = e.second.exceptionData
            } else {
                e.second.exceptionData.forEach {
                    if (exceptionData.find { d -> d.dataTime == it.dataTime } == null) {
                        exceptionData.add(it)
                    }
                }
            }
 
            // 将所有历史数据去重合并
            if (historyData.isEmpty()) {
                historyData = e.second.historyData
            } else {
                e.second.historyData.forEach {
                    if (historyData.find { d -> d.dataTime == it.dataTime } == null) {
                        historyData.add(it)
                    }
                }
            }
        }
        // 按照采样时间升序排列
        exceptionData.sortBy { it.dataTime }
        historyData.sortBy { it.dataTime }
 
        // 获取去重后的监测因子类型
        val factorList = exceptions.map { it.first }.distinct()
        pollutedData = PollutedData(
            startData!!, endData, factorList, exceptionData, historyData, eType, windLevelCondition
        )
        pollutedArea = PollutedArea(historyData, exceptionData, config, windLevelCondition)
 
    }
 
    /**
     * @see [MsgType]
     */
    var msgType: Int? = null
 
    var deviceCode: String? = null
 
    var pollutedData: PollutedData? = null
 
    var pollutedArea: PollutedArea? = null
 
    var pollutedSource: PollutedSource? = null
 
    /**
     * 查找系统内部溯源范围内的污染企业
     */
    fun searchScenes(sceneInfoRep: SceneInfoRep) {
        if (pollutedArea == null || pollutedData == null) return
        pollutedSource = PollutedSource().also {
            it.searchScenes(pollutedArea!!, sceneInfoRep, pollutedData!!)
        }
    }
}