feat(shipping-notice): 新增发货通知重复检测与处理接口,支持重复决策保存与重新执行检测

This commit is contained in:
hugo committed 2026-07-14 21:12:36 +08:00
1 parent 729546a7b7
commit ceb49461e8
72 files changed
+14270 -460

No files matched your search

+23 -2
View File
@@ -3,7 +3,9 @@ backend/app/models/file_asset.py
用途:平台级通用文件资产模型,承载私有 MinIO 存储元数据与生命周期。
依赖:models.base.Base。
逻辑:由 file_assets.service 创建与更新;ShippingNoticeIntake 等业务通过 asset_id 引用。
逻辑:由 file_assets.service 创建与更新;ShippingNoticeIntake 经 asset_id 引用上传根资产;
EML 解析后的订单附件以 parent_asset_id 挂为 derived 子资产(阶段二);
派生资产对 (parent_asset_id, content_hash) 使用未删除行的部分唯一索引。
"""
from __future__ import annotations
@@ -11,7 +13,7 @@ from __future__ import annotations
from datetime import datetime
from typing import Optional
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, UniqueConstraint
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, UniqueConstraint, text
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
@@ -26,12 +28,31 @@ class FileAsset(Base):
Index('ix_file_assets_owner_content_hash', 'owner_user_id', 'content_hash'),
Index('ix_file_assets_lifecycle_expires', 'lifecycle_status', 'expires_at'),
Index('ix_file_assets_owner_created', 'owner_user_id', 'created_at'),
# 仅约束未删除派生资产,避免 soft-delete 永久阻塞同哈希重资产化
Index(
'uq_file_assets_parent_content_hash_alive',
'parent_asset_id',
'content_hash',
unique=True,
postgresql_where=text('deleted_at IS NULL AND parent_asset_id IS NOT NULL'),
sqlite_where=text('deleted_at IS NULL AND parent_asset_id IS NOT NULL'),
),
Index('ix_file_assets_parent_attachment_key', 'parent_asset_id', 'source_attachment_key'),
)
id: Mapped[int] = mapped_column(primary_key=True)
asset_no: Mapped[str] = mapped_column(String(64), nullable=False)
owner_user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), index=True, nullable=False)
tenant_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
# 派生资产:EML 根资产 → 附件 PDF 等子资产
parent_asset_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('file_assets.id'),
index=True,
nullable=True,
)
asset_role: Mapped[str] = mapped_column(String(32), default='upload', nullable=False)
# 派生资产首次落库时的 attachment_key;后续复用同哈希时不覆盖(当前来源见 Document.attachment_key)
source_attachment_key: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
original_filename: Mapped[str] = mapped_column(String(255), nullable=False)
storage_provider: Mapped[str] = mapped_column(String(32), default='minio', nullable=False)
storage_bucket: Mapped[str] = mapped_column(String(128), nullable=False)