feat(shipping-notice): 收敛复核状态隔离、STP 重试幂等与 XFA 合成预览标注
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
84a881b554
commit
74270adc22
149 files changed
+20111
-3871
No files matched your search
@@ -3,10 +3,12 @@ backend/app/api/admin/shipping_order_document_profiles.py
|
||||
|
||||
用途:提供订单文档模板 Profile 的管理员版本治理 API。
|
||||
依赖:admin blueprint、require_admin、order_document_profile_service、
|
||||
order_document_profile_visual_binding_service、order_profile_unified_migration。
|
||||
逻辑:路由只转换请求和操作者;版本、Schema、字段、统一迁移与发布门禁全部由服务层执行。
|
||||
order_document_profile_preview_service、order_document_profile_xfa_preview_service、
|
||||
order_document_profile_xfa_automark_service、order_document_profile_visual_binding_service、
|
||||
order_profile_unified_migration。
|
||||
逻辑:路由只转换请求和操作者;版本、Schema、字段、XFA 合成预览、OCR 自动标记、
|
||||
统一迁移与发布门禁由服务层执行。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
@@ -23,6 +25,8 @@ from app.services.shipping_notice import order_document_profile_diff as diff_ser
|
||||
from app.services.shipping_notice import order_document_profile_creation_service as creation_service
|
||||
from app.services.shipping_notice import order_document_profile_lease_service as lease_service
|
||||
from app.services.shipping_notice import order_document_profile_preview_service as preview_service
|
||||
from app.services.shipping_notice import order_document_profile_xfa_preview_service as xfa_preview_service
|
||||
from app.services.shipping_notice import order_document_profile_xfa_automark_service as xfa_automark_service
|
||||
from app.services.shipping_notice import order_document_profile_revision_service as revision_service
|
||||
from app.services.shipping_notice import order_document_profile_suggestion_service as suggestion_service
|
||||
from app.services.shipping_notice import order_document_profile_service as service
|
||||
@@ -798,6 +802,62 @@ def preview_order_document_profile_sample_xfa_value(document_id: int):
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/preview',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def request_order_document_profile_sample_xfa_synthetic_preview(document_id: int):
|
||||
"""
|
||||
生成或复用绑定冻结 Analysis 的 XFA 合成预览,返回身份与页元数据(不含大图)。
|
||||
|
||||
核心逻辑:委托 xfa_preview_service;可选 body.force=true 强制重生成。
|
||||
"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
return _private_ok(xfa_preview_service.request_xfa_synthetic_preview(
|
||||
document_id,
|
||||
actor_id=_actor_id(),
|
||||
force=bool(data.get('force')),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/preview/pages',
|
||||
methods=['GET'],
|
||||
)
|
||||
@require_admin
|
||||
def list_order_document_profile_sample_xfa_synthetic_preview_pages(document_id: int):
|
||||
"""列出冻结 Analysis 绑定的最新 ready 合成预览页并签发短时 token。"""
|
||||
return _private_ok(xfa_preview_service.list_xfa_synthetic_preview_pages(
|
||||
document_id,
|
||||
actor_id=_actor_id(),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/preview/pages/<int:page_no>',
|
||||
methods=['GET'],
|
||||
)
|
||||
@require_admin
|
||||
def get_order_document_profile_sample_xfa_synthetic_preview_page(document_id: int, page_no: int):
|
||||
"""
|
||||
消费一次性授权并返回合成预览单页 PNG。
|
||||
|
||||
核心逻辑:与既有 preview-pages 一致——query preview_token、private no-store。
|
||||
"""
|
||||
image = xfa_preview_service.render_xfa_synthetic_preview_page(
|
||||
document_id,
|
||||
page_no=page_no,
|
||||
token=str(request.args.get('preview_token') or ''),
|
||||
actor_id=_actor_id(),
|
||||
)
|
||||
response = send_file(io.BytesIO(image), mimetype='image/png', as_attachment=False, max_age=0)
|
||||
response.headers['Cache-Control'] = 'private, no-store, max-age=0'
|
||||
response.headers['Pragma'] = 'no-cache'
|
||||
response.headers['X-Content-Type-Options'] = 'nosniff'
|
||||
return response
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/split-rules/preview',
|
||||
methods=['POST'],
|
||||
@@ -948,7 +1008,7 @@ def suggest_order_document_profile_xfa_visual_bindings(profile_id: int):
|
||||
)
|
||||
@require_admin
|
||||
def confirm_order_document_profile_xfa_visual_binding(profile_id: int, binding_id: str):
|
||||
"""管理员确认视觉绑定;写 before/after 审计。"""
|
||||
"""管理员确认视觉绑定;须携带合成预览 checksum / render_mode;写 before/after 审计。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
ctx = _write_context(data)
|
||||
visual = data.get('visual_binding') if isinstance(data.get('visual_binding'), dict) else {}
|
||||
@@ -962,6 +1022,8 @@ def confirm_order_document_profile_xfa_visual_binding(profile_id: int, binding_i
|
||||
lease_token=ctx.get('lease_token'),
|
||||
operation_id=ctx.get('operation_id'),
|
||||
request_id=getattr(g, 'request_id', None),
|
||||
preview_render_checksum=str(data.get('preview_render_checksum') or '').strip() or None,
|
||||
render_mode=str(data.get('render_mode') or '').strip() or None,
|
||||
))
|
||||
|
||||
|
||||
@@ -986,6 +1048,97 @@ def reject_order_document_profile_xfa_visual_binding(profile_id: int, binding_id
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/automark',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def enqueue_order_document_profile_xfa_ocr_automark(profile_id: int):
|
||||
"""
|
||||
入队 XFA OCR 自动标记异步 Job。
|
||||
|
||||
核心逻辑:body.document_id 必填;可选 force 强制重生成合成预览后入队。
|
||||
"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
document_id = data.get('document_id')
|
||||
if document_id in (None, ''):
|
||||
raise ValidationError(
|
||||
'document_id is required',
|
||||
code='SHIPPING.ORDER_DOCUMENT_PROFILE_INVALID',
|
||||
)
|
||||
page_nos = data.get('page_nos') if isinstance(data.get('page_nos'), list) else None
|
||||
return _private_ok(xfa_automark_service.enqueue_xfa_ocr_automark(
|
||||
profile_id,
|
||||
document_id=int(document_id),
|
||||
actor_id=_actor_id(),
|
||||
force=bool(data.get('force')),
|
||||
page_nos=[int(item) for item in (page_nos or [])],
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/automark/jobs/<int:job_id>',
|
||||
methods=['GET'],
|
||||
)
|
||||
@require_admin
|
||||
def get_order_document_profile_xfa_ocr_automark_job(profile_id: int, job_id: int):
|
||||
"""轮询 OCR 自动标记 Job 状态与建议列表。"""
|
||||
return _private_ok(xfa_automark_service.get_xfa_ocr_automark_job(
|
||||
job_id,
|
||||
profile_id=profile_id,
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/automark/suggestions/<string:suggestion_id>/accept',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def accept_order_document_profile_xfa_automark_suggestion(profile_id: int, suggestion_id: str):
|
||||
"""
|
||||
接受 OCR 自动标记建议。
|
||||
|
||||
核心逻辑:high→confirmed(须 checksum);medium/low→suggested;mismatch 阻断。
|
||||
"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
ctx = _write_context(data)
|
||||
job_id = data.get('job_id')
|
||||
return _private_ok(xfa_automark_service.accept_xfa_automark_suggestion(
|
||||
profile_id,
|
||||
suggestion_id,
|
||||
actor_id=_actor_id(),
|
||||
browser_session_id=ctx.get('browser_session_id'),
|
||||
lease_token=ctx.get('lease_token'),
|
||||
operation_id=ctx.get('operation_id'),
|
||||
request_id=getattr(g, 'request_id', None),
|
||||
job_id=int(job_id) if job_id not in (None, '') else None,
|
||||
preview_render_checksum=str(data.get('preview_render_checksum') or '').strip() or None,
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/automark/suggestions/<string:suggestion_id>/reject',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def reject_order_document_profile_xfa_automark_suggestion(profile_id: int, suggestion_id: str):
|
||||
"""驳回 OCR 自动标记建议并减少 unresolved mismatch 计数。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
ctx = _write_context(data)
|
||||
job_id = data.get('job_id')
|
||||
return _private_ok(xfa_automark_service.reject_xfa_automark_suggestion(
|
||||
profile_id,
|
||||
suggestion_id,
|
||||
actor_id=_actor_id(),
|
||||
browser_session_id=ctx.get('browser_session_id'),
|
||||
lease_token=ctx.get('lease_token'),
|
||||
operation_id=ctx.get('operation_id'),
|
||||
request_id=getattr(g, 'request_id', None),
|
||||
reason_code=str(data.get('reason_code') or '').strip() or None,
|
||||
job_id=int(job_id) if job_id not in (None, '') else None,
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/unified-migration/dry-run',
|
||||
methods=['POST'],
|
||||
|
||||
Reference in new issue
Block a user