"""花粉档案 数据模型""" from datetime import date from sqlalchemy import Date, Float, ForeignKey, Index, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.base_model import MappedBase, ModelMixin, UserMixin class PollenModel(ModelMixin, UserMixin, MappedBase): """花粉档案:采集父本/日期/贮藏/活力/有效期,授粉窗口计划地基。""" __tablename__ = "bre_pollen" lot_code: Mapped[str] = mapped_column( String(64), nullable=False, unique=True, comment="花粉批次号(如 PL-2026-0001)" ) male_tree_id: Mapped[int | None] = mapped_column( Integer, ForeignKey("bre_tree.id", ondelete="SET NULL"), index=True, nullable=True, comment="采集父本树(混合/外地采集可空)" ) source_type: Mapped[str] = mapped_column( String(16), nullable=False, default="tree", comment="来源类型 tree父本树/mixed混合花粉/external外地采集" ) source_desc: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="来源说明(混合配比/外地品种)") collect_date: Mapped[date | None] = mapped_column(Date, nullable=True, comment="花粉采集日期", default=None) collect_method: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="采集方式(采花取粉/振动收集…)", default=None) quantity: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="采集量(如 50g / 花药数)", default=None) storage_method: Mapped[str] = mapped_column( String(16), nullable=False, default="fridge", comment="贮藏方式 fridge4℃/minus20/minus80/liquid_n2液氮" ) viability_method: Mapped[str | None] = mapped_column( String(16), nullable=True, comment="活力测定方法 ttc(TTC染色率)/germination(离体萌发率%)", default=None ) viability_pct: Mapped[float | None] = mapped_column(Float, nullable=True, comment="花粉活力 %", default=None) viability_test_date: Mapped[date | None] = mapped_column(Date, nullable=True, comment="活力测定日期", default=None) expiry_date: Mapped[date | None] = mapped_column(Date, nullable=True, comment="有效期/失效日期(授粉窗口上界)", default=None) remark: Mapped[str | None] = mapped_column(Text, nullable=True, comment="备注", default=None) # 无 status 列:覆盖基类默认 ix_<表>_status_deleted 索引, # 仅保留 (created_time, is_deleted) 复合索引用于数据权限过滤。 __table_args__ = ( Index("ix_bre_pollen_created_deleted", "created_time", "is_deleted"), )