feat: 为 PointMonitorInfo 添加旧值追踪和值变化检测
This commit is contained in:
parent
8127d04855
commit
562a2d566b
15
src/event.rs
15
src/event.rs
|
|
@ -131,6 +131,18 @@ impl EventManager {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(point_id) = point_id {
|
if let Some(point_id) = point_id {
|
||||||
|
// 从缓存中读取旧值
|
||||||
|
let monitor_data = connection_manager.get_point_monitor_data_read_guard().await;
|
||||||
|
let old_monitor_info = monitor_data.get(&point_id);
|
||||||
|
|
||||||
|
let (old_value, old_timestamp, value_changed) = if let Some(old_info) = old_monitor_info {
|
||||||
|
let changed = old_info.value != payload.value ||
|
||||||
|
old_info.timestamp != payload.timestamp;
|
||||||
|
(old_info.value.clone(), old_info.timestamp, changed)
|
||||||
|
} else {
|
||||||
|
(None, None, false)
|
||||||
|
};
|
||||||
|
|
||||||
let monitor = crate::telemetry::PointMonitorInfo {
|
let monitor = crate::telemetry::PointMonitorInfo {
|
||||||
protocol: payload.protocol.clone(),
|
protocol: payload.protocol.clone(),
|
||||||
source_id,
|
source_id,
|
||||||
|
|
@ -142,6 +154,9 @@ impl EventManager {
|
||||||
value: payload.value.clone(),
|
value: payload.value.clone(),
|
||||||
value_type: payload.value_type.clone(),
|
value_type: payload.value_type.clone(),
|
||||||
value_text: payload.value_text.clone(),
|
value_text: payload.value_text.clone(),
|
||||||
|
old_value,
|
||||||
|
old_timestamp,
|
||||||
|
value_changed,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = connection_manager.update_point_monitor_data(monitor.clone()).await {
|
if let Err(e) = connection_manager.update_point_monitor_data(monitor.clone()).await {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ impl PointQuality {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(tag = "kind", content = "value", rename_all = "snake_case")]
|
#[serde(tag = "kind", content = "value", rename_all = "snake_case")]
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub enum DataValue {
|
pub enum DataValue {
|
||||||
Null,
|
Null,
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
|
|
@ -85,6 +86,9 @@ pub struct PointMonitorInfo {
|
||||||
pub value: Option<DataValue>,
|
pub value: Option<DataValue>,
|
||||||
pub value_type: Option<ValueType>,
|
pub value_type: Option<ValueType>,
|
||||||
pub value_text: Option<String>,
|
pub value_text: Option<String>,
|
||||||
|
pub old_value: Option<DataValue>,
|
||||||
|
pub old_timestamp: Option<DateTime<Utc>>,
|
||||||
|
pub value_changed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PointMonitorInfo {
|
impl PointMonitorInfo {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue