写好了增加学生接口,增加学生dao层,main里加入了student——router

This commit is contained in:
wolin_liyujie
2026-09-21 16:19:44 +08:00
parent da71b48a10
commit 1a8e4f7571
9 changed files with 82 additions and 55 deletions
+13
View File
@@ -0,0 +1,13 @@
from models import *
from core.database import *
from sqlalchemy import create_engine
db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/student_manager?charset=utf8mb4"
engine = create_engine(db_url
,pool_size=50
,echo=True)
Base.metadata.create_all(engine)
db = SessionLocal()
db.commit()
+7 -1
View File
@@ -1 +1,7 @@
from .class_model import Classes
from .class_teacher import ClassTeachers
from .consultant import Consultant
from .employment import Employment
from .score import Score
from .student import Student
from .teacher import Teacher
+1 -1
View File
@@ -3,7 +3,7 @@ from datetime import datetime # 导入datetime模块下的datetime类
from core.database import Base # 从core软件包下的database模块导入Base from core.database import Base # 从core软件包下的database模块导入Base
class Classes( Base ): # 在python里的名字 class Classes( Base ): # 在python里的名字
__tablename__ = 'classes' # 在数据库中表的名字 __tablename__ = 'class_info_detail' # 在数据库中表的名字
#————创建班级"主键"的字段名———— #————创建班级"主键"的字段名————
id = Column( Integer # 声明字段的数据类型是"整数" id = Column( Integer # 声明字段的数据类型是"整数"
, primary_key = True # 声明是"主键" , primary_key = True # 声明是"主键"
+53
View File
@@ -0,0 +1,53 @@
from sqlalchemy import (Column, Integer, String, Text,
BigInteger,ForeignKey,VARCHAR,DateTime
)
from sqlalchemy.dialects.mssql import TINYINT
from core.database import Base
from datetime import datetime
#班级老师关系表 class_teachers_info_detail 中间表 ORM 模型完整定义
#字段包括id,class_id,teacher_id,role,created_at,updated_at,is_deleted
class ClassTeachers(Base):
__tablename__ = "class_teachers_info_detail"
id = Column(
Integer
,primary_key=True
,autoincrement=True
,comment='关系')
class_id = Column(
Integer
,ForeignKey('class_info_detail.id')
,nullable=False
,comment='关联 class_id'
)
teacher_id = Column(
Integer
,ForeignKey("teacher_info_detail.id")
,nullable=False
,comment='关联 teacher_id'
)
role = Column(
VARCHAR(30)
,nullable=False
,comment='老师在班级中的角色:head_teacher班主任 / lecturer授课老师 / assistant助教'
)
created_at = Column(
DateTime
,nullable=False
,default=datetime.now()
,comment='创建时间'
)
updated_at = Column(
DateTime
,nullable=False
,default=datetime.now()
,comment='更新时间'
)
is_deleted = Column(
TINYINT
,nullable=False
,default=0
,comment='逻辑删除'
)
+1 -1
View File
@@ -3,7 +3,7 @@ from sqlalchemy import *
from datetime import datetime from datetime import datetime
from core.database import Base from core.database import Base
class Consultant(Base): class Consultant(Base):
__tablename__ = "consultants" __tablename__ = "consultant_info_detail"
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键") id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
consultant_no = Column(String(50), unique=True, nullable=False, comment="顾问编号") consultant_no = Column(String(50), unique=True, nullable=False, comment="顾问编号")
+3 -3
View File
@@ -6,11 +6,11 @@ from core.database import Base, engine
# 为了符合三范式,就业表只保存 student_id,不保存学生姓名和班级名称。查询返回时通过关联 students 和 classes 带出学生姓名、班级名称。 # 为了符合三范式,就业表只保存 student_id,不保存学生姓名和班级名称。查询返回时通过关联 students 和 classes 带出学生姓名、班级名称。
class Employment(Base): class Employment(Base):
__tablename__ = "employments" # 实际数据库的表名字 __tablename__ = "employment_info_detail" # 实际数据库的表名字
id = Column(BigInteger, primary_key=True # 主键 id = Column(Integer, primary_key=True # 主键
, autoincrement=True # 声明是自增主键 , autoincrement=True # 声明是自增主键
,comment="就业信息主键id") ,comment="就业信息主键id")
student_id = Column(BigInteger, ForeignKey("students.id") # 外键 -> students.id student_id = Column(Integer, ForeignKey("student_info_detail.id") # 外键 -> students.id
, nullable=False # 不允许为null , nullable=False # 不允许为null
,comment="关联学生id") ,comment="关联学生id")
employment_status = Column(String(50) employment_status = Column(String(50)
+1 -1
View File
@@ -9,7 +9,7 @@ class Score(Base):
,comment="成绩表序号,自增主键" ,comment="成绩表序号,自增主键"
) )
student_id = Column(Integer student_id = Column(Integer
,ForeignKey("student.id") ,ForeignKey("student_info_detail.id")
,nullable=False ,nullable=False
,comment="学生学号" ,comment="学生学号"
) )
+2 -2
View File
@@ -13,11 +13,11 @@ class Student(Base):
, unique = True) , unique = True)
student_name = Column(VARCHAR(50)) student_name = Column(VARCHAR(50))
class_id = Column(Integer class_id = Column(Integer
,foreign_key = 'class_info_detail.id' ,ForeignKey('class_info_detail.id')
)#外键约束 班级表的主键id,存在这个班级,学生表才可以输入 )#外键约束 班级表的主键id,存在这个班级,学生表才可以输入
consultant_id = Column(Integer consultant_id = Column(Integer
, ForeignKey('consultant_info_detail.id')
,nullable = True ,nullable = True
,foreign_key = 'consultant_info_detail.id'
)#外键约束 顾问表的主键id,存在这个顾问,才可以写入,允许为空 )#外键约束 顾问表的主键id,存在这个顾问,才可以写入,允许为空
native_place = Column(VARCHAR(100) native_place = Column(VARCHAR(100)
,nullable = True) ,nullable = True)
+1 -46
View File
@@ -10,7 +10,7 @@ from datetime import datetime
# teachers 老师表 ORM 模型 # teachers 老师表 ORM 模型
#字段包括id,teacher_no,teacher_name,phone,email,remark,created_at,updated_at,is_deleted #字段包括id,teacher_no,teacher_name,phone,email,remark,created_at,updated_at,is_deleted
class Teacher(Base): class Teacher(Base):
__tablename__ = 'teachers_info_detail' __tablename__ = 'teacher_info_detail'
id = Column( id = Column(
Integer Integer
, primary_key=True , primary_key=True
@@ -62,48 +62,3 @@ class Teacher(Base):
) )
#班级老师关系表 class_teachers_info_detail 中间表 ORM 模型完整定义
#字段包括id,class_id,teacher_id,role,created_at,updated_at,is_deleted
class ClassTeachers(Base):
__tablename__ = "class_teachers_info_detail"
id = Column(
BigInteger
,primary_key=True
,autoincrement=True
,comment='关系')
class_id = Column(
BigInteger
,ForeignKey('class_id')
,nullable=False
,comment='关联 class_id'
)
teacher_id = Column(
BigInteger
,ForeignKey('teacher_id')
,nullable=False
,comment='关联 teacher_id'
)
role = Column(
VARCHAR(30)
,nullable=False
,comment='老师在班级中的角色:head_teacher班主任 / lecturer授课老师 / assistant助教'
)
created_at = Column(
DateTime
,nullable=False
,default=datetime.now()
,comment='创建时间'
)
updated_at = Column(
DateTime
,nullable=False
,default=datetime.now()
,comment='更新时间'
)
is_deleted = Column(
TINYINT
,nullable=False
,default=0
,comment='逻辑删除'
)