feat(shipping_notice): 新增货代订单全流程业务模块及配套基建

本次提交新增货代订单处理全流程的完整业务能力、数据库迁移与测试用例:
1.  统一追加式审计事件体系,支持全链路不可篡改的业务追溯
2.  货代任务撤销、版本替代管控逻辑,规范已上传订单的合规版本更替
3.  订单抽取路由审计、模板自动冻结资格、路由计数等核心业务基建
4.  EML订单补充表解析契约与合并逻辑,完善订单补全能力
5.  Chatflow只读能力令牌校验机制,保障工具调用安全
6.  人工复核证据校验服务,规范人工审核的证据留存
所有变更均配套完整的单元测试与迁移契约测试,支持受控回退
This commit is contained in:
hugo committed 2026-07-28 08:56:58 +08:00
1 parent 90f77634d6
commit 1f3ecb87b7
128 files changed
+3635 -2074

No files matched your search

@@ -3,7 +3,7 @@ backend/app/services/shipping_notice/intake_service.py
用途:发货通知接入记录(ShippingNoticeIntake)业务编排(含重复决策投影与权限)。
依赖:file_assets.service、intake_parse_workflow、order_extraction、jobs.queue、models、
duplicate_detection、attachment_integrity。
duplicate_detection、attachment_integrity、document_layout 生命周期模型。
逻辑:由 workspace API 与 chat action 调用;解析 Job 由 intake_parse_workflow 执行;
创建 Intake:SAVEPOINT 插入 + IntegrityError 回落,mutate/enqueue 前 FOR UPDATE;
cancelled/expired 拒绝复活;重投仅复用 queued Job(与 retry 同口径);
@@ -24,7 +24,14 @@ from app.core.errors import ConflictError, ForbiddenError, NotFoundError, Valida
from app.core.response import utc_iso
from app.jobs.queue import QUEUED_ONLY_STATUSES, enqueue
from app.jobs.types import JobType
from app.models import FileAsset, ShippingNoticeIntake, ShippingTask, User
from app.models import (
FileAsset,
ShippingDocumentLayoutVersion,
ShippingNoticeDocument,
ShippingNoticeIntake,
ShippingTask,
User,
)
from app.services.file_assets.service import get_asset_for_user, mark_asset_referenced
from app.services.shipping_notice.attachment_integrity import is_attachment_parse_incomplete
@@ -180,6 +187,7 @@ def serialize_intake(
parse_summary = structured if include_parse_texts else _lean_parse_summary(structured)
documents = list_intake_documents(int(intake.id), include_text=include_parse_texts)
candidates = list_intake_candidates(int(intake.id))
layout_summary = _serialize_intake_layout_summary(int(intake.id))
payload: dict[str, Any] = {
'intake_no': intake.intake_no,
'asset_no': asset.asset_no if asset else None,
@@ -200,6 +208,8 @@ def serialize_intake(
'candidates': candidates,
'document_count': len(documents),
'candidate_count': len(candidates),
'layout_status': layout_summary['status'],
'layout_summary': layout_summary,
'warnings': list(intake.parse_warnings_json or []),
'error_code': intake.error_code,
'error_message': intake.error_message,
@@ -215,6 +225,48 @@ def serialize_intake(
return payload
def _serialize_intake_layout_summary(intake_id: int) -> dict[str, Any]:
"""
汇总 Intake 下已调度的文档版面任务,供聊天页判断订单识别是否可启动。
Args:
intake_id: ShippingNoticeIntake 主键;只统计其派生 Document 的布局版本。
Returns:
脱敏状态与数量。processing 表示仍有 queued/running;completed 表示所有任务已终结;
not_required 表示没有独立布局任务,不阻断文本或 Dify 兜底。
"""
rows = (
db.session.query(ShippingDocumentLayoutVersion.status)
.join(
ShippingNoticeDocument,
ShippingNoticeDocument.id == ShippingDocumentLayoutVersion.document_id,
)
.filter(ShippingNoticeDocument.intake_id == int(intake_id))
.all()
)
counts = {
'queued': 0,
'running': 0,
'ready': 0,
'needs_review': 0,
'failed': 0,
'unsupported': 0,
}
for (raw_status,) in rows:
status = str(raw_status or '')
if status in counts:
counts[status] += 1
total = sum(counts.values())
if counts['queued'] or counts['running']:
status = 'processing'
elif total:
status = 'completed'
else:
status = 'not_required'
return {'status': status, 'total': total, **counts}
def get_intake_for_user(intake_no: str, user_id: int) -> ShippingNoticeIntake:
"""按编号查询当前用户的接入记录。"""
normalized = str(intake_no or '').strip().upper()