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

@@ -22,6 +22,7 @@ from app.config import settings
from app.services.vlm_service import get_vlm_service
from app.services.wechat_service import get_wechat_service
from app.utils.logger import logger
from app.utils.timezone import beijing_now
async def process_alarm_notification(alarm_data: Dict):
@@ -151,10 +152,20 @@ def _mark_false_alarm(alarm_id: str):
try:
alarm = db.query(AlarmEvent).filter(AlarmEvent.alarm_id == alarm_id).first()
if alarm:
now = beijing_now()
alarm.alarm_status = "FALSE"
alarm.handle_status = "DONE"
alarm.handle_remark = "VLM复核判定误报"
alarm.handled_at = datetime.now()
alarm.handled_at = now
# 计算告警时长VLM复核时间 - 事件时间)
if alarm.duration_ms is None and alarm.event_time:
try:
delta = now - alarm.event_time
alarm.duration_ms = int(delta.total_seconds() * 1000)
except Exception:
pass
if alarm.last_frame_time is None:
alarm.last_frame_time = now
db.commit()
logger.info(f"告警已标记误报: {alarm_id}")
except Exception as e: