fix(alerts): F4b 展示口径与落库口径同源 — summary/suggestions/upcoming_7d 按快照批次 mode 过滤 + raw/excluded/batches 可见 (dama-cashplan-zombie-alert-cleanup-20260913)

This commit is contained in:
wecom-fullstack
2026-09-13 07:38:58 +08:00
parent 75309ffcaa
commit e159db058a
3 changed files with 315 additions and 10 deletions
@@ -212,6 +212,23 @@ def main():
e1_ids_after = {r[0] for r in raw("SELECT id FROM kpi_alerts WHERE entity_id=1", db=SCRATCH_DB)}
check("F1 酣客(entity1) 预警零变化", e1_ids_before == e1_ids_after,
f"{len(e1_ids_before)} -> {len(e1_ids_after)}")
# ── F4b:summary/suggestions 展示口径与落库口径同源 ──
# (任务 dama-cashplan-zombie-alert-cleanup-20260913 B 段:曾是「写入 0 / 展示 216」)
sm = res["summary"]
check("F4b summary 快照批次不计入逐户口径(count=0)", sm["overdue_receive_count"] == 0,
f"count={sm['overdue_receive_count']} raw={sm['overdue_receive_count_raw']}")
check("F4b 展示口径 ⇔ 落库口径(overdue_receive_count=0 与 new_alerts=0 一致)",
(sm["overdue_receive_count"] == 0) == (res["new_alerts"] == 0),
f"count={sm['overdue_receive_count']} new={res['new_alerts']}")
check("F4b 剔除量显式可见(excluded == skipped_rows == 快照逾期行数)",
sm["snapshot_rows_excluded"] == res["balance_snapshot"]["skipped_rows"] == snap_plans,
f"excluded={sm['snapshot_rows_excluded']} skipped={res['balance_snapshot']['skipped_rows']} expect={snap_plans}")
check("F4b 全集可追溯(raw_count == 快照逾期行数)", sm["overdue_receive_count_raw"] == snap_plans,
f"raw={sm['overdue_receive_count_raw']} expect={snap_plans}")
check("F4b 批次明细可见(bohai_ar_20260630 210 户)",
any(b["source"] == "bohai_ar_20260630" and b["count"] == 210 for b in sm["snapshot_batches"]),
f"batches={sm['snapshot_batches']}")
s.close()
# ══════════════════════════════════════════════════════════
@@ -282,6 +299,12 @@ def main():
check("F4 aggregate 幂等(二次 0 新增 / 0 变更)",
res4["new_alerts"] == 0 and res4["refreshed_alerts"] == 0,
f"new={res4['new_alerts']} refreshed={res4['refreshed_alerts']}")
agg_sm = res3["summary"]
check("F4b aggregate 展示口径=落库(业务行 + 每批次 1 条)",
agg_sm["overdue_receive_count"] ==
(agg_sm["overdue_receive_count_raw"] - agg_sm["snapshot_rows_total"]) + len(agg_sm["snapshot_batches"]),
f"count={agg_sm['overdue_receive_count']} raw={agg_sm['overdue_receive_count_raw']} "
f"snapshot={agg_sm['snapshot_rows_total']} batches={len(agg_sm['snapshot_batches'])}")
s.close()
# ══════════════════════════════════════════════════════════
@@ -307,6 +330,11 @@ def main():
check("F1/F3 旧模式金额按现值渲染(无 10000 倍放大)",
max(amts5) < 5000 and abs(sum(amts5) - exp_sum) < 0.6,
f"max={max(amts5)} sum={sum(amts5):.2f}万 expect={exp_sum:.2f}万")
sm5 = res5["summary"]
check("F4b per_customer 展示口径=落库(逐户全额 / excluded=0)",
sm5["overdue_receive_count"] == sm5["overdue_receive_count_raw"] and sm5["snapshot_rows_excluded"] == 0,
f"count={sm5['overdue_receive_count']} raw={sm5['overdue_receive_count_raw']} "
f"excluded={sm5['snapshot_rows_excluded']}")
s.close()
os.environ.pop("CMA_CASH_SNAPSHOT_MODE", None)
@@ -347,6 +375,11 @@ def main():
d0.get("balance_snapshot", {}).get("mode") == "skip"
and d0.get("balance_snapshot", {}).get("skipped_rows") == snap_plans,
f"snapshot={d0.get('balance_snapshot')}")
check("F4b 端点响应 summary=落库口径(count=new_alerts / 快照批次不计入 / excluded 可见)",
d0.get("summary", {}).get("overdue_receive_count") == d0.get("new_alerts")
and d0.get("summary", {}).get("snapshot_rows_excluded") == snap_plans,
f"count={d0.get('summary', {}).get('overdue_receive_count')} new={d0.get('new_alerts')} "
f"excluded={d0.get('summary', {}).get('snapshot_rows_excluded')} expect={snap_plans}")
snap_pids = set(r[0] for r in raw(
"SELECT id FROM cash_plans WHERE entity_id=2 AND plan_type='receive' AND status='pending' "
"AND plan_date < CURDATE() AND source IN ('bohai_ar_20260630','bohai_ap_20260630',"