feat(shipping-notice): 落地字段资产治理与唯一 Schema,自动建单随版本冻结

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-07-29 16:23:15 +08:00
1 parent b7307fc573
commit 3a1dbf7ce5
144 files changed
+15167 -4480

No files matched your search

@@ -17,7 +17,7 @@ from flask import current_app
from sqlalchemy import and_, func, or_, update
from app.extensions import db
from app.models import ShippingDocumentLayoutVersion, ShippingNoticeDocument
from app.models import ShippingDocumentLayoutVersion, ShippingNoticeDocument, ShippingNoticeIntake
LAYOUT_PARSER_NAME = 'mineru'
@@ -156,6 +156,27 @@ def schedule_layout_version(
source_hash = str(document.content_hash or '').strip().lower()
if len(source_hash) != 64:
return None
# Identical files from the same owner reuse a completed layout rather than waiting for MinerU again.
owner_id = db.session.query(ShippingNoticeIntake.user_id).filter(
ShippingNoticeIntake.id == document.intake_id,
).scalar()
if not force:
reusable_from_owner = (
ShippingDocumentLayoutVersion.query
.join(ShippingNoticeDocument, ShippingNoticeDocument.id == ShippingDocumentLayoutVersion.document_id)
.join(ShippingNoticeIntake, ShippingNoticeIntake.id == ShippingNoticeDocument.intake_id)
.filter(
ShippingNoticeIntake.user_id == owner_id,
ShippingNoticeDocument.content_hash == source_hash,
ShippingDocumentLayoutVersion.parser_key == current_layout_parser_key(),
ShippingDocumentLayoutVersion.status.in_(tuple(CURRENT_LAYOUT_STATUSES)),
)
.order_by(ShippingDocumentLayoutVersion.finished_at.desc(), ShippingDocumentLayoutVersion.id.desc())
.first()
)
if reusable_from_owner is not None:
document.current_layout_version_id = reusable_from_owner.id
return reusable_from_owner
active = ShippingDocumentLayoutVersion.query.filter(
ShippingDocumentLayoutVersion.document_id == int(document.id),
ShippingDocumentLayoutVersion.status.in_({'queued', 'running'}),