From dc7653c256ee508e67f9c87ca6377416a09ed87a Mon Sep 17 00:00:00 2001 From: Misaka Date: Fri, 31 Jul 2026 22:58:12 +0800 Subject: [PATCH] fix(db_compare): anchor comparison on actual_offset so yunda reads fresh data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 比对以实到扫描日(actual.scan_time::date)为锚,锚点日期必须等于实到下载日 = actual_offset。 原 _site_undelivered_handler(runtime.py)与 _target_date_for(db_compare.py)误用 expected_offset 算锚点:韵达 exp=1 / act=0,锚点落到 today-1(昨天),读到历史数据。 两处改用 actual_offset 后韵达锚点 = today,反推出 expected 的昨天批次正确参与比对。 其余 3 站 exp == act == 0,锚点不变。 5 站真机验证:韵达 07-31 比对现读新鲜数据 107/104/3(修复前读昨天 116/115/1); 中通/安能/顺心 不变;全站汇总报表重新生成。 Co-Authored-By: Claude --- inbound_verify/db_compare.py | 6 +++--- inbound_verify/runtime.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inbound_verify/db_compare.py b/inbound_verify/db_compare.py index ff93494..b9deca9 100644 --- a/inbound_verify/db_compare.py +++ b/inbound_verify/db_compare.py @@ -499,10 +499,10 @@ def _stats_to_dict(s: CompareStats) -> dict: def _target_date_for(site: str) -> str: - """4 站比对锚点:today - expected_offset(与 _site_undelivered_handler 一致)。""" + """4 站比对锚点:today - actual_offset(以实到扫描日为锚,与 _site_undelivered_handler 一致)。""" from inbound_verify import state_store # 懒导入,避免成环 - offset = state_store.get_offset(site, "expected") + offset = state_store.get_offset(site, "actual") return (date.today() - timedelta(days=offset)).strftime("%Y-%m-%d") @@ -555,7 +555,7 @@ def _baishi_from_pg(cur, target: str): def build_full_report(date=None) -> str: """DB 版全站汇总报表:4 站走 DB 比对、百世走 PG,复用 compare.build_summary 渲染。 - 产出 output/应到未到数据.xlsx(/report 下载)。date=None 时各站按 expected_offset 算锚点。 + 产出 output/应到未到数据.xlsx(/report 下载)。date=None 时各站按 actual_offset 算锚点(以实到扫描日为锚)。 返回输出路径。""" from inbound_verify import compare # 复用 build_summary / write_station / OUTFILE diff --git a/inbound_verify/runtime.py b/inbound_verify/runtime.py index 54546d0..867ca4b 100644 --- a/inbound_verify/runtime.py +++ b/inbound_verify/runtime.py @@ -517,7 +517,7 @@ def _site_undelivered_handler(site): if date: target_date = date else: - offset = state_store.get_offset(site, "expected") + offset = state_store.get_offset(site, "actual") target_date = (datetime.now().date() - timedelta(days=offset)).strftime( "%Y-%m-%d" )