切换到 IoT 工单驱动模式:所有状态变更由 IoT 回调驱动

1. notify_dispatch: 工单优先于卡片发送,创建成功则跳过直发卡片(等IoT回调send-card)
2. wechat_callback: IoT API 成功后直接返回,等 sync-status 回调更新告警+卡片
3. edge_compat: 启用工单自动结单,成功后等 sync-status 回调
4. yudao_aiot_alarm: 前端操作优先调 IoT 工单 API,降级直接更新卡片
5. wechat_notify_api: 修复 confirmed 的 card_action 为 None 导致卡片不更新的 bug

所有路径均保留降级逻辑:IoT 失败或工单未启用时直接处理告警+更新卡片
This commit is contained in:
2026-03-25 15:38:52 +08:00
parent 5a64e2fe11
commit 3a9595de7c
5 changed files with 127 additions and 88 deletions

View File

@@ -147,24 +147,9 @@ async def process_alarm_notification(alarm_data: Dict):
else:
logger.debug("未配置群聊ID跳过群聊推送")
# ---- 3b. 个人按钮交互卡片 ----
sent = await wechat_service.send_alarm_card(
user_ids=user_ids,
alarm_id=alarm_id,
alarm_type=alarm_type,
area_name=area_name,
camera_name=camera_name,
description=description,
event_time=event_time_str,
alarm_level=alarm_level,
)
if sent:
logger.info(f"告警通知完成: {alarm_id}")
else:
logger.warning(f"个人卡片发送失败: {alarm_id}")
# ---- 4. 创建安保工单 ----
# ---- 3b. 创建工单(优先于卡片发送) ----
wo_client = get_work_order_client()
order_created = False
if wo_client.enabled:
wo_area_id = _get_alarm_area_id(alarm_id) or area_id_int
if wo_area_id:
@@ -187,9 +172,28 @@ async def process_alarm_notification(alarm_data: Dict):
)
if order_id:
_save_order_id(alarm_id, order_id)
order_created = True
logger.info(f"工单已创建等待IoT回调发卡片: alarm={alarm_id}, order={order_id}")
else:
logger.warning(f"告警无 area_id跳过工单创建: {alarm_id}")
# ---- 3c. 个人卡片(仅在工单未创建时降级发送) ----
if not order_created:
sent = await wechat_service.send_alarm_card(
user_ids=user_ids,
alarm_id=alarm_id,
alarm_type=alarm_type,
area_name=area_name,
camera_name=camera_name,
description=description,
event_time=event_time_str,
alarm_level=alarm_level,
)
if sent:
logger.info(f"降级直发卡片完成: {alarm_id}")
else:
logger.warning(f"降级直发卡片失败: {alarm_id}")
except Exception as e:
logger.error(f"告警通知处理失败: {alarm_id}, error={e}", exc_info=True)