feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置 新增收料报表管理的前端页面、路由和侧边栏入口 新增后端收料报表配置接口、数据库模型和RPA脚本 优化发货通知流程的重试策略,将shipping相关job默认不自动重试 移除废弃的库存源确认相关逻辑,更新流程门禁规则 重构订单模板的值适配器模块,新增坐标OCR值适配器 清理前端shipping菜单和action的废弃选项 更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
1 parent
260465b72d
commit
1b6483a4ea
466 files changed
+32115
-33796
No files matched your search
@@ -165,6 +165,22 @@ def update_shipping_inventory_source(source_id: int):
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/sources/<int:source_id>/receipt-report-config', methods=['GET'])
|
||||
@require_admin
|
||||
def get_shipping_receipt_report_config(source_id: int):
|
||||
"""读取站点独立收料报表配置;库存配置和收料配置永不混写。"""
|
||||
return _ok(shipping_inventory_service.get_receipt_report_config(source_id))
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/sources/<int:source_id>/receipt-report-config', methods=['PUT'])
|
||||
@require_admin
|
||||
def save_shipping_receipt_report_config(source_id: int):
|
||||
"""保存独立收料报表配置,并由服务记录可追溯的前后快照审计。"""
|
||||
return _ok(shipping_inventory_service.save_receipt_report_config(
|
||||
source_id, request.get_json(silent=True) or {}, actor_id=_actor_id(),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/sources/<int:source_id>/bind-parsing-profile', methods=['POST'])
|
||||
@require_admin
|
||||
def bind_shipping_inventory_source_parsing_profile(source_id: int):
|
||||
|
||||
@@ -3,10 +3,10 @@ backend/app/api/admin/shipping_order_document_profiles.py
|
||||
|
||||
用途:提供订单文档模板 Profile 的管理员版本治理 API。
|
||||
依赖:admin blueprint、require_admin、order_document_profile_service、
|
||||
order_document_profile_preview_service、order_document_profile_xfa_preview_service、
|
||||
order_document_profile_xfa_automark_service、order_document_profile_visual_binding_service、
|
||||
order_document_profile_preview_service、
|
||||
order_document_profile_pdf_automark_service、
|
||||
order_profile_unified_migration。
|
||||
逻辑:路由只转换请求和操作者;版本、Schema、字段、XFA 合成预览、OCR 自动标记、
|
||||
逻辑:路由只转换请求和操作者;版本、Schema、字段、原生 PDF 预览、统一自动标记、
|
||||
统一迁移与发布门禁由服务层执行。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -25,8 +25,6 @@ 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_pdf_automark_service as pdf_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
|
||||
@@ -35,8 +33,8 @@ from app.services.shipping_notice import order_document_profile_usage_service as
|
||||
from app.services.shipping_notice import order_document_profile_validation_service as validation_service
|
||||
from app.services.shipping_notice import order_document_profile_publish_check_service as publish_check_service
|
||||
from app.services.shipping_notice import order_document_profile_version_service as version_service
|
||||
from app.services.shipping_notice import order_document_profile_visual_binding_service as visual_binding_service
|
||||
from app.services.shipping_notice import order_profile_unified_migration as unified_migration
|
||||
from app.services.shipping_notice.order_profile_value_adapter import get_runtime_value_adapter
|
||||
|
||||
|
||||
def _actor_id() -> int | None:
|
||||
@@ -57,6 +55,15 @@ def _private_ok(data, *, status: int = 200):
|
||||
return response, response_status
|
||||
|
||||
|
||||
def _sample_mapping_adapter(document_id: int):
|
||||
"""从共同视觉 Layout 解析当前样本的末端值源 adapter。"""
|
||||
document = service._require_sample_document(document_id)
|
||||
return get_runtime_value_adapter(
|
||||
layout=service._document_layout(document),
|
||||
selected_profile=None,
|
||||
)
|
||||
|
||||
|
||||
def _query_int(name: str, default: int, *, minimum: int | None = None, maximum: int | None = None) -> int:
|
||||
"""读取可选整数查询参数,并做受控范围校验。"""
|
||||
raw = request.args.get(name)
|
||||
@@ -244,9 +251,20 @@ def update_order_document_profile(profile_id: int):
|
||||
if profile_row is not None and isinstance(profile_row.definition_json, dict)
|
||||
else {}
|
||||
)
|
||||
# [STEP] 变更 split_rules 强制校验 xfa_split_rule_edit(注释与实现一致)。
|
||||
if service.split_rules_definition_changed(previous_def, incoming_def if isinstance(incoming_def, dict) else {}):
|
||||
_require_xfa_split_edit_permission()
|
||||
# [STEP] 末端映射规则变化由当前样本 adapter 判定,Route 不识别文件格式。
|
||||
previous_adapter = get_runtime_value_adapter(
|
||||
layout=None,
|
||||
selected_profile={'definition': previous_def} if previous_def else None,
|
||||
)
|
||||
incoming_adapter = get_runtime_value_adapter(
|
||||
layout=None,
|
||||
selected_profile={'definition': incoming_def} if incoming_def else None,
|
||||
)
|
||||
if (
|
||||
previous_adapter.mapping_rules_changed(previous_def, incoming_def if isinstance(incoming_def, dict) else {})
|
||||
or incoming_adapter.mapping_rules_changed(previous_def, incoming_def if isinstance(incoming_def, dict) else {})
|
||||
):
|
||||
_require_value_mapping_edit_permission()
|
||||
return _ok(service.save_draft(
|
||||
data, actor_id=_actor_id(), profile_id=profile_id, **_write_context(data), enforce_lease=True,
|
||||
))
|
||||
@@ -428,8 +446,10 @@ def confirm_order_document_profile_publish_check(profile_id: int, report_no: str
|
||||
|
||||
data = request.get_json(silent=True) or {}
|
||||
entity = db.session.get(ShippingOrderDocumentProfile, int(profile_id))
|
||||
definition = dict((entity.definition_json or {}) if entity is not None else {})
|
||||
if str(definition.get('template_mode') or '') == 'xfa_dataset':
|
||||
value_adapter = service._publish_value_adapter(
|
||||
service._profile_template_mode(entity) if entity is not None else 'coordinate',
|
||||
)
|
||||
if value_adapter.requires_split_rule_publish_permission:
|
||||
user = getattr(g, 'current_user', None)
|
||||
if not bool(user and user.has_feature_permission('shipping_notice.xfa_split_rule_publish')):
|
||||
raise ForbiddenError(
|
||||
@@ -534,31 +554,6 @@ def get_order_document_profile_preview_page(profile_id: int, page_no: int):
|
||||
return response
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/order-document-profiles/<int:profile_id>/xfa-pdf-preview', methods=['POST'])
|
||||
@require_admin
|
||||
def authorize_order_document_profile_xfa_pdf_preview(profile_id: int):
|
||||
"""兼容旧 XFA 路由:签发统一编辑画布的单用途原 PDF 令牌。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
return _private_ok(service.authorize_pdf_preview(
|
||||
profile_id, document_id=data.get('document_id'), actor_id=_actor_id(),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/order-document-profiles/<int:profile_id>/xfa-pdf-preview', methods=['GET'])
|
||||
@require_admin
|
||||
def get_order_document_profile_xfa_pdf_preview(profile_id: int):
|
||||
"""兼容旧 XFA 路由:消费短时令牌返回原 PDF,仅供 PDF.js 内存渲染。"""
|
||||
pdf = service.read_pdf_preview(
|
||||
token=str(request.args.get('preview_token') or ''), actor_id=_actor_id(),
|
||||
)
|
||||
response = send_file(io.BytesIO(pdf), mimetype='application/pdf', 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'
|
||||
response.headers['Content-Disposition'] = 'inline'
|
||||
return response
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/order-document-profiles/<int:profile_id>/pdf-preview', methods=['POST'])
|
||||
@require_admin
|
||||
def authorize_order_document_profile_pdf_preview(profile_id: int):
|
||||
@@ -694,16 +689,17 @@ def run_order_document_profile_current_sample(profile_id: int):
|
||||
), status=201)
|
||||
|
||||
|
||||
@admin_bp.route('/shipping-notice/order-document-profiles/<int:profile_id>/validation-runs/profile-identity-signature', methods=['POST'])
|
||||
@admin_bp.route('/shipping-notice/order-document-profiles/<int:profile_id>/validation-runs/layout-signature', methods=['POST'])
|
||||
@require_admin
|
||||
def run_order_document_profile_layout_signature(profile_id: int):
|
||||
def run_order_document_profile_identity_signature(profile_id: int):
|
||||
"""
|
||||
生成当前草稿的版面签名 ValidationRun,并更新 Profile 轻量签名引用。
|
||||
生成当前草稿的统一身份签名 ValidationRun,并更新 Profile 轻量签名引用。
|
||||
|
||||
前端不得提交 Matcher 分数或签名正文;服务端仅消费租约与 operation_id。
|
||||
"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
return _ok(validation_service.run_layout_signature(
|
||||
return _ok(validation_service.run_profile_identity_signature(
|
||||
profile_id, data=data, actor_id=_actor_id(), **_write_context(data),
|
||||
), status=201)
|
||||
|
||||
@@ -810,31 +806,35 @@ def approve_order_document_profile_test_suite(suite_id: int):
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/field-tree',
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/value-adapter/field-tree',
|
||||
methods=['GET'],
|
||||
)
|
||||
@require_admin
|
||||
def get_order_document_profile_sample_xfa_field_tree(document_id: int):
|
||||
"""返回 XFA 字段树安全投影;不含 XML/PDF 正文。"""
|
||||
return _private_ok(service.get_xfa_field_tree(document_id, actor_id=_actor_id()))
|
||||
def get_order_document_profile_sample_value_field_tree(document_id: int):
|
||||
"""返回当前值源字段树安全投影;不含原始正文。"""
|
||||
return _private_ok(_sample_mapping_adapter(document_id).mapping_field_tree(
|
||||
document_id=document_id, actor_id=_actor_id(),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/collections',
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/value-adapter/collections',
|
||||
methods=['GET'],
|
||||
)
|
||||
@require_admin
|
||||
def get_order_document_profile_sample_xfa_collections(document_id: int):
|
||||
"""返回 XFA 重复集合候选摘要。"""
|
||||
return _private_ok(service.get_xfa_collections(document_id, actor_id=_actor_id()))
|
||||
def get_order_document_profile_sample_value_collections(document_id: int):
|
||||
"""返回当前值源的重复集合候选摘要。"""
|
||||
return _private_ok(_sample_mapping_adapter(document_id).mapping_collections(
|
||||
document_id=document_id, actor_id=_actor_id(),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/xfa/value-preview',
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/value-adapter/value-preview',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def preview_order_document_profile_sample_xfa_value(document_id: int):
|
||||
def preview_order_document_profile_sample_value(document_id: int):
|
||||
"""
|
||||
按 path_id 返回样本值投影。
|
||||
|
||||
@@ -845,8 +845,8 @@ def preview_order_document_profile_sample_xfa_value(document_id: int):
|
||||
reveal = bool(data.get('reveal'))
|
||||
if reveal:
|
||||
_require_audit_sensitive_read_permission()
|
||||
return _private_ok(service.preview_xfa_sample_value(
|
||||
document_id,
|
||||
return _private_ok(_sample_mapping_adapter(document_id).mapping_value_preview(
|
||||
document_id=document_id,
|
||||
path_id=str(data.get('path_id') or ''),
|
||||
actor_id=_actor_id(),
|
||||
include_full_value=reveal,
|
||||
@@ -854,82 +854,26 @@ 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',
|
||||
'/shipping-notice/order-document-profile-samples/<int:document_id>/value-adapter/split-rules/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'],
|
||||
)
|
||||
@require_admin
|
||||
def preview_order_document_profile_sample_xfa_split_rules(document_id: int):
|
||||
def preview_order_document_profile_sample_value_split_rules(document_id: int):
|
||||
"""
|
||||
预览拆分规则执行结果并签发确认令牌。
|
||||
|
||||
核心逻辑:须 xfa_split_rule_preview;完整 mapped/raw 值另需 audit_sensitive_read,
|
||||
且完整值路径强制写访问审计。
|
||||
"""
|
||||
_require_xfa_split_preview_permission()
|
||||
_require_value_mapping_preview_permission()
|
||||
data = request.get_json(silent=True) or {}
|
||||
rule_set = data.get('rule_set') if isinstance(data.get('rule_set'), dict) else {}
|
||||
profile_id = data.get('profile_id')
|
||||
reveal = bool(data.get('reveal'))
|
||||
if reveal:
|
||||
_require_audit_sensitive_read_permission()
|
||||
return _private_ok(service.preview_xfa_split_rules(
|
||||
document_id,
|
||||
return _private_ok(_sample_mapping_adapter(document_id).mapping_split_preview(
|
||||
document_id=document_id,
|
||||
path_id=str(data.get('path_id') or ''),
|
||||
rule_set=rule_set,
|
||||
actor_id=_actor_id(),
|
||||
@@ -940,46 +884,46 @@ def preview_order_document_profile_sample_xfa_split_rules(document_id: int):
|
||||
|
||||
|
||||
def _require_audit_sensitive_read_permission() -> None:
|
||||
"""完整 XFA 样本/拆分值读取需 shipping_notice.audit_sensitive_read。"""
|
||||
"""完整值源样本/拆分值读取需 shipping_notice.audit_sensitive_read。"""
|
||||
user = getattr(g, 'current_user', None)
|
||||
if not bool(user and user.has_feature_permission('shipping_notice.audit_sensitive_read')):
|
||||
raise ForbiddenError(
|
||||
'XFA sensitive value read permission is required',
|
||||
'Sensitive value read permission is required',
|
||||
code='SHIPPING.ORDER_DOCUMENT_PROFILE_XFA_VALUE_FORBIDDEN',
|
||||
details={'permission': 'shipping_notice.audit_sensitive_read'},
|
||||
)
|
||||
|
||||
|
||||
def _require_xfa_split_preview_permission() -> None:
|
||||
"""拆分规则预览/建议需 xfa_split_rule_preview 权限(admin 默认具备)。"""
|
||||
def _require_value_mapping_preview_permission() -> None:
|
||||
"""值源映射预览/建议需既有拆分预览权限(admin 默认具备)。"""
|
||||
user = getattr(g, 'current_user', None)
|
||||
if not bool(user and user.has_feature_permission('shipping_notice.xfa_split_rule_preview')):
|
||||
raise ForbiddenError(
|
||||
'XFA split rule preview permission is required',
|
||||
'Value mapping preview permission is required',
|
||||
code='SHIPPING.ORDER_DOCUMENT_PROFILE_XFA_VALUE_FORBIDDEN',
|
||||
details={'permission': 'shipping_notice.xfa_split_rule_preview'},
|
||||
)
|
||||
|
||||
|
||||
def _require_xfa_split_edit_permission() -> None:
|
||||
"""变更拆分规则需 shipping_notice.xfa_split_rule_edit。"""
|
||||
def _require_value_mapping_edit_permission() -> None:
|
||||
"""变更末端映射拆分规则需既有编辑权限。"""
|
||||
user = getattr(g, 'current_user', None)
|
||||
if not bool(user and user.has_feature_permission('shipping_notice.xfa_split_rule_edit')):
|
||||
raise ForbiddenError(
|
||||
'XFA split rule edit permission is required',
|
||||
'Value mapping edit permission is required',
|
||||
code='SHIPPING.ORDER_DOCUMENT_PROFILE_XFA_SPLIT_EDIT_FORBIDDEN',
|
||||
details={'permission': 'shipping_notice.xfa_split_rule_edit'},
|
||||
)
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/split-rules/suggest',
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/value-adapter/split-rules/suggest',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def suggest_order_document_profile_xfa_split_rules(profile_id: int):
|
||||
def suggest_order_document_profile_value_split_rules(profile_id: int):
|
||||
"""生成 MATNR 类拆分规则建议;不写 Draft、不 commit。"""
|
||||
_require_xfa_split_preview_permission()
|
||||
_require_value_mapping_preview_permission()
|
||||
data = request.get_json(silent=True) or {}
|
||||
return _private_ok(suggestion_service.suggest_xfa_split_rules(
|
||||
profile_id,
|
||||
@@ -991,34 +935,11 @@ def suggest_order_document_profile_xfa_split_rules(profile_id: int):
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/unified-mapping/suggest',
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/value-adapter/split-rules/validate',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def suggest_order_document_profile_xfa_unified_mapping(profile_id: int):
|
||||
"""统一返回视觉 + 拆分规则建议;不写 Draft、不 commit。"""
|
||||
_require_xfa_split_preview_permission()
|
||||
data = request.get_json(silent=True) or {}
|
||||
bbox = data.get('normalized_bbox') if isinstance(data.get('normalized_bbox'), dict) else {}
|
||||
return _private_ok(suggestion_service.suggest_xfa_unified_mapping(
|
||||
profile_id,
|
||||
document_id=data.get('document_id'),
|
||||
page_no=data.get('page_no', 1),
|
||||
normalized_bbox=bbox,
|
||||
path_id=str(data.get('path_id') or '').strip() or None,
|
||||
actor_id=_actor_id(),
|
||||
include_visual=bool(data.get('include_visual', True)),
|
||||
include_split=bool(data.get('include_split', True)),
|
||||
write_audit=False,
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/split-rules/validate',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def validate_order_document_profile_xfa_split_rules(profile_id: int):
|
||||
def validate_order_document_profile_value_split_rules(profile_id: int):
|
||||
"""校验 Profile 拆分规则契约与 Schema 映射;不持久化。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
split_rules = data.get('split_rules')
|
||||
@@ -1027,78 +948,16 @@ def validate_order_document_profile_xfa_split_rules(profile_id: int):
|
||||
'split_rules must be a list',
|
||||
code='SHIPPING.ORDER_DOCUMENT_PROFILE_INVALID',
|
||||
)
|
||||
return _private_ok(service.validate_xfa_split_rules(
|
||||
profile_id,
|
||||
profile = service._profile(profile_id)
|
||||
return _private_ok(get_runtime_value_adapter(
|
||||
layout=None, selected_profile={'definition': profile.definition_json},
|
||||
).mapping_split_validation(
|
||||
profile_id=profile_id,
|
||||
split_rules=split_rules,
|
||||
actor_id=_actor_id(),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/visual-bindings/suggest',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def suggest_order_document_profile_xfa_visual_bindings(profile_id: int):
|
||||
"""为页面区域生成 XFA 视觉绑定候选;歧义不自动确认。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
bbox = data.get('normalized_bbox') if isinstance(data.get('normalized_bbox'), dict) else {}
|
||||
return _private_ok(visual_binding_service.suggest_xfa_visual_bindings(
|
||||
profile_id,
|
||||
document_id=data.get('document_id'),
|
||||
page_no=data.get('page_no', 1),
|
||||
normalized_bbox=bbox,
|
||||
actor_id=_actor_id(),
|
||||
request_id=getattr(g, 'request_id', None),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/visual-bindings/<string:binding_id>/confirm',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def confirm_order_document_profile_xfa_visual_binding(profile_id: int, binding_id: str):
|
||||
"""管理员确认视觉绑定;须携带合成预览 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 {}
|
||||
return _private_ok(visual_binding_service.confirm_xfa_visual_binding(
|
||||
profile_id,
|
||||
binding_id,
|
||||
visual_binding=visual,
|
||||
path_id=str(data.get('path_id') or '').strip() or None,
|
||||
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),
|
||||
preview_render_checksum=str(data.get('preview_render_checksum') or '').strip() or None,
|
||||
render_mode=str(data.get('render_mode') or '').strip() or None,
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/xfa/visual-bindings/<string:binding_id>/reject',
|
||||
methods=['POST'],
|
||||
)
|
||||
@require_admin
|
||||
def reject_order_document_profile_xfa_visual_binding(profile_id: int, binding_id: str):
|
||||
"""管理员驳回视觉绑定建议;写 before/after 审计。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
ctx = _write_context(data)
|
||||
return _private_ok(visual_binding_service.reject_xfa_visual_binding(
|
||||
profile_id,
|
||||
binding_id,
|
||||
reason_code=str(data.get('reason_code') or '').strip() or None,
|
||||
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),
|
||||
))
|
||||
|
||||
|
||||
@admin_bp.route(
|
||||
'/shipping-notice/order-document-profiles/<int:profile_id>/pdf-automark',
|
||||
methods=['POST'],
|
||||
@@ -1131,97 +990,6 @@ def get_order_document_profile_pdf_automark_job(profile_id: int, job_id: int):
|
||||
return _private_ok(pdf_automark_service.get_pdf_automark_job(job_id, profile_id=profile_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