feat(shipping-notice): 完善处理投影与待办轮询

- 统一处理阶段、Gate 状态及跨页面投影
- 优化订单提取自动推进与待办分类查询
- 完善任务中心待办与批次轮询逻辑
- 补充后端投影、Gate、查询及 Worker 测试
- 新增待办轮询设计文档并更新技术文档
This commit is contained in:
hugo committed 2026-09-14 17:06:11 +08:00
1 parent 9d2fa522fa
commit fbca0b485c
22 files changed
+1454 -225

No files matched your search

@@ -4,10 +4,13 @@ backend/app/jobs/handlers/shipping_order_extraction.py
用途:消费订单抽取 Run,使用固定模板/通用确定性解析并持久化可复核结果。
依赖:Job queue、冻结 Run/Plan、确定性路由和解析、统一审计服务、版面排程、
ensure_workflow_items_for_run(物化后兜底建 Item)、order_extraction_merge、
order_supplement_merge(仅 eml)、order_extraction_ready_document_ids(Unit 级放行)。
order_supplement_merge(仅 eml)、order_extraction_ready_document_ids(Unit 级放行)、
order_extraction_has_extractable_ready_work(收口自交接判断)。
逻辑:物化附件与排版面 Job 均在主 try 内执行;有 ready PDF 即按 Unit 抽取并下游推进,
兄弟文件 layout pending 时 Job 以 partial_units_done 回到 waiting_layout;
收口时用 DB 实况判断:有 extractable ready work 则 layout_ready_continue 自交接;
仅 layouts_pending 且无 ready work 时以 partial_units_done 回到 waiting_layout;
运行时预算耗尽且仍有 pending Unit 时入队续抽,禁止终态 partially_completed;
两处续抽均 continue_from_running,避免复用即将结束的 running Job;
每个 Unit 按 STP route_decision 直通或落 provisional;needs_review 剥离验收标记;
不调用 Dify 主链。阶段 2:direct_pdf 跳过 email_supplements 与 ORDER_EMAIL_ADJUDICATION_*;
合并默认 keep_primary_documents_separate(多 PDF 各成 Candidate)。
@@ -46,6 +49,7 @@ from app.services.shipping_notice.order_extraction_run_service import (
begin_input_freeze,
complete_input_freeze,
mark_order_extraction_persistence_started,
order_extraction_has_extractable_ready_work,
order_extraction_layout_prerequisite_issues,
order_extraction_layouts_pending,
order_extraction_ready_document_ids,
@@ -1158,8 +1162,36 @@ def run_shipping_order_extraction(ctx: JobContext, payload: dict) -> None:
job_id=job.id,
)
raise
# [STEP] 仍有兄弟文件版式未完成:已抽 Unit 保留,Job 成功收口并回到 waiting_layout,禁止 Run 终态。
if layout_blocked_in_wave or order_extraction_layouts_pending(run):
# [STEP] 收口前用 DB 实况判断版面就绪:有可抽 ready work 则自交接续抽,
# 覆盖「Job 中途 layout 变 ready」与「开工快照过期跳过」;勿仅信 layout_blocked_in_wave。
has_ready_work = order_extraction_has_extractable_ready_work(run)
layouts_pending = order_extraction_layouts_pending(run)
if has_ready_work:
continue_job_id = _enqueue_ready_order_extraction_job(
run,
message='附件版面已就绪,继续识别剩余附件',
continue_from_running=True,
)
run.current_job_id = continue_job_id
run.phase = 'waiting_layout' if layouts_pending else 'queued'
db.session.commit()
finish_job(
job.id,
result={
'run_no': run.run_no,
'waiting_layout': bool(layouts_pending),
'waiting_continue': True,
'handoff_status': 'layout_ready_continue',
'merged_unit_count': len(pending_merge_unit_ids),
'ready_document_ids': sorted(ready_document_ids),
'continue_job_id': int(continue_job_id),
},
message='附件版面已就绪,已排队继续识别剩余附件',
owned_attempt=owned_attempt,
)
return
if layouts_pending:
# 仅仍有 layout pending、无可抽 ready work:回到 waiting_layout,靠 layout 完成回调唤醒。
run.phase = 'waiting_layout'
db.session.commit()
finish_job(
@@ -1197,7 +1229,9 @@ def run_shipping_order_extraction(ctx: JobContext, payload: dict) -> None:
commit=False,
)
continue_job_id = _enqueue_ready_order_extraction_job(
run, message='运行时预算已用尽,继续识别剩余附件',
run,
message='运行时预算已用尽,继续识别剩余附件',
continue_from_running=True,
)
run.current_job_id = continue_job_id
run.phase = 'waiting_layout'