feat(shipping-notice): 添加订单文档 Profile 盲测集和样本管理功能,支持创建、执行和批准盲测,增强订单冻结和库存核验功能
This commit is contained in:
1 parent
c35223d49d
commit
abd8fc1e16
98 files changed
+4629
-528
No files matched your search
@@ -44,6 +44,7 @@ ACTIVE_INTAKE_STATUSES = frozenset(
|
||||
)
|
||||
|
||||
_DUPLICATE_RESOLUTIONS = frozenset({'open_existing', 'create_revision', 'force_create'})
|
||||
ORDER_DOCUMENT_PROFILE_SAMPLE_PURPOSE = 'order_document_profile_sample'
|
||||
|
||||
|
||||
def _parser_version() -> str:
|
||||
@@ -284,6 +285,29 @@ def create_shipping_notice_intake(
|
||||
3. parsed/consumed/queued/parsing 直接返回;cancelled/expired(含过期时间到期)冲突拒绝;
|
||||
4. 仅 created/parse_failed 持锁重投:enqueue(commit=False) 并绑定 parse_job_id。
|
||||
"""
|
||||
return _create_intake_for_asset(
|
||||
user_id=user_id, asset_no=asset_no, purpose='shipping_notice',
|
||||
conversation_id=conversation_id,
|
||||
)
|
||||
|
||||
|
||||
def create_order_document_profile_sample_intake(*, user_id: int, asset_no: str) -> dict[str, Any]:
|
||||
"""
|
||||
为订单文档模板页创建隔离的 PDF/EML 样本解析 Intake。
|
||||
|
||||
AI/调用方触发时机:仅管理员在模板页上传用于配置/复核的文件后调用。该 Intake
|
||||
不绑定会话,后续预解析只生成 Document 和布局候选,禁止进入候选、建单或 Dify 链路。
|
||||
"""
|
||||
return _create_intake_for_asset(
|
||||
user_id=user_id, asset_no=asset_no, purpose=ORDER_DOCUMENT_PROFILE_SAMPLE_PURPOSE,
|
||||
conversation_id=None,
|
||||
)
|
||||
|
||||
|
||||
def _create_intake_for_asset(
|
||||
*, user_id: int, asset_no: str, purpose: str, conversation_id: str | None,
|
||||
) -> dict[str, Any]:
|
||||
"""按受控 purpose 创建幂等 Intake;模板样本与业务发货通知共享基础设施但隔离用途。"""
|
||||
asset = get_asset_for_user(asset_no, user_id)
|
||||
if str(asset.upload_status or '') != 'ready':
|
||||
raise ValidationError(code='FILE_ASSET.INVALID_STATUS', message='文件尚未上传完成')
|
||||
@@ -291,8 +315,14 @@ def create_shipping_notice_intake(
|
||||
raise ValidationError(code='FILE_ASSET.EXPIRED', message='文件资产已过期')
|
||||
|
||||
parser_version = _parser_version()
|
||||
purpose = 'shipping_notice'
|
||||
conv = str(conversation_id or '').strip() or None
|
||||
if purpose == ORDER_DOCUMENT_PROFILE_SAMPLE_PURPOSE:
|
||||
extension = str(asset.extension or '').strip().lower()
|
||||
if extension not in {'pdf', 'eml'}:
|
||||
raise ValidationError(
|
||||
code='SHIPPING.ORDER_DOCUMENT_PROFILE_SAMPLE_FILE_TYPE_INVALID',
|
||||
message='Only PDF and EML files can be order profile samples',
|
||||
)
|
||||
|
||||
# [STEP 1] 持锁定位或创建 Intake
|
||||
intake = _lock_intake_for_asset_purpose_parser(
|
||||
@@ -373,7 +403,7 @@ def create_shipping_notice_intake(
|
||||
domain=SHIPPING_NOTICE_JOB_DOMAIN,
|
||||
business_ref=intake.intake_no,
|
||||
created_by_id=user_id,
|
||||
message='等待预解析发货通知',
|
||||
message=('等待解析订单模板样本' if purpose == ORDER_DOCUMENT_PROFILE_SAMPLE_PURPOSE else '等待预解析发货通知'),
|
||||
max_attempts=int(current_app.config.get('SHIPPING_NOTICE_PARSE_MAX_ATTEMPTS', 3) or 3),
|
||||
dedupe_active=True,
|
||||
dedupe_statuses=QUEUED_ONLY_STATUSES,
|
||||
|
||||
Reference in new issue
Block a user