Files
group_xinghuo_jinrong/scripts/cron/escalation_scan.py
T
GaoYiYuan_0626 90d0660b44 feat: C5 FR-9 预警处置时效升级(RISK-007,P0)
- 仓储:新增 list_pending_alerts_all / update_alert_escalation(统一读改写 payload,
  升级标记独占写入,status/handler_* 列不碰;_parse_alert 补 created_at/handled_at
  字符串→datetime 解析,兼容 sqlite 原生 DDL)
- escalation_service.scan_and_escalate:扫描判级(普通 4h/24h、AML 1h/4h 短通道)、
  幂等闸门(仅升不降)、先持久化再推送、按 (customer_id,level) 降噪合并一次推送、
  通知链累积(L1 含 risk_manager / L2 含 compliance)、逐单+任务级审计
- scripts/cron/escalation_scan.py:15min 定时扫描壳(sys.path 引导 + new_trace + JSON 摘要)
- 对话线 query_overdue_alerts Tool + 注册表 + 意图词(置于 alert_query 之前)+ summarize 分支
- C5 前置:seed STAFF-31001/31002(risk_manager) + deps 矩阵放行 + chat.py 显式 deny +
  risk.py 台账全量只读分支;JWT 手册 §5.3/§5.4/§6.1 增补 risk_manager
- 测试:conftest 回拨 fixture + test_escalation_service(9) + risk_api/manager(5) +
  chat deny(1) + chat_tools overdue(2);全量 470 绿(453+17)
2026-09-07 19:28:04 +08:00

34 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""RISK-007 处置时效升级扫描(建议 15min 周期;RISK_ESCALATION_SCAN_MINUTES 可配)。
初期独立脚本 + 系统 cron;内嵌 lifespan 归 M4 评估(开发计划挂账 #2)。
结构对齐 scripts/demo/rebuild_alerts.py:sys.path 引导 → new_trace → 扫描 → 打印
JSON 摘要(供 cron 日志 / 演示走查)。审计写库失败由 service 内降级留底,不阻塞
下次扫描(红线 5 口径)。
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
# ① sys.path 引导项目根(rebuild_alerts 先例)
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
from app.service.risk.escalation_service import scan_and_escalate # noqa: E402
from app.utils.trace import new_trace # noqa: E402
def main() -> int:
# ② 显式生成 trace(无 HTTP 上下文,service 内 current_trace 复用)
new_trace()
# ③ 扫描 → 打印 JSON 摘要
summary = scan_and_escalate()
print(json.dumps(summary, ensure_ascii=False, default=str, indent=2))
return 0
if __name__ == "__main__":
sys.exit(main())