feat(shipping-notice): 增加发货通知建单幂等性支持及内容哈希校验

This commit is contained in:
hugo committed 2026-07-14 00:28:52 +08:00
1 parent 0a9bd6415d
commit 143e054d86
39 files changed
+1750 -80

No files matched your search

+9 -1
View File
@@ -3,7 +3,7 @@ backend/app/models/shipping.py
用途:货代发货通知批次、任务、事件、库存文件与库存映射模型。
依赖:models.base.Base。
逻辑:ShippingTask 独立字段承载目的地与库存源身份;step_payload_json 仅保留候选/证据等辅助信息。
逻辑:ShippingBatch.create_idempotency_key 为建单幂等;ShippingTask.idempotency_key 为货代上传幂等,二者语义分离。
"""
from __future__ import annotations
@@ -24,6 +24,11 @@ class ShippingBatch(Base):
__table_args__ = (
Index('ix_shipping_batches_user_created', 'user_id', 'created_at'),
Index('ix_shipping_batches_conversation', 'conversation_id'),
UniqueConstraint(
'user_id',
'create_idempotency_key',
name='uq_shipping_batches_user_create_idempotency',
),
)
id: Mapped[int] = mapped_column(primary_key=True)
@@ -40,6 +45,7 @@ class ShippingBatch(Base):
nullable=True,
)
file_count: Mapped[int] = mapped_column(Integer, default=1)
create_idempotency_key: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
process_summary_json: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
@@ -65,6 +71,7 @@ class ShippingTask(Base):
Index('ix_shipping_tasks_inventory_source_status', 'inventory_source_status'),
Index('ix_shipping_tasks_inventory_routing_fingerprint', 'inventory_routing_fingerprint'),
Index('ix_shipping_tasks_inventory_rpa_consumed_run_no', 'inventory_rpa_consumed_run_no'),
Index('ix_shipping_tasks_user_source_content_hash', 'user_id', 'source_content_hash'),
)
id: Mapped[int] = mapped_column(primary_key=True)
@@ -75,6 +82,7 @@ class ShippingTask(Base):
source_type: Mapped[str] = mapped_column(String(32), default='manual')
source_file_name: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
source_file_type: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
source_content_hash: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
batch_index: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
batch_total: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)