feat(scada): add calibrated monitoring and incident recovery

This commit is contained in:
2026-11-07 19:44:58 +08:00
parent 26fa5d1909
commit ff8aba4964
109 changed files with 9165 additions and 629 deletions
+4
View File
@@ -161,9 +161,13 @@ class UpdateWorkOrder(Model):
clear_scenario_code: StrictBool = False
feedback_requirements: list[Text] | None = None
progress_note: Text | None = None
occurred_at: WireDateTime | None = None
@model_validator(mode="after")
def valid_update(self):
if self.occurred_at is not None:
if self.occurred_at.tzinfo is None or not self.progress_note:
raise ValueError("occurred_at requires a timezone and field feedback")
changed = set(self.model_fields_set) - {"request_id", "expected_revision"}
if not changed:
raise ValueError("at least one work order field must be updated")
+5 -5
View File
@@ -362,7 +362,7 @@ class PostgresStore:
with self.connection(readonly=True) as conn:
self._available(conn, who)
return self._managed_document(conn, who, "work_orders", "work_order_id", work_order_id,
"WORK_ORDER_NOT_FOUND", "测试工单不存在")
"WORK_ORDER_NOT_FOUND", "工单不存在")
def create_work_order(self, who: Identity, command: CreateWorkOrder) -> dict[str, Any]:
def write(conn, _):
@@ -382,11 +382,11 @@ class PostgresStore:
command: UpdateWorkOrder) -> dict[str, Any]:
def write(conn, _):
document = self._managed_document(conn, who, "work_orders", "work_order_id", work_order_id,
"WORK_ORDER_NOT_FOUND", "测试工单不存在")
"WORK_ORDER_NOT_FOUND", "工单不存在")
ensure(document["revision"] == command.expected_revision, "REVISION_CONFLICT", "工单版本已变化,请重新读取", 409)
changes = command.model_dump(mode="json", exclude_unset=True,
exclude={"request_id", "expected_revision", "clear_assignee", "clear_scheduled_at",
"clear_location", "clear_scenario_code", "progress_note"})
"clear_location", "clear_scenario_code", "progress_note", "occurred_at"})
if command.clear_assignee:
changes["assignee"] = None
if command.clear_scheduled_at:
@@ -409,7 +409,7 @@ class PostgresStore:
) + "。", "updated"
else:
title, detail, kind = "工单信息确认", "工单信息已确认,未记录新的现场进展。", "updated"
document["activity"].append({"sequence": revision, "occurred_at": now,
document["activity"].append({"sequence": revision, "occurred_at": command.occurred_at.isoformat() if command.occurred_at else now,
"actor": who.user_id, "kind": kind,
"title": title, "detail": detail})
document.update(revision=revision, updated_at=now,
@@ -421,7 +421,7 @@ class PostgresStore:
command: DeleteResource) -> dict[str, Any]:
def write(conn, _):
document = self._managed_document(conn, who, "work_orders", "work_order_id", work_order_id,
"WORK_ORDER_NOT_FOUND", "测试工单不存在")
"WORK_ORDER_NOT_FOUND", "工单不存在")
ensure(document["revision"] == command.expected_revision, "REVISION_CONFLICT", "工单版本已变化,请重新读取", 409)
revision = document["revision"] + 1
deleted_at = datetime.now(timezone.utc).isoformat()