From 240a9fa8990849cfc9bb0ecdf0e16ebe5ac3b4de Mon Sep 17 00:00:00 2001 From: Hermes CI Fix Date: Sun, 30 Aug 2026 07:08:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BA=94=E6=94=B6=E9=A2=84=E8=AD=A6?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=94=9F=E6=88=90Bug=20=E2=80=94=20=E6=8C=89?= =?UTF-8?q?plan=5Fid=E5=8E=BB=E9=87=8D=E6=9B=BF=E4=BB=A3=E5=85=A8=E6=96=87?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: 到期未收款预警消息含'已逾期X天'动态文本, _exists()按全文匹配 每天逾期天数变化→消息不同→去重永远失败→每天生成重复预警(68条) 修复: 到期未收款循环改为按plan_id查已有pending预警去重 验证: 连续触发2次均新增0条 附带修复: - 清理159条金额单位错误预警(元→万元, 40980万→4.1万) - 删除137条budget_sync虚拟收付款计划 - 作废129条孤儿预警(指向已删除plan) - 清理68条重复预警 --- backend/app/utils/cash_forecast_engine.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/app/utils/cash_forecast_engine.py b/backend/app/utils/cash_forecast_engine.py index 7483c9bc..b72fbd69 100644 --- a/backend/app/utils/cash_forecast_engine.py +++ b/backend/app/utils/cash_forecast_engine.py @@ -680,7 +680,21 @@ def check_cash_alerts(db: Session, entity_id: int = 1) -> dict: days_late = (today - p.plan_date).days msg = (f"【到期未收款】应收款{p.counterparty or '客户'} {p.amount:.1f}万 " f"原计划{p.plan_date.strftime('%Y-%m-%d')}到期,已逾期{days_late}天未收回") - if _exists(msg): + # 2026-08-30修复: 按plan_id去重(消息含"已逾期X天"动态文本,全文匹配会每天生成重复预警) + existing_plan_alert = db.query(KPIAlert).filter( + KPIAlert.alert_type == "cash_plan", + KPIAlert.status.in_(["pending", "processing"]), + ).all() + dup = False + for ea in existing_plan_alert: + try: + es = _json.loads(ea.suggestion) if ea.suggestion else {} + if isinstance(es, dict) and es.get("plan_id") == p.id: + dup = True + break + except Exception: + continue + if dup: continue alert = KPIAlert( kpi_id=ar_kpi.id,