feat(shipping_notice): 新增货代订单全流程业务模块及配套基建
本次提交新增货代订单处理全流程的完整业务能力、数据库迁移与测试用例: 1. 统一追加式审计事件体系,支持全链路不可篡改的业务追溯 2. 货代任务撤销、版本替代管控逻辑,规范已上传订单的合规版本更替 3. 订单抽取路由审计、模板自动冻结资格、路由计数等核心业务基建 4. EML订单补充表解析契约与合并逻辑,完善订单补全能力 5. Chatflow只读能力令牌校验机制,保障工具调用安全 6. 人工复核证据校验服务,规范人工审核的证据留存 所有变更均配套完整的单元测试与迁移契约测试,支持受控回退
This commit is contained in:
1 parent
90f77634d6
commit
1f3ecb87b7
128 files changed
+3635
-2074
No files matched your search
@@ -20,6 +20,7 @@ from app.core.errors import ConflictError, ForbiddenError, NotFoundError, Valida
|
||||
from app.models import (
|
||||
FileAsset,
|
||||
ShippingBatch,
|
||||
ShippingDocumentLayoutVersion,
|
||||
ShippingNoticeCandidate,
|
||||
ShippingNoticeDocument,
|
||||
ShippingNoticeIntake,
|
||||
@@ -51,6 +52,62 @@ def _make_upload(content: bytes = b'customer order line', filename: str = 'notic
|
||||
return FileStorage(stream=BytesIO(content), filename=filename, content_type='text/plain')
|
||||
|
||||
|
||||
def test_intake_status_exposes_layout_lifecycle_without_blocking_terminal_fallback(app, shipping_user):
|
||||
"""
|
||||
Intake 状态须区分附件预解析与版面任务;只有 queued/running 阻断发送。
|
||||
|
||||
关键断言:无任务为 not_required;活动任务为 processing;ready/failed 等终态统一为 completed,
|
||||
使前端继续轮询活动任务但保留文本/Dify 兜底能力。
|
||||
"""
|
||||
from app.services.shipping_notice.intake_service import serialize_intake
|
||||
|
||||
with app.app_context():
|
||||
asset = FileAsset(
|
||||
asset_no='FA-LAYOUT-STATUS-001', owner_user_id=shipping_user.id,
|
||||
original_filename='layout-status.eml', storage_provider='minio',
|
||||
storage_bucket='hxops-file-assets', storage_key='temporary/layout-status.eml',
|
||||
content_hash='a' * 64, file_size=100, mime_type='message/rfc822',
|
||||
upload_status='ready', lifecycle_status='temporary',
|
||||
)
|
||||
db.session.add(asset)
|
||||
db.session.flush()
|
||||
intake = ShippingNoticeIntake(
|
||||
intake_no='SNI-LAYOUT-STATUS-001', asset_id=asset.id, user_id=shipping_user.id,
|
||||
purpose='shipping_notice', parse_status='parsed', parser_version='v6',
|
||||
)
|
||||
db.session.add(intake)
|
||||
db.session.flush()
|
||||
document = ShippingNoticeDocument(
|
||||
intake_id=intake.id, document_type='attachment', attachment_key='order.pdf',
|
||||
filename='order.pdf', classification='order_notice', parse_status='parsed',
|
||||
content_hash='b' * 64,
|
||||
)
|
||||
db.session.add(document)
|
||||
db.session.flush()
|
||||
|
||||
# 没有独立版面任务时不阻断普通文本附件。
|
||||
assert serialize_intake(intake, asset=asset)['layout_status'] == 'not_required'
|
||||
|
||||
version = ShippingDocumentLayoutVersion(
|
||||
document_id=document.id, version=1, status='queued', source_content_hash='b' * 64,
|
||||
parser_key='mineru:test', parser_name='mineru', contract_version='shipping_document_layout.v1',
|
||||
issues_json=[],
|
||||
)
|
||||
db.session.add(version)
|
||||
db.session.flush()
|
||||
processing = serialize_intake(intake, asset=asset)
|
||||
assert processing['layout_status'] == 'processing'
|
||||
assert processing['layout_summary']['queued'] == 1
|
||||
|
||||
# 失败也是终态;订单抽取可以继续使用文本或 Dify 兜底。
|
||||
version.status = 'failed'
|
||||
version.finished_at = datetime.utcnow()
|
||||
db.session.flush()
|
||||
completed = serialize_intake(intake, asset=asset)
|
||||
assert completed['layout_status'] == 'completed'
|
||||
assert completed['layout_summary']['failed'] == 1
|
||||
|
||||
|
||||
def test_candidate_review_duplicate_api_and_access_guards(app, client):
|
||||
"""Candidate API 应支持修订、刷新和决策,并阻止越权或已消费候选修改。"""
|
||||
from app.core.auth.jwt import issue_local_access_token
|
||||
|
||||
Reference in new issue
Block a user