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
|
}
|
}
|