From b8988966861f347ab5b25e7923d5f03391ccbe43 Mon Sep 17 00:00:00 2001 From: nfy <2425896042@qq.com> Date: Mon, 21 Sep 2026 14:18:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8D=97=E6=96=B9=E5=AE=87model=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/employment.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/models/employment.py b/models/employment.py index e69de29..086ff92 100644 --- a/models/employment.py +++ b/models/employment.py @@ -0,0 +1,46 @@ +from sqlalchemy import * +from sqlalchemy.orm import declarative_base,sessionmaker +from datetime import datetime +from core.database import Base, engine + +db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/student_manager?charset=utf8mb4" +engine = create_engine(db_url) # 连接地址 +Base = declarative_base() # 执行函数,返回一个基类 + +# 为了符合三范式,就业表只保存 student_id,不保存学生姓名和班级名称。查询返回时通过关联 students 和 classes 带出学生姓名、班级名称。 + +class Employment(Base): + __tablename__ = "employments" # 实际数据库的表名字 + id = Column(BigInteger, primary_key=True # 主键 + , autoincrement=True # 声明是自增主键 + ,comment="就业信息主键id") + student_id = Column(BigInteger, ForeignKey("students.id") # 外键 -> students.id + , nullable=False # 不允许为null + ,comment="关联学生id") + employment_status = Column(String(50) + , default="not_started" + ,comment="就业状态:not_started/job_hunting/offered/employed") + employment_open_date = Column(Date + ,comment="就业开放时间") + offer_date = Column(Date + ,comment="offer下发时间") + company_name = Column(String(100) + , comment="就业公司名称") + salary = Column(DECIMAL(10, 2) # 高精度浮点数薪资,最多 10 位数字,小数占 2 位 + , comment="就业薪资") + remark = Column(String(255) + ,default=None + , comment="备注信息") + created_at = Column(DateTime + , default=datetime.now + , comment="创建时间") + updated_at = Column(DateTime + , default=datetime.now + , onupdate=datetime.now + ,comment="更新时间") + is_deleted = Column(SmallInteger + ,default=0 + ,comment="逻辑删除:0正常,1删除") + +Base.metadata.create_all(engine) +print("建表完成:employments") \ No newline at end of file From d28b4beff980a3cbb25ad81d14f272895332f3ac Mon Sep 17 00:00:00 2001 From: nfy <2425896042@qq.com> Date: Mon, 21 Sep 2026 14:33:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8D=97=E6=96=B9=E5=AE=87model=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/employment.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/models/employment.py b/models/employment.py index 086ff92..69e2706 100644 --- a/models/employment.py +++ b/models/employment.py @@ -3,10 +3,6 @@ from sqlalchemy.orm import declarative_base,sessionmaker from datetime import datetime from core.database import Base, engine -db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/student_manager?charset=utf8mb4" -engine = create_engine(db_url) # 连接地址 -Base = declarative_base() # 执行函数,返回一个基类 - # 为了符合三范式,就业表只保存 student_id,不保存学生姓名和班级名称。查询返回时通过关联 students 和 classes 带出学生姓名、班级名称。 class Employment(Base): @@ -42,5 +38,3 @@ class Employment(Base): ,default=0 ,comment="逻辑删除:0正常,1删除") -Base.metadata.create_all(engine) -print("建表完成:employments") \ No newline at end of file