feat(shipping-notice): 无表头文档抽取增强与复核深链身份修复
- 新增表头 OCR 救援:模板匹配落 layout_drift/no_match 时按表头带证据补洞重评候选身份,主抽取流程接入并落 identity_rescue 事实字段 - 预约号裸数字兜底:正文无表头且常规证据缺失时扫描 5/10 位纯数字候选,持久化预置、合并末段唯一/多候选裁决 - 修复复核深链仅带 run_no 时队列项显示未命名:Case 身份优先按当前工作面 displayCase 匹配队列项 - 同步抽取 Job/运行服务/候选持久化配套与 OCR 救援、预约号启发式、表头身份测试
This commit is contained in:
1 parent
5187b6105b
commit
3b53a2219c
15 files changed
+1660
-6
No files matched your search
@@ -724,6 +724,58 @@ def _handoff_continue_order_extraction(
|
||||
return True
|
||||
|
||||
|
||||
def _emit_reservation_heuristic_audit(
|
||||
*,
|
||||
run: Any,
|
||||
merged_by_unit_id: dict[int, list[dict[str, Any]]],
|
||||
) -> None:
|
||||
"""
|
||||
合并末段「裸数字预约单号兜底」落地后补审计事件,供上线后观察误判率。
|
||||
|
||||
【AI 触发时机】:EML 补充合并(merge_email_supplements)完成后调用。
|
||||
只读订单上的 _hxops_reservation_heuristic 标记,不修改订单;命中与多候选
|
||||
各发一条事件,metadata 携带 unit/候选值/正文文档定位,便于按 Case 回溯证据。
|
||||
|
||||
Args:
|
||||
run: 当前订单抽取 Run(审计聚合根)。
|
||||
merged_by_unit_id: 本趟合并产物 {unit_id: [order]}。
|
||||
"""
|
||||
applied_entries: list[dict[str, Any]] = []
|
||||
ambiguous_entries: list[dict[str, Any]] = []
|
||||
for unit_id, orders in (merged_by_unit_id or {}).items():
|
||||
for order in orders or []:
|
||||
marker = order.get('_hxops_reservation_heuristic') if isinstance(order, dict) else None
|
||||
if not isinstance(marker, dict):
|
||||
continue
|
||||
entry = {
|
||||
'unit_id': int(unit_id),
|
||||
'values': marker.get('values') or [],
|
||||
'document_id': marker.get('document_id'),
|
||||
}
|
||||
if marker.get('status') == 'applied':
|
||||
applied_entries.append({**entry, 'value': marker.get('value')})
|
||||
else:
|
||||
ambiguous_entries.append(entry)
|
||||
for event_type, entries in (
|
||||
('reservation_heuristic_applied', applied_entries),
|
||||
('reservation_heuristic_ambiguous', ambiguous_entries),
|
||||
):
|
||||
if not entries:
|
||||
continue
|
||||
append_shipping_audit_event(
|
||||
event_type=event_type,
|
||||
aggregate_type='order_extraction_run',
|
||||
aggregate_id=str(run.id),
|
||||
run_no=run.run_no,
|
||||
actor_type='system',
|
||||
source='shipping_order_extraction',
|
||||
metadata={
|
||||
'entries': entries,
|
||||
'decision_rule_version': 'bare-numeric-reservation-v1',
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _is_transient_lock_error(exc: BaseException) -> bool:
|
||||
"""
|
||||
判断异常是否为瞬时锁冲突(PostgreSQL 死锁 40P01 / 锁等待超时 55P03)。
|
||||
@@ -1139,6 +1191,7 @@ def run_shipping_order_extraction(ctx: JobContext, payload: dict) -> None:
|
||||
},
|
||||
)
|
||||
_merge_group_orders(eml_units, apply_email_supplements=True)
|
||||
_emit_reservation_heuristic_audit(run=run, merged_by_unit_id=merged_by_unit_id)
|
||||
append_shipping_audit_event(
|
||||
event_type='ORDER_EMAIL_ADJUDICATION_COMPLETED',
|
||||
aggregate_type='order_extraction_run',
|
||||
|
||||
Reference in new issue
Block a user