52 lines
2.6 KiB
Python
52 lines
2.6 KiB
Python
# model/employment.py
|
||
# 就业表(两张):
|
||
# EmploymentBase 基础信息表:每个开放简历的学生 1 条数据(补充冗余字段 stu_name/class_name)
|
||
# EmploymentOffer offer 表:拿到 offer 后才插入数据,一个学生可有多条
|
||
from sqlalchemy import Column, Integer, String, Date, Float, ForeignKey
|
||
from sqlalchemy.orm import relationship
|
||
|
||
from database import Base
|
||
|
||
|
||
class EmploymentBase(Base):
|
||
__tablename__ = "employment_base"
|
||
|
||
stu_id = Column(Integer, ForeignKey("student.stu_id"), primary_key=True, comment="学生编号")
|
||
employment_open_time = Column(Date, nullable=False, comment="就业开放时间(开放简历)")
|
||
job_time = Column(Date, default=None, comment="offer 下发时间(未拿到 offer 为 NULL)")
|
||
company_name = Column(String(100), default="未就业", comment="就业公司名称")
|
||
salary = Column(Float, default=0, comment="就业薪资")
|
||
# ---------- 冗余字段(需求 2.3 设计提示:优化查询与一致性,登记时从 student/class 同步写入) ----------
|
||
stu_name = Column(String(10), nullable=False, comment="冗余:学生姓名")
|
||
class_name = Column(String(50), nullable=False, comment="冗余:学生班级名称")
|
||
is_deleted = Column(Integer, default=0, nullable=False, comment="逻辑删除: 0正常 1删除")
|
||
|
||
student = relationship("Student", back_populates="employment")
|
||
# 一个学生可有多条 offer;viewonly=True:offer 由 offer 表接口单独维护,不走本关系写入
|
||
offers = relationship(
|
||
"EmploymentOffer",
|
||
primaryjoin="EmploymentBase.stu_id == foreign(EmploymentOffer.stu_id)",
|
||
foreign_keys="EmploymentOffer.stu_id",
|
||
viewonly=True,
|
||
order_by="EmploymentOffer.offer_id",
|
||
)
|
||
|
||
def __repr__(self):
|
||
return f"<EmploymentBase(stu_id={self.stu_id}, company_name='{self.company_name}', salary={self.salary})>"
|
||
|
||
|
||
class EmploymentOffer(Base):
|
||
__tablename__ = "employment_offer"
|
||
|
||
stu_id = Column(
|
||
Integer, ForeignKey("employment_base.stu_id"), primary_key=True, comment="学生编号"
|
||
)
|
||
offer_id = Column(Integer, primary_key=True, comment="offer 序号(同一学生内自增)")
|
||
offer_time = Column(Date, nullable=False, comment="offer 下发时间")
|
||
company_name = Column(String(100), default="", comment="offer 公司名")
|
||
salary = Column(Float, default=0, comment="offer 薪资")
|
||
is_deleted = Column(Integer, default=0, nullable=False, comment="逻辑删除: 0正常 1删除")
|
||
|
||
def __repr__(self):
|
||
return f"<EmploymentOffer(stu_id={self.stu_id}, offer_id={self.offer_id}, offer_time={self.offer_time})>"
|