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,