"""杂交组合 数据模型""" from datetime import datetime from sqlalchemy import Float, ForeignKey, Index, Integer, String, Text, text from sqlalchemy.orm import Mapped, mapped_column from app.core.base_model import MappedBase, ModelMixin, UserMixin class CrossCombinationModel(ModelMixin, UserMixin, MappedBase): """杂交组合 主数据表。""" __tablename__ = "bre_cross_combination" combination_code: Mapped[str] = mapped_column(String(100), nullable=False, comment="组合编号") cross_year: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="杂交年份", default=None) bre_target_id: Mapped[int] = mapped_column( Integer, ForeignKey("bre_target.id", ondelete="CASCADE"), index=True, nullable=False, comment="育种目标" ) female_parent_id: Mapped[int] = mapped_column( Integer, ForeignKey("bre_germplasm.id", ondelete="CASCADE"), index=True, nullable=True, comment="母本" ) male_parent_id: Mapped[int] = mapped_column( Integer, ForeignKey("bre_germplasm.id", ondelete="CASCADE"), index=True, nullable=True, comment="父本" ) cross_method: Mapped[str | None] = mapped_column(String(50), nullable=True, comment="杂交方式", default=None) cross_type: Mapped[str | None] = mapped_column(String(16), nullable=True, comment="杂交类型(杂交/自交/开放)", default=None) design_type: Mapped[str] = mapped_column( String(32), nullable=False, default="full_diallel", comment="交配设计(full_diallel完全双列/partial_diallel部分双列/line_tester line×tester NCII/nciii NCIII测交)", ) parent_combination_id: Mapped[int | None] = mapped_column( Integer, ForeignKey("bre_cross_combination.id", ondelete="SET NULL"), index=True, nullable=True, comment="母本组合(自关联)" ) reason: Mapped[str | None] = mapped_column(String(512), nullable=True, comment="组配理由", default=None) stage: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="育种阶段(breeding_stage)", default=None) cross_date: Mapped[str | None] = mapped_column(String(20), nullable=True, comment="杂交日期", default=None) seed_count: Mapped[int | None] = mapped_column(Integer, 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_cross_combination_created_deleted", "created_time", "is_deleted"), # 组合编号唯一(仅约束未软删记录,与 service 层查重语义一致) Index( "uniq_bre_cross_combination_code", "combination_code", unique=True, postgresql_where=text("is_deleted = false"), ), )