refactor: OCR 字段改驼峰(ocrLayout/ocrCourier/ocrSName...)

This commit is contained in:
yeuimu
2026-07-24 08:33:46 +00:00
parent 7267aa928c
commit 3e075fd366
2 changed files with 13 additions and 13 deletions
+8 -8
View File
@@ -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
+5 -5
View File
@@ -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",),
)