From 3e075fd3664d86e17ef0409b7fc401eb8cf16e26 Mon Sep 17 00:00:00 2001 From: yeuimu <2197651308@qq.com> Date: Fri, 24 Jul 2026 08:33:46 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20OCR=20=E5=AD=97=E6=AE=B5=E6=94=B9?= =?UTF-8?q?=E9=A9=BC=E5=B3=B0(ocrLayout/ocrCourier/ocrSName...)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flows/label_ocr.py | 16 ++++++++-------- flows/shared/db.py | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/flows/label_ocr.py b/flows/label_ocr.py index 60c48f2..20aa99f 100644 --- a/flows/label_ocr.py +++ b/flows/label_ocr.py @@ -14,17 +14,17 @@ from flows.shared import SyncDB, build_stats_rows, emit_sync_summary BATCH_SIZE = 200 _OCR_FIELD_MAP = [ - ("layout", "ocr_layout"), ("courier", "ocr_courier"), ("tracking", "ocr_tracking"), - ("marker", "ocr_marker"), ("s_name", "ocr_s_name"), ("s_street", "ocr_s_street"), - ("s_city", "ocr_s_city"), ("s_state", "ocr_s_state"), ("s_zip", "ocr_s_zip"), - ("r_name", "ocr_r_name"), ("r_street", "ocr_r_street"), ("r_city", "ocr_r_city"), - ("r_state", "ocr_r_state"), ("r_zip", "ocr_r_zip"), + ("layout", "ocrLayout"), ("courier", "ocrCourier"), ("tracking", "ocrTracking"), + ("marker", "ocrMarker"), ("s_name", "ocrSName"), ("s_street", "ocrSStreet"), + ("s_city", "ocrSCity"), ("s_state", "ocrSState"), ("s_zip", "ocrSZip"), + ("r_name", "ocrRName"), ("r_street", "ocrRStreet"), ("r_city", "ocrRCity"), + ("r_state", "ocrRState"), ("r_zip", "ocrRZip"), ] def _result_to_fields(r) -> dict[str, str | None]: if not r.ok: - return {"ocr_layout": "ERROR"} + return {"ocrLayout": "ERROR"} return {col: (getattr(r, attr) or "") for attr, col in _OCR_FIELD_MAP} @@ -45,7 +45,7 @@ def process_all(pending: list) -> dict[str, int]: unsupp.append((order_no, created_at)) if unsupp: - db.update_ocr_batch([(no, ca, {"ocr_layout": "UNSUPPORTED"}) for no, ca in unsupp]) + db.update_ocr_batch([(no, ca, {"ocrLayout": "UNSUPPORTED"}) for no, ca in unsupp]) stats["unsupported"] = len(unsupp) print(f"[OCR] 不支持国家: {len(unsupp)} 单 → UNSUPPORTED") @@ -62,7 +62,7 @@ def process_all(pending: list) -> dict[str, int]: results = ocr.recognize_batch(urls, country_code) except Exception as err: # noqa: BLE001 print(f"[OCR] {country_code} batch {batch_no}/{total_batches} 请求失败: {str(err)[:100]}") - db.update_ocr_batch([(no, created_map[no], {"ocr_layout": "ERROR"}) for no in created_map]) + db.update_ocr_batch([(no, created_map[no], {"ocrLayout": "ERROR"}) for no in created_map]) stats["error"] += len(batch) continue diff --git a/flows/shared/db.py b/flows/shared/db.py index bbd9a3c..6a01f7b 100644 --- a/flows/shared/db.py +++ b/flows/shared/db.py @@ -111,7 +111,7 @@ class SyncDB: sql = ( 'SELECT "orderNo","createdAt","labelPdfUrl","destinationCountry" ' 'FROM "Orders" ' - 'WHERE "labelPdfUrl" IS NOT NULL AND "ocr_layout" IS NULL' + 'WHERE "labelPdfUrl" IS NOT NULL AND "ocrLayout" IS NULL' ) params: list = [] if destination_country: @@ -180,10 +180,10 @@ class SyncDB: with conn.cursor() as cur: cur.execute( '''SELECT - COUNT(*) FILTER (WHERE "ocr_layout" IS NOT NULL AND "ocr_layout" NOT IN ('ERROR','UNSUPPORTED')) AS done, - COUNT(*) FILTER (WHERE "ocr_layout"='ERROR') AS error, - COUNT(*) FILTER (WHERE "ocr_layout"='UNSUPPORTED') AS unsupported, - COUNT(*) FILTER (WHERE "ocr_layout" IS NULL AND "labelPdfUrl" IS NOT NULL) AS pending + COUNT(*) FILTER (WHERE "ocrLayout" IS NOT NULL AND "ocrLayout" NOT IN ('ERROR','UNSUPPORTED')) AS done, + COUNT(*) FILTER (WHERE "ocrLayout"='ERROR') AS error, + COUNT(*) FILTER (WHERE "ocrLayout"='UNSUPPORTED') AS unsupported, + COUNT(*) FILTER (WHERE "ocrLayout" IS NULL AND "labelPdfUrl" IS NOT NULL) AS pending FROM "Orders" WHERE "systemName"=%s''', ("SDS",), )