feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理

清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
hugo committed 2026-08-26 02:47:07 +08:00
1 parent 7cfd5d167e
commit 1e5aedb9ed
235 files changed
+11394 -9613

No files matched your search

-2
View File
@@ -151,7 +151,6 @@ from app.models.shipping_receipt_report import (
from app.models.shipping_temporary_inventory import ShippingTemporaryInventorySession
from app.models.shipping_customer import (
ShippingBusinessSequence,
ShippingCase,
ShippingCustomer,
ShippingCustomerExternalRef,
ShippingCustomerIdentifier,
@@ -290,7 +289,6 @@ __all__ = [
'ShippingCustomerSiteIdentifier',
'ShippingCustomerImportBatch',
'ShippingCustomerImportRow',
'ShippingCase',
'ShippingBusinessSequence',
'ShippingCustomerShadowResolution',
'ShippingCustomerShadowMatch',
+12 -9
View File
@@ -25,6 +25,7 @@ from typing import List, Optional
from sqlalchemy import (
Boolean,
CheckConstraint,
Date,
DateTime,
Float,
ForeignKey,
@@ -54,6 +55,7 @@ class ShippingNotice(Base):
Index('ix_shipping_notices_conversation', 'conversation_id'),
Index('ix_shipping_notices_current_step', 'current_step'),
Index('ix_shipping_notices_upload_status', 'upload_status'),
Index('ix_shipping_notices_business_no', 'business_no'),
Index('ix_shipping_notices_inventory_source_code', 'inventory_source_code'),
Index('ix_shipping_notices_inventory_source_status', 'inventory_source_status'),
Index('ix_shipping_notices_inventory_routing_fingerprint', 'inventory_routing_fingerprint'),
@@ -70,11 +72,16 @@ class ShippingNotice(Base):
id: Mapped[int] = mapped_column(primary_key=True)
task_no: Mapped[str] = mapped_column(String(64), unique=True, index=True)
shipping_case_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('shipping_cases.id'),
index=True,
nullable=True,
customer_id: Mapped[Optional[int]] = mapped_column(
ForeignKey('shipping_customers.id'), index=True, nullable=True,
)
customer_name_snapshot: Mapped[Optional[str]] = mapped_column(String(200), nullable=True)
customer_short_code_snapshot: Mapped[Optional[str]] = mapped_column(String(6), nullable=True)
# 发货通知单的对外业务编号;同一 PO 的不同波次各自拥有独立编号。
business_no: Mapped[Optional[str]] = mapped_column(String(32), nullable=True, unique=True)
business_date: Mapped[Optional[datetime]] = mapped_column(Date, nullable=True)
business_sequence_value: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
business_numbering_rule_version: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
user_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), index=True, nullable=True)
conversation_id: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
source_type: Mapped[str] = mapped_column(String(32), default='manual')
@@ -234,11 +241,7 @@ class ShippingNotice(Base):
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
shipping_case: Mapped[Optional['ShippingCase']] = relationship(
'ShippingCase',
back_populates='tasks',
lazy='joined',
)
customer: Mapped[Optional['ShippingCustomer']] = relationship('ShippingCustomer', lazy='joined')
events: Mapped[List['ShippingTaskEvent']] = relationship(
'ShippingTaskEvent',
back_populates='task',
+2 -37
View File
@@ -1,9 +1,9 @@
"""
backend/app/models/shipping_customer.py
用途:货代标准客户、客户识别证据、业务单聚合与业务编号流水模型。
用途:货代标准客户、客户识别证据与业务编号流水模型。
依赖:models.base.Base、users、shipping_notices。
逻辑:客户主数据提供稳定身份;ShippingCase 聚合 Notice 修订链;流水表供后续编号服务原子递增。
逻辑:客户主数据提供稳定身份;发货通知自持履约事实;流水表供编号服务原子递增。
"""
from __future__ import annotations
@@ -55,7 +55,6 @@ class ShippingCustomer(Base):
back_populates='customer',
cascade='all, delete-orphan',
)
cases: Mapped[List['ShippingCase']] = relationship('ShippingCase', back_populates='customer')
merged_into_customer: Mapped[Optional['ShippingCustomer']] = relationship(
'ShippingCustomer',
remote_side='ShippingCustomer.id',
@@ -189,40 +188,6 @@ class ShippingCustomerSiteIdentifier(Base):
site: Mapped['ShippingCustomerSite'] = relationship('ShippingCustomerSite', back_populates='identifiers')
class ShippingCase(Base):
"""一票发货业务聚合;多个线性任务修订版本共享同一业务单。"""
__tablename__ = 'shipping_cases'
__table_args__ = (
Index('ix_shipping_cases_customer_created', 'customer_id', 'created_at'),
Index('ix_shipping_cases_status_created', 'status', 'created_at'),
UniqueConstraint('replaces_case_id', name='uq_shipping_cases_replaces_case_id'),
)
id: Mapped[int] = mapped_column(primary_key=True)
case_no: Mapped[str] = mapped_column(String(64), nullable=False, unique=True)
customer_id: Mapped[Optional[int]] = mapped_column(ForeignKey('shipping_customers.id'), nullable=True, index=True)
business_no: Mapped[Optional[str]] = mapped_column(String(32), nullable=True, unique=True)
customer_name_snapshot: Mapped[Optional[str]] = mapped_column(String(200), nullable=True)
customer_short_code_snapshot: Mapped[Optional[str]] = mapped_column(String(6), nullable=True)
business_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
sequence_value: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
numbering_rule_version: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
numbering_status: Mapped[str] = mapped_column(String(32), nullable=False, default='pending', server_default='pending')
status: Mapped[str] = mapped_column(String(32), nullable=False, default='open', server_default='open')
replaces_case_id: Mapped[Optional[int]] = mapped_column(ForeignKey('shipping_cases.id'), nullable=True)
created_by_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), 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)
customer: Mapped[Optional['ShippingCustomer']] = relationship('ShippingCustomer', back_populates='cases')
tasks: Mapped[List['ShippingNotice']] = relationship(
'ShippingNotice',
back_populates='shipping_case',
lazy='selectin',
)
class ShippingBusinessSequence(Base):
"""按业务类型、客户和 Asia/Shanghai 业务日期保存当前流水值。"""
@@ -4,7 +4,7 @@ models/shipping_excel_template.py
用途:定义版本化发货 Excel 模板及不可变 Notice 导出产物。
依赖:models.base.Base、库存源、订单 Schema、ShippingNotice 与库存快照模型。
逻辑:库存源只绑定已发布模板版本;每次生成均新增 Artifact 并锁定输入版本与校验和;
co8e9f0a1b2c 已删除 export artifact 的 batch_id 列。
co8e9f0a1b2c 已删除 export artifact 的 batch_id 列;Artifact 直接属于一张 Notice。
"""
from __future__ import annotations
@@ -12,7 +12,7 @@ from app.models.base import Base
class ShippingFreightCancellation(Base):
"""已上传旧 Notice 的撤销申请与货代回执;成功前新版本不得履约。"""
"""已上传旧 Notice 的撤销申请与外部撤销确认;成功前新版本不得履约。"""
__tablename__ = 'shipping_notice_freight_cancellations'
__table_args__ = (
+2 -1
View File
@@ -155,8 +155,9 @@ class ShippingUploadAttempt(Base):
finished_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
error_message: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
# 历史资产关联字段仅为兼容旧数据;新货代上传不写截图或文件证据。
evidence_asset_id: Mapped[Optional[int]] = mapped_column(ForeignKey('file_assets.id'), nullable=True)
# [BE-05] RPA 成功时持久化绿色 DOM 证据(kind/selector/observed_at/filename 等)。
# RPA 仅保存最小状态摘要(kind/selector/observed_at/filename 等),不保存截图或 DOM。
success_evidence_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
operator_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
freight_ref_no: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
@@ -1,7 +1,7 @@
"""
models/shipping_order_review_wave_line.py
用途:复核 Case 履约波次行归属(不可变),保证同一明细行最多进入一个 Task。
用途:复核 Case 履约波次行归属(不可变),保证同一明细行最多进入一张 Notice。
依赖:ShippingOrderReviewCase、ShippingNotice、ShippingOrderReviewConfirmedRevision。
逻辑:由 order_review_confirmation_service 在建波次/整单确认时写入;
(review_case_id, line_key) 数据库唯一约束防并发重复入波次。