feiyu02
2025-08-14 dac47617b37ccfb834cd73ce0ee725e1101de214
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
package com.flightfeather.uav.biz.dataanalysis.model
 
import com.flightfeather.uav.biz.dataanalysis.BaseExceptionResult
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import org.apache.commons.lang3.SerializationUtils
import org.springframework.beans.BeanUtils
import java.io.Serializable
 
/**
 * 异常数据标签
 * @date 2025/5/13
 * @author feiyu02
 */
open class ExceptionTag : Serializable {
    companion object {
        const val MAX_HISTORY = 10
    }
 
    // 起始数据下标
    var sIndex = 0
 
    // 起始数据对象
    var startData: BaseRealTimeData? = null
 
    // 末尾数据下标
    var eIndex = -1
 
    // 末尾数据对象
    var endData: BaseRealTimeData? = null
 
    // 异常数据段
    var exceptionData = mutableListOf<BaseRealTimeData>()
 
    // 近段时间内的历史数据
    var historyData = mutableListOf<BaseRealTimeData>()
 
    // 是否存在异常
    var exceptionExisted = false
 
    // 异常结果是否创建
    var exceptionCreated = false
 
    var exceptionResult = mutableListOf<BaseExceptionResult>()
 
    fun addHistoryData(data: BaseRealTimeData) {
        historyData.add(data)
        if (exceptionData.isNotEmpty()) {
            // 保证历史数据包含所有异常数据(异常数据可能不连续),并且在首个异常数据之前最多再保存10个数据
            val i = historyData.indexOf(exceptionData.first())
            if (i > MAX_HISTORY) {
                historyData = historyData.subList(i - MAX_HISTORY, historyData.size).toMutableList()
            }
        } else {
            if (historyData.size > MAX_HISTORY) {
                historyData = historyData.subList(historyData.size - MAX_HISTORY, historyData.size).toMutableList()
            }
        }
    }
 
    fun addExceptionData(data: BaseRealTimeData) {
        exceptionExisted = true
        exceptionData.add(data)
    }
 
    fun refreshWithNoException(data: BaseRealTimeData) {
        sIndex = eIndex
        startData = data
    }
 
    fun refreshWithNextException(data: BaseRealTimeData) {
        refreshWithNoException(data)
        exceptionData.clear()
        exceptionExisted = false
        exceptionCreated = false
    }
 
    fun clone(): ExceptionTag {
        val exceptionTag = SerializationUtils.clone(this)
//        val exceptionTag = ExceptionTag()
//        BeanUtils.copyProperties(this, exceptionTag)
//        exceptionTag.apply {
//            this.sIndex = this@ExceptionTag.sIndex
//            this.startData = this@ExceptionTag.startData
//            this.eIndex = this@ExceptionTag.eIndex
//            this.endData = this@ExceptionTag.endData
//            this.exceptionData = this@ExceptionTag.exceptionData
//            this.historyData = this@ExceptionTag.historyData
//            this.exceptionExisted = this@ExceptionTag.exceptionExisted
//            this.exceptionCreated = this@ExceptionTag.exceptionCreated
//            this.exceptionResult = this@ExceptionTag.exceptionResult
//        }
        return exceptionTag
    }
}