feat: label-ocr 支持 destination_country/courier_source 筛选优先处理

This commit is contained in:
yeuimu
2026-07-24 02:10:03 +00:00
parent 72039e480b
commit f0580a8ce4
2 changed files with 25 additions and 10 deletions
+13 -6
View File
@@ -86,15 +86,22 @@ def process_all(pending: list) -> dict[str, int]:
@flow(name="label-ocr", log_prints=True)
def label_ocr() -> dict:
def label_ocr(destination_country: str | None = None, courier_source: str | None = None) -> dict:
"""面单 OCR enrichment。可选按 destinationCountry / courierSource 筛选优先处理。
例: label_ocr(destination_country='GB', courier_source='手动物流')
"""
db = SyncDB()
before = db.count_ocr_status()
print(f"OCR 状态(开始): {before}")
pending = db.get_ocr_pending()
print(f"待 OCR: {len(pending)} 单 (RIIN+SDS)")
pending = db.get_ocr_pending(destination_country=destination_country, courier_source=courier_source)
scope = ""
if destination_country or courier_source:
scope = f" [{destination_country or ''} {courier_source or ''}]".strip()
print(f"待 OCR: {len(pending)} 单{scope} (RIIN+SDS)")
if not pending:
emit_sync_summary("面单 OCR", build_stats_rows("ALL", {}, [
emit_sync_summary(f"面单 OCR{scope}", build_stats_rows("ALL", {}, [
("待处理", 0), ("累计已完成", before.get("done", 0)),
]))
return {"processed": 0, **before}
@@ -102,10 +109,10 @@ def label_ocr() -> dict:
stats = process_all(pending)
after = db.count_ocr_status()
total_processed = stats["success"] + stats["error"] + stats["unsupported"]
print(f"完成: 处理 {total_processed} 单 / {stats['batches']} 批 | "
print(f"完成{scope}: 处理 {total_processed} 单 / {stats['batches']} 批 | "
f"成功 {stats['success']} 失败 {stats['error']} 不支持 {stats['unsupported']}")
print(f"累计: {after}")
emit_sync_summary("面单 OCR", build_stats_rows("ALL", {}, [
emit_sync_summary(f"面单 OCR{scope}", build_stats_rows("ALL", {}, [
("本批处理", total_processed), ("成功", stats["success"]),
("失败", stats["error"]), ("不支持", stats["unsupported"]),
("累计已完成", after.get("done", 0)), ("累计待处理", after.get("pending", 0)),