feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -11,7 +11,7 @@ from __future__ import annotations
|
||||
from datetime import date, datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import Boolean, CheckConstraint, Date, ForeignKey, Index, Integer, String, Text, UniqueConstraint, text
|
||||
from sqlalchemy import Boolean, CheckConstraint, Date, ForeignKey, Index, Integer, JSON, String, Text, UniqueConstraint, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.models.base import Base
|
||||
@@ -39,6 +39,11 @@ class ShippingCustomer(Base):
|
||||
standard_name: Mapped[str] = mapped_column(String(200), nullable=False, index=True)
|
||||
short_code: Mapped[str] = mapped_column(String(6), nullable=False, unique=True)
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False, default='active', server_default='active')
|
||||
merged_into_customer_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey('shipping_customers.id'),
|
||||
nullable=True,
|
||||
index=True,
|
||||
)
|
||||
remark: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
created_by_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
updated_by_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
@@ -51,6 +56,21 @@ class ShippingCustomer(Base):
|
||||
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',
|
||||
back_populates='merged_source_customers',
|
||||
)
|
||||
external_refs: Mapped[List['ShippingCustomerExternalRef']] = relationship(
|
||||
'ShippingCustomerExternalRef', back_populates='customer', cascade='all, delete-orphan',
|
||||
)
|
||||
sites: Mapped[List['ShippingCustomerSite']] = relationship(
|
||||
'ShippingCustomerSite', back_populates='customer', cascade='all, delete-orphan',
|
||||
)
|
||||
merged_source_customers: Mapped[List['ShippingCustomer']] = relationship(
|
||||
'ShippingCustomer',
|
||||
back_populates='merged_into_customer',
|
||||
)
|
||||
|
||||
|
||||
class ShippingCustomerIdentifier(Base):
|
||||
@@ -108,7 +128,65 @@ class ShippingCustomerExternalRef(Base):
|
||||
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
customer: Mapped['ShippingCustomer'] = relationship('ShippingCustomer')
|
||||
customer: Mapped['ShippingCustomer'] = relationship('ShippingCustomer', back_populates='external_refs')
|
||||
|
||||
|
||||
class ShippingCustomerSite(Base):
|
||||
"""标准客户下的送货/收货站点;Ship-to 匹配指向站点而不是复制一条账款客户。"""
|
||||
|
||||
__tablename__ = 'shipping_customer_sites'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('customer_id', 'site_code', name='uq_shipping_customer_sites_customer_code'),
|
||||
Index('ix_shipping_customer_sites_status_name', 'status', 'site_name'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
customer_id: Mapped[int] = mapped_column(ForeignKey('shipping_customers.id'), nullable=False, index=True)
|
||||
site_name: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
site_code: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
address: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
city: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
|
||||
country: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False, default='active', server_default='active')
|
||||
remark: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
created_by_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
updated_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['ShippingCustomer'] = relationship('ShippingCustomer', back_populates='sites')
|
||||
identifiers: Mapped[List['ShippingCustomerSiteIdentifier']] = relationship(
|
||||
'ShippingCustomerSiteIdentifier', back_populates='site', cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
|
||||
class ShippingCustomerSiteIdentifier(Base):
|
||||
"""送货站点的名称、外部站点编码或地址别名,用于 Ship-to 确定性匹配。"""
|
||||
|
||||
__tablename__ = 'shipping_customer_site_identifiers'
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
'site_id', 'identifier_type', 'source_system', 'normalized_value',
|
||||
name='uq_shipping_customer_site_identifiers_value',
|
||||
),
|
||||
Index(
|
||||
'ix_shipping_customer_site_identifiers_lookup',
|
||||
'identifier_type', 'source_system', 'normalized_value', 'status',
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
site_id: Mapped[int] = mapped_column(ForeignKey('shipping_customer_sites.id'), nullable=False, index=True)
|
||||
identifier_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
source_system: Mapped[str] = mapped_column(String(64), nullable=False, default='', server_default='')
|
||||
raw_value: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
normalized_value: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False, default='approved', server_default='approved')
|
||||
remark: Mapped[Optional[str]] = mapped_column(Text, 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)
|
||||
|
||||
site: Mapped['ShippingCustomerSite'] = relationship('ShippingCustomerSite', back_populates='identifiers')
|
||||
|
||||
|
||||
class ShippingCase(Base):
|
||||
@@ -174,3 +252,45 @@ class ShippingBusinessSequence(Base):
|
||||
current_value: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default='0')
|
||||
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
|
||||
class ShippingCustomerLifecycleEvent(Base):
|
||||
"""客户生命周期审计;只保存客户快照,不能反向阻断受控删除。"""
|
||||
|
||||
__tablename__ = 'shipping_customer_lifecycle_events'
|
||||
__table_args__ = (
|
||||
Index('ix_shipping_customer_lifecycle_events_customer_created', 'customer_id_snapshot', 'created_at'),
|
||||
Index('ix_shipping_customer_lifecycle_events_event_created', 'event_type', 'created_at'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
event_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
customer_id_snapshot: Mapped[Optional[int]] = mapped_column(Integer, 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)
|
||||
actor_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
reason: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
detail_json: Mapped[dict] = mapped_column(JSON, nullable=False, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
|
||||
|
||||
|
||||
class ShippingCustomerMerge(Base):
|
||||
"""客户身份归并审计;仅存快照,不给历史审计链增加客户外键依赖。"""
|
||||
|
||||
__tablename__ = 'shipping_customer_merges'
|
||||
__table_args__ = (
|
||||
UniqueConstraint('source_customer_id_snapshot', name='uq_shipping_customer_merges_source_snapshot'),
|
||||
Index('ix_shipping_customer_merges_target_created', 'target_customer_id_snapshot', 'created_at'),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
source_customer_id_snapshot: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
source_name_snapshot: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
source_short_code_snapshot: Mapped[str] = mapped_column(String(6), nullable=False)
|
||||
target_customer_id_snapshot: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
target_name_snapshot: Mapped[str] = mapped_column(String(200), nullable=False)
|
||||
target_short_code_snapshot: Mapped[str] = mapped_column(String(6), nullable=False)
|
||||
actor_id: Mapped[Optional[int]] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
reason: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
detail_json: Mapped[dict] = mapped_column(JSON, nullable=False, default=dict)
|
||||
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow, index=True)
|
||||
Reference in new issue
Block a user