feat(event): add business control events (fault, comm, auto, state change)

This commit is contained in:
caoqianming 2026-03-24 14:46:25 +08:00
parent 684ca9da85
commit 68e724898c
1 changed files with 70 additions and 0 deletions

View File

@ -34,6 +34,13 @@ pub enum AppEvent {
unit_id: Option<Uuid>, unit_id: Option<Uuid>,
point_id: Uuid, point_id: Uuid,
}, },
AutoControlStarted { unit_id: Uuid },
AutoControlStopped { unit_id: Uuid },
FaultLocked { unit_id: Uuid, equipment_id: Uuid },
FaultAcked { unit_id: Uuid },
CommLocked { unit_id: Uuid },
CommRecovered { unit_id: Uuid },
UnitStateChanged { unit_id: Uuid, from_state: String, to_state: String },
PointNewValue(crate::telemetry::PointNewValue), PointNewValue(crate::telemetry::PointNewValue),
} }
@ -219,6 +226,27 @@ async fn handle_control_event(
point_id point_id
); );
} }
AppEvent::AutoControlStarted { unit_id } => {
tracing::info!("Auto control started for unit {}", unit_id);
}
AppEvent::AutoControlStopped { unit_id } => {
tracing::info!("Auto control stopped for unit {}", unit_id);
}
AppEvent::FaultLocked { unit_id, equipment_id } => {
tracing::warn!("Fault locked: unit={}, equipment={}", unit_id, equipment_id);
}
AppEvent::FaultAcked { unit_id } => {
tracing::info!("Fault acked for unit {}", unit_id);
}
AppEvent::CommLocked { unit_id } => {
tracing::warn!("Comm locked for unit {}", unit_id);
}
AppEvent::CommRecovered { unit_id } => {
tracing::info!("Comm recovered for unit {}", unit_id);
}
AppEvent::UnitStateChanged { unit_id, from_state, to_state } => {
tracing::info!("Unit {} state: {} → {}", unit_id, from_state, to_state);
}
AppEvent::PointNewValue(_) => { AppEvent::PointNewValue(_) => {
tracing::warn!("PointNewValue routed to control worker unexpectedly"); tracing::warn!("PointNewValue routed to control worker unexpectedly");
} }
@ -310,6 +338,48 @@ async fn persist_event_if_needed(
"point_id": point_id "point_id": point_id
}), }),
)), )),
AppEvent::AutoControlStarted { unit_id } => Some((
"unit.auto_control_started", "info",
Some(*unit_id), None, None,
format!("Auto control started for unit {}", unit_id),
serde_json::json!({ "unit_id": unit_id }),
)),
AppEvent::AutoControlStopped { unit_id } => Some((
"unit.auto_control_stopped", "info",
Some(*unit_id), None, None,
format!("Auto control stopped for unit {}", unit_id),
serde_json::json!({ "unit_id": unit_id }),
)),
AppEvent::FaultLocked { unit_id, equipment_id } => Some((
"unit.fault_locked", "error",
Some(*unit_id), Some(*equipment_id), None,
format!("Unit {} fault locked by equipment {}", unit_id, equipment_id),
serde_json::json!({ "unit_id": unit_id, "equipment_id": equipment_id }),
)),
AppEvent::FaultAcked { unit_id } => Some((
"unit.fault_acked", "info",
Some(*unit_id), None, None,
format!("Unit {} fault acknowledged", unit_id),
serde_json::json!({ "unit_id": unit_id }),
)),
AppEvent::CommLocked { unit_id } => Some((
"unit.comm_locked", "warn",
Some(*unit_id), None, None,
format!("Unit {} communication locked", unit_id),
serde_json::json!({ "unit_id": unit_id }),
)),
AppEvent::CommRecovered { unit_id } => Some((
"unit.comm_recovered", "info",
Some(*unit_id), None, None,
format!("Unit {} communication recovered", unit_id),
serde_json::json!({ "unit_id": unit_id }),
)),
AppEvent::UnitStateChanged { unit_id, from_state, to_state } => Some((
"unit.state_changed", "info",
Some(*unit_id), None, None,
format!("Unit {} state: {}{}", unit_id, from_state, to_state),
serde_json::json!({ "unit_id": unit_id, "from": from_state, "to": to_state }),
)),
AppEvent::PointNewValue(_) => None, AppEvent::PointNewValue(_) => None,
}; };