"""选育结果 数据模型""" from datetime import datetime from sqlalchemy import Float, ForeignKey, Index, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.base_model import MappedBase, ModelMixin, UserMixin class SelectionResultModel(ModelMixin, UserMixin, MappedBase): """选育结果 主数据表。""" __tablename__ = "bre_selection_result" combination_id: Mapped[int] = mapped_column( Integer, ForeignKey("bre_cross_combination.id", ondelete="CASCADE"), index=True, nullable=False, comment="杂交组合" ) tree_id: Mapped[int] = mapped_column( Integer, ForeignKey("bre_tree.id", ondelete="CASCADE"), index=True, nullable=False, comment="单株" ) tree_no: Mapped[str] = mapped_column(String(100), nullable=False, comment="单株编号(冗余自单株表)", default="") selection_year: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="入选年份", default=None) is_selected: Mapped[str | None] = mapped_column(String(50), nullable=True, comment="选育结论", default=None) clone_id: Mapped[int | None] = mapped_column( Integer, ForeignKey("bre_clone.id", ondelete="SET NULL"), index=True, nullable=True, comment="晋级无性系" ) rule_id: Mapped[int | None] = mapped_column( Integer, ForeignKey("bre_selection_rule.id", ondelete="SET NULL"), index=True, nullable=True, comment="选育规则" ) from_stage: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="起始阶段(breeding_stage)", default=None) to_stage: Mapped[str | None] = mapped_column(String(32), nullable=True, comment="晋级阶段(breeding_stage)", default=None) approved_by: Mapped[int | None] = mapped_column( Integer, ForeignKey("bre_personnel.id", ondelete="SET NULL"), index=True, nullable=True, comment="审核人" ) trial_study_id: Mapped[int | None] = mapped_column( Integer, ForeignKey("bre_trial_study.id", ondelete="SET NULL"), index=True, nullable=True, comment="所属试验研究点" ) reason: Mapped[str | None] = mapped_column(Text, 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_selection_result_created_deleted", "created_time", "is_deleted"), )