refactor(db_compare): 差缺统计改为应到驱动,以出库日为批次归属日
将未到统计从实到驱动(实到锚点反推批次)改为应到驱动(batch_out_date 归属日直接取应到批次),以吸收应到任务提前 1~2 天提交的扰动(韵达固定 +1、中通偶发 +1)。 - expected_record 新增 out_date / batch_out_date + 索引;入库解析出库时间并聚合批次归属日,支持历史回填 - 新增 compare_site_outdate 应到驱动入口,保留 compare_site_date 实到驱动作对照 - 未到任务 / POST /compare / 全站汇总切换到应到驱动 - 附现状梳理、设计、实现总结三篇文档
This commit is contained in:
@@ -492,23 +492,20 @@ def _site_undelivered_handler(site):
|
||||
except Exception as e:
|
||||
print(f">> [入库] {site} 前置入库失败(不影响比对尝试): {e}")
|
||||
|
||||
# ── DB 比对(替代旧 Excel 比对)──
|
||||
# ── DB 比对(应到驱动:以批次归属日 batch_out_date 为锚)──
|
||||
try:
|
||||
from inbound_verify import db_compare # 懒导入,避免成环
|
||||
|
||||
if date:
|
||||
target_date = date
|
||||
else:
|
||||
offset = state_store.get_offset(site, "actual")
|
||||
target_date = (datetime.now().date() - timedelta(days=offset)).strftime(
|
||||
"%Y-%m-%d"
|
||||
)
|
||||
target_date = datetime.now().date().strftime("%Y-%m-%d")
|
||||
|
||||
result = db_compare.compare_site_date(site, target_date)
|
||||
result = db_compare.compare_site_outdate(site, target_date)
|
||||
if result is not None:
|
||||
db_compare.write_result_excel(result)
|
||||
else:
|
||||
print(f">> [未到] {site} {target_date}: 当天无实到数据,跳过比对")
|
||||
print(f">> [未到] {site} {target_date}: 当日无应到批次,跳过比对")
|
||||
except Exception as e:
|
||||
print(f">> [未到] {site} DB 比对异常(不影响下载结果): {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user