Commit Graph

23 Commits

Author SHA1 Message Date
683791d1c9 fix(service): Alarm creation without duration - aligns with ai_edge changes
Changes:
1. Modified create_from_mqtt to parse first_frame_time from MQTT data
2. Removed duration_minutes processing logic
3. Set duration_ms=None and last_frame_time=None on alarm creation
4. Updated _determine_alarm_level to handle duration_ms=None (returns level 2 for leave_post)

This ensures alarms are created with status=NEW and no duration/end time,
which will be populated later when the alarm is resolved.

Test: test_alarm_create_no_duration.py validates the new behavior.

Related: Task 2 of alarm status management fix

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-13 09:50:53 +08:00
789dc6a373 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>
2026-02-12 14:57:03 +08:00
f3af9cac22 feat(aiot): 告警结束接口 + 持续时长更新 + first_frame_time存储
新增告警结束接口:
- 新增EdgeAlarmResolve请求模型
- 新增POST /edge/resolve端点(无需认证,Edge设备调用)
- 新增resolve_alarm服务方法:更新duration_ms、last_frame_time
- 人员回岗/非工作时间自动设置alarm_status=CLOSED、handle_status=DONE

告警创建修复:
- create_from_edge_report现在从ext_data读取first_frame_time写入数据库
- create_from_edge_report现在从ext_data读取duration_ms写入数据库
- 统一edge_node_id从ext_data提取
2026-02-11 17:56:02 +08:00
cf41db2983 feat(aiot): 告警生成时异步上报运维平台
- 边缘告警入库后异步 POST 到运维平台 /admin-api/ops/alarm/receive
- 提前提取 ORM 字段避免异步执行时 session 关闭导致属性为空
- event_time 转为 ISO 字符串格式,修复时间显示为 1970 的问题
- 请求参数含 alarmId、alarmType、deviceId、eventTime、alarmLevel、notifyUserIds、tenantId

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 14:00:11 +08:00
0f5e3ebce2 feat(aiot): 本地截图回退访问 + 告警API前端兼容
- 挂载 Edge 截图目录为 /captures 静态文件(COS 不可用时回退)
- 挂载 /uploads 静态文件目录
- _alarm_to_camel 支持 local: 前缀转 /captures/ URL
- 告警分页/详情/处理/删除接口兼容前端旧字段名(id、cameraId、status 等)
- 设备告警汇总添加前端兼容别名(cameraId、pendingCount 等)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 09:56:15 +08:00
9f4cea0810 feat(aiot): 边缘告警HTTP上报 + 移除配置中转层
- 新增 edge/report 端点接收边缘端HTTP告警上报
- alarm_event_service 新增 create_from_edge_report 幂等创建
- schemas 新增 EdgeAlarmReport 模型
- 移除 config_service/redis_service/yudao_aiot_config 配置中转
- MQTT 服务标记废弃,告警上报改为HTTP+COS
- config 新增 COS/Redis 配置项
- requirements 新增 redis 依赖

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 15:22:01 +08:00
6cf1524013 feat(aiot): 告警三表结构升级 + 腾讯云COS对象存储集成
1. 新增三表结构: alarm_event(主表), alarm_event_ext(算法扩展), alarm_llm_analysis(大模型分析)
2. 新增 AlarmEventService 服务,支持 MQTT/HTTP 双路创建告警
3. MQTT handler 双写新旧表,平滑过渡
4. 重写 yudao_aiot_alarm 路由,对接新告警服务
5. 集成腾讯云 COS 对象存储:上传、预签名URL、STS临时凭证
6. 新增 storage 路由:upload/presign/upload-url/sts 四个接口
7. COS 未启用时自动降级本地 uploads/ 目录存储
8. 新增数据迁移脚本 migrate_to_alarm_event.py
9. 删除根目录 main.py(非项目入口)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 17:47:35 +08:00
b4fa6901f3 fix(mqtt): 修复 MQTT 连接反复断开重连的问题
- 协议从 MQTTv5 降级为 MQTTv311,提高兼容性
- client_id 添加随机后缀,防止多实例冲突导致互相踢连接
- 修复 on_connect/on_disconnect 回调的参数解析逻辑

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 11:43:15 +08:00
08e9d785eb fix(aiot): 删除实时视频菜单项
实时视频为 AIoT 自建功能,非芋道原生模块,直接删除菜单定义。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 11:40:50 +08:00
a8726cebed fix(aiot): 恢复实时视频菜单项并设置隐藏
恢复被误删的实时视频菜单定义,通过 visible=False 隐藏菜单,
保留路由和组件以备后续启用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 11:20:32 +08:00
283f12e443 fix(aiot): 移除实时视频菜单项
从后端菜单定义中彻底删除实时视频菜单条目,
而非仅设置 visible=False,确保前端不再显示该菜单。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 11:17:41 +08:00
0f4ebde69f feat(aiot): 隐藏实时视频菜单
将实时视频菜单的 visible 设为 False,前端不再显示该菜单项,
但保留组件和路由定义以备后续启用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 10:50:03 +08:00
b3cf544343 feat: 注册 aiot 路由并更新主程序配置
- main.py:注册 aiot_alarm 和 aiot_edge 路由,保留旧路由兼容
- config.py/alert_service.py/mqtt_service.py:同步更新配置和服务
- 添加 CLAUDE.md 项目说明文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:39:53 +08:00
5a2d887f1f feat(aiot): 添加 aiot/alarm 和 aiot/edge 芋道兼容路由
- 新增 yudao_aiot_alarm.py:/admin-api/aiot/alarm/* 告警管理路由
  包含分页查询、详情、处理、删除、统计、摄像头汇总
- 新增 yudao_aiot_edge.py:/admin-api/aiot/edge/* 边缘设备路由
  包含设备分页、详情、统计
- 复用现有 alert_service 和 device_service

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:39:39 +08:00
1ddc23e0d3 feat(yudao): 添加芋道兼容层和基础路由
- 新增 yudao_compat.py:芋道标准响应格式、权限校验
- 新增 yudao_auth.py:登录认证、权限信息、租户等系统接口
- 新增 yudao_alert.py:告警管理和摄像头汇总的芋道兼容路由
- 新增 routers/__init__.py:统一导出路由模块

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:38:54 +08:00
c08702085b chore: 调整存储和日志模块
- oss_storage: 暂时使用本地存储,OSS 代码注释保留
- logger: 优化日志配置

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:57:49 +08:00
885665ecf0 feat: 集成所有服务到主程序
- 使用 lifespan 管理服务生命周期
- 启动时自动连接 MQTT 并订阅告警主题
- 新增 WebSocket 端点 /ws/alerts
- 新增设备管理 API /api/v1/devices
- 新增 MQTT 状态 API /api/v1/mqtt/statistics
- 增强健康检查返回 MQTT 和 WebSocket 状态

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:57:25 +08:00
cd21d65b85 feat: 增强 Schema 定义
- AlertCreate/Response: 新增 bind_id/device_id/bbox/level
- 新增 DeviceResponse/DeviceListResponse
- 新增 DeviceStatisticsResponse
- HealthResponse: 新增 mqtt/websocket_connections

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:57:15 +08:00
a5ecec7610 feat: 增强告警服务
- 新增 create_alert_from_mqtt 处理 MQTT 告警
- 新增 _determine_level 自动判断告警级别
- 新增 dispatch_alert 派发告警到工单
- 支持告警级别统计

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:57:05 +08:00
6861fb6653 feat: 新增核心服务模块
- mqtt_service: MQTT 订阅服务,对接 ai_edge 告警和心跳
- notification_service: WebSocket 实时推送服务
- device_service: 边缘设备心跳管理和离线检测

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:56:57 +08:00
9ea47938dc feat: 增强数据模型
- Alert: 新增 bind_id/device_id/bbox/level/work_order_id
- 新增 WorkOrder 工单模型
- 新增 EdgeDevice 边缘设备模型
- 新增 AlertLevel/WorkOrderStatus/DeviceStatus 枚举
- 修复 SQLite 主键自增问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:56:48 +08:00
78d147b7da feat: 新增 MQTT 配置支持
- 新增 MQTTConfig 配置类
- 支持 broker_host/port/client_id 等配置
- 支持环境变量覆盖配置

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 13:56:39 +08:00
baa895a6f1 feat: 初始化告警平台后端项目
- 创建 FastAPI 项目结构
- 实现告警数据模型(SQLAlchemy)
- 实现 multipart/form-data 告警接收接口
- 实现阿里云 OSS 图片上传模块
- 实现告警查询和处理 API
- 实现异步大模型分析模块
2026-02-02 09:40:02 +08:00