Files

72 lines
2.8 KiB
Python
Raw Permalink Normal View History

"""定植管理 数据模型"""
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 PlantingModel(ModelMixin, UserMixin, MappedBase):
"""定植管理 主数据表。"""
__tablename__ = "bre_planting"
combination_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_cross_combination.id", ondelete="CASCADE"),
index=True, nullable=False, comment="杂交组合"
)
plot_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_plot.id", ondelete="CASCADE"),
index=True, nullable=True, comment="试验地块"
)
planting_date: Mapped[str | None] = mapped_column(String(20), nullable=True, comment="定植日期", default=None)
tree_count: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="定植株数", default=None)
row_no: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="行号", default=None)
col_no: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="列号", default=None)
bre_personnel_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_personnel.id", ondelete="CASCADE"),
index=True, nullable=True, comment="定植人"
)
seedling_id: Mapped[int] = mapped_column(
Integer, ForeignKey("bre_seedling.id", ondelete="CASCADE"),
index=True, nullable=True, comment="育苗批次"
)
seed_lot_id: Mapped[int | None] = mapped_column(
Integer, ForeignKey("bre_seed_lot.id", ondelete="SET NULL"),
index=True, nullable=True, comment="种子来源批(选择强度链,规格 §3.13)"
)
rootstock_id: Mapped[int | None] = mapped_column(
Integer, ForeignKey("bre_rootstock.id", ondelete="SET NULL"),
index=True, nullable=True, comment="砧木"
)
entry_id: Mapped[int | None] = mapped_column(
Integer, ForeignKey("bre_trial_study_entry.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="所属试验研究点"
)
block_no: 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_planting_created_deleted", "created_time", "is_deleted"),
)