from datetime import datetime from sqlalchemy import ( BigInteger, Boolean, DateTime, Index, Integer, Numeric, String, func, ) from sqlalchemy.orm import Mapped, mapped_column from app.core.database import Base SCHEMA = "CargoTrace" class AttachmentCategory(Base): """附件类型字典。本期由业务方直接维护表数据,无管理界面。""" __tablename__ = "attachment_category" __table_args__ = ({"schema": SCHEMA},) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(64), nullable=False, unique=True) sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0) is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True) created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), server_default=func.current_timestamp(), ) class FinishedGoodsAttachment(Base): """订单级附件判定,每个总排号一行。""" __tablename__ = "finished_goods_attachment" __table_args__ = ( Index("uk_fga_zongpai_no", "zongpai_no", unique=True), {"schema": SCHEMA}, ) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False) # undetermined / none / has determination: Mapped[str] = mapped_column( String(16), nullable=False, default="undetermined" ) created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), server_default=func.current_timestamp(), ) updated_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), onupdate=func.current_timestamp(), server_default=func.current_timestamp(), ) class FinishedGoodsAttachmentItem(Base): """类型级计划明细:每个 总排号 × 类型 一行。已到数量由箱明细派生,不落库。""" __tablename__ = "finished_goods_attachment_item" __table_args__ = ( Index( "uk_fgai_zongpai_category", "zongpai_no", "category_id", unique=True ), Index("idx_fgai_zongpai_no", "zongpai_no"), {"schema": SCHEMA}, ) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False) category_id: Mapped[int] = mapped_column(BigInteger, nullable=False) expected_qty: Mapped[int] = mapped_column(Integer, nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), server_default=func.current_timestamp(), ) updated_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), onupdate=func.current_timestamp(), server_default=func.current_timestamp(), ) class FinishedGoodsAttachmentLocation(Base): """附件上架,镜像 finished_goods_location。每种类型一个货位。""" __tablename__ = "finished_goods_attachment_location" __table_args__ = ( Index( "uk_fgal_zongpai_category", "zongpai_no", "category_id", unique=True ), {"schema": SCHEMA}, ) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False) category_id: Mapped[int] = mapped_column(BigInteger, nullable=False) location_code: Mapped[str] = mapped_column(String(64), nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), server_default=func.current_timestamp(), ) class FinishedGoodsBoxAttachmentItem(Base): """附件装箱明细,共用 finished_goods_box(排产号级箱)。""" __tablename__ = "finished_goods_box_attachment_item" __table_args__ = ( Index("idx_fgbai_box_id", "box_id"), Index("idx_fgbai_zongpai_category", "zongpai_no", "category_id"), {"schema": SCHEMA}, ) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) box_id: Mapped[int] = mapped_column(BigInteger, nullable=False) zongpai_no: Mapped[str] = mapped_column(String(64), nullable=False) category_id: Mapped[int] = mapped_column(BigInteger, nullable=False) quantity: Mapped[float] = mapped_column(Numeric(18, 3), nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=func.current_timestamp(), server_default=func.current_timestamp(), )