fix: 修复告警时间戳格式 - 移除微秒保持一致性

问题描述:
- 告警结束时间显示过多小数位(如 2026-02-12T14:23:42.331566)
- 与触发时间格式不一致(2026-02-12 14:23:24)

修改内容:
1. app/models.py
   - AlarmEvent.to_dict() 使用 strftime 格式化所有时间戳
   - 统一格式为 'YYYY-MM-DD HH:MM:SS'(去除微秒和T分隔符)

2. app/services/alarm_event_service.py
   - resolve_alarm() 解析 last_frame_time 时去除微秒
   - 确保数据库存储的时间戳格式一致

影响范围:
- 告警事件API响应格式
- 前端显示更加简洁统一

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 14:57:03 +08:00
parent f3af9cac22
commit 789dc6a373
2 changed files with 10 additions and 9 deletions

View File

@@ -295,9 +295,9 @@ class AlarmEvent(Base):
"algorithm_code": self.algorithm_code,
"device_id": self.device_id,
"scene_id": self.scene_id,
"event_time": self.event_time.isoformat() if self.event_time else None,
"first_frame_time": self.first_frame_time.isoformat() if self.first_frame_time else None,
"last_frame_time": self.last_frame_time.isoformat() if self.last_frame_time else None,
"event_time": self.event_time.strftime('%Y-%m-%d %H:%M:%S') if self.event_time else None,
"first_frame_time": self.first_frame_time.strftime('%Y-%m-%d %H:%M:%S') if self.first_frame_time else None,
"last_frame_time": self.last_frame_time.strftime('%Y-%m-%d %H:%M:%S') if self.last_frame_time else None,
"duration_ms": self.duration_ms,
"alarm_level": self.alarm_level,
"confidence_score": self.confidence_score,
@@ -308,9 +308,9 @@ class AlarmEvent(Base):
"edge_node_id": self.edge_node_id,
"handler": self.handler,
"handle_remark": self.handle_remark,
"handled_at": self.handled_at.isoformat() if self.handled_at else None,
"created_at": self.created_at.isoformat() if self.created_at else None,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
"handled_at": self.handled_at.strftime('%Y-%m-%d %H:%M:%S') if self.handled_at else None,
"created_at": self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
"updated_at": self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None,
}