feiyu02
2025-08-14 dac47617b37ccfb834cd73ce0ee725e1101de214
src/main/kotlin/com/flightfeather/uav/biz/sourcetrace/model/PollutedClue.kt
@@ -18,39 +18,87 @@
 * @date 2025/5/27
 * @author feiyu02
 */
class PollutedClue() : BaseExceptionResult(){
class PollutedClue() : BaseExceptionResult() {
//    constructor(
//        start: BaseRealTimeData,
//        end: BaseRealTimeData?,
//        factor: FactorFilter.SelectedFactor,
//        exceptionData: List<BaseRealTimeData>,
//        eType: ExceptionType,
//        config: RTExcWindLevelConfig,
//        tag: ExceptionTag, factor: FactorFilter.SelectedFactor, eType: ExceptionType, config: RTExcWindLevelConfig,
//        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?,
//    ) : this() {
//        if (exceptionData.isEmpty()) return
//        pollutedData = PollutedData(start, end, factor, exceptionData, eType, windLevelCondition)
//        pollutedArea = PollutedArea(exceptionData, config, windLevelCondition)
//        if (tag.exceptionData.isEmpty()) return
//        deviceCode = tag.startData?.deviceCode
//        pollutedData = PollutedData(
//            tag.startData!!, tag.endData, factor, tag.exceptionData, tag.historyData, eType, windLevelCondition
//        )
//        pollutedArea = PollutedArea(tag.historyData, tag.exceptionData, config, windLevelCondition)
//    }
    constructor(
        tag: ExceptionTag, factor: FactorFilter.SelectedFactor, eType: ExceptionType, config: RTExcWindLevelConfig,
        exceptions: List<Pair<FactorFilter.SelectedFactor, ExceptionTag>>,
        eType: ExceptionType,
        config: RTExcWindLevelConfig,
        windLevelCondition: RTExcWindLevelConfig.WindLevelCondition?,
    ) : this()
//            this(
//        tag.startData!!, tag.endData, factor, tag.exceptionData, eType, config,
//        windLevelCondition
//    )
    {
        if (tag.exceptionData.isEmpty()) return
        deviceCode = tag.startData?.deviceCode
    ) : 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(
            tag.startData!!, tag.endData, factor, tag.exceptionData, tag.historyData, eType, windLevelCondition
            startData!!, endData, factorList, exceptionData, historyData, eType, windLevelCondition
        )
        pollutedArea = PollutedArea(tag.historyData, tag.exceptionData, config, windLevelCondition)
        pollutedArea = PollutedArea(historyData, exceptionData, config, windLevelCondition)
    }
    /**
     * 6. 展示数据变化情况,上升速率等等
     */