fix: 统一所有服务时间为北京时间 + 处理/忽略时计算告警时长

- notify_dispatch: _mark_false_alarm 使用 beijing_now() + 计算 duration_ms
- alarm_event_service: handle_alarm 处理时自动计算 duration_ms 和 last_frame_time
- notification_service: datetime.utcnow() 替换为 beijing_now()
- device_service: datetime.now(timezone.utc) 替换为 beijing_now()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 16:27:30 +08:00
parent 1585abf843
commit 766ee6a69a
4 changed files with 37 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ from typing import Dict, Any, List, Set
from fastapi import WebSocket
from app.utils.logger import logger
from app.utils.timezone import beijing_now
class ConnectionManager:
@@ -80,7 +81,7 @@ class NotificationService:
message = {
"event": "new_alert",
"data": alert_data,
"timestamp": datetime.utcnow().isoformat(),
"timestamp": beijing_now().isoformat(),
}
await self._manager.broadcast(message)
logger.debug(f"已广播新告警通知: {alert_data.get('alert_no', 'N/A')}")
@@ -90,7 +91,7 @@ class NotificationService:
message = {
"event": "alert_updated",
"data": alert_data,
"timestamp": datetime.utcnow().isoformat(),
"timestamp": beijing_now().isoformat(),
}
await self._manager.broadcast(message)
@@ -99,7 +100,7 @@ class NotificationService:
message = {
"event": "device_status",
"data": device_data,
"timestamp": datetime.utcnow().isoformat(),
"timestamp": beijing_now().isoformat(),
}
await self._manager.broadcast(message)
@@ -108,7 +109,7 @@ class NotificationService:
message = {
"event": f"work_order_{event_type}",
"data": order_data,
"timestamp": datetime.utcnow().isoformat(),
"timestamp": beijing_now().isoformat(),
}
await self._manager.broadcast(message)
@@ -121,7 +122,7 @@ class NotificationService:
message = {
"event": event,
"data": data,
"timestamp": datetime.utcnow().isoformat(),
"timestamp": beijing_now().isoformat(),
}
async def _broadcast():