122 lines
5.3 KiB
Python
122 lines
5.3 KiB
Python
from database import Base
|
|
from datetime import datetime,date
|
|
from sqlalchemy import *
|
|
from sqlalchemy import Column, Integer, String, Date, JSON
|
|
from sqlalchemy import Column, String, Date, Enum, DateTime, func
|
|
from sqlalchemy.orm import declarative_base
|
|
import enum
|
|
|
|
class Class_info(Base): # python里的表名字
|
|
__tablename__ = 'class_info' # 实际数据库的表名字
|
|
class_id = Column(String(20)
|
|
, primary_key=True
|
|
, autoincrement=False
|
|
, comment='班级编号,字符串类型手动维护')
|
|
|
|
class_code = Column(String(20) # 对应数据库的varchar类型
|
|
, nullable=False
|
|
,comment='班级业务编码,格式示例:2026-CS-01'# 不允许为null
|
|
)
|
|
class_name = Column(String(50)
|
|
, nullable=False
|
|
,comment='所在班级显示名称,如“2026级计算机科学与技术1班”,直接用于前端展示'
|
|
)
|
|
grade_year = Column(Date
|
|
,default=date.today
|
|
,comment='入学年级,如2026,用数值存储比字符串更便于按年级筛选、排序'
|
|
)
|
|
|
|
# teacher_id = Column(Integer
|
|
# , nullable=False
|
|
# ,comment='班主任外键,关联教师表,一个班级对应一名班主任'
|
|
# )
|
|
#
|
|
# student_id = Column(Integer
|
|
# , nullable=False
|
|
# ,comment='学号 用来连接学生表'
|
|
# )
|
|
|
|
enrollment_date = Column(Date
|
|
,default=date.today
|
|
,comment='班级正式入学日期'
|
|
)
|
|
|
|
status = Column(Integer
|
|
, nullable=False
|
|
,comment='班级正式入学日期'
|
|
)
|
|
|
|
|
|
tags = Column(JSON
|
|
, nullable=False
|
|
,comment='存储多维标签,例如:["重点班", "科技特长", "2026届"]'
|
|
)
|
|
|
|
is_deleted = Column(Boolean, default=0, comment="0=数据存在 1=数据逻辑删除")
|
|
|
|
|
|
create_time = Column(DATETIME
|
|
, default=datetime.now # 默认值是当前时间
|
|
)
|
|
update_time = Column(DATETIME
|
|
, default=datetime.now # 首次创建的时间跟更新时间一致
|
|
, onupdate=datetime.now
|
|
)
|
|
|
|
class StudentClassIntermediate(Base):
|
|
__tablename__ = "student_class_intermediate_table"
|
|
id = Column(String(20), primary_key=True)
|
|
class_id= Column(String(20))
|
|
student_id =Column(String(20))
|
|
is_deleted= Column(Integer)
|
|
create_time= Column(DateTime)
|
|
update_time= Column(DateTime)
|
|
|
|
|
|
|
|
|
|
class GenderEnum(str, enum.Enum):
|
|
FEMALE = '0'
|
|
MALE = '1'
|
|
|
|
class StudentStatusEnum(str, enum.Enum):
|
|
NORMAL = '0' # 正常
|
|
SUSPENDED = '1' # 休学
|
|
DROPPED = '2' # 退学
|
|
GRADUATED = '3' # 毕业
|
|
OTHER = '4' # 其他
|
|
|
|
class EducationLevelEnum(str, enum.Enum):
|
|
COLLEGE = '1' # 大专
|
|
UNDERGRADUATE = '2' # 本科
|
|
MASTER = '3' # 硕士
|
|
DOCTOR = '4' # 博士
|
|
|
|
class IsDeletedEnum(str, enum.Enum):
|
|
ACTIVE = '0' # 未删除
|
|
DELETED = '1' # 已删除
|
|
|
|
# 3. 定义学生模型类
|
|
class Student_info(Base):
|
|
__tablename__ = "student_info"
|
|
student_id = Column(String(20),primary_key=True, comment='学号')
|
|
student_name = Column(String(50), nullable=False, comment='学生姓名')
|
|
gender = Column(Enum(GenderEnum), nullable=False, comment='性别: 0=女, 1=男')
|
|
id_card = Column(String(18), nullable=False, comment='身份证号码,收紧至18位')
|
|
birthday = Column(Date, nullable=True, comment='出生日期')
|
|
ethnicity = Column(String(20), nullable=True, comment='民族')
|
|
region_id = Column(String(12), nullable=True, comment='籍贯地区编码,外键关联地区维度表(region_dimension)')
|
|
phone = Column(String(11), nullable=True, comment='手机号码,收紧至11位')
|
|
graduation_school = Column(String(20), nullable=True, comment='毕业学校')
|
|
major = Column(String(20), nullable=False, comment='就读专业')
|
|
class_id = Column(String(20), nullable=False, index=True, comment='所在班级,外键关联班级表(class_info)')
|
|
enrollment_date = Column(Date, nullable=True, comment='入学日期')
|
|
graduation_date = Column(Date, nullable=True, comment='毕业日期')
|
|
student_status = Column(Enum(StudentStatusEnum), nullable=False, default=StudentStatusEnum.NORMAL,
|
|
comment='学籍状态')
|
|
education_level = Column(Enum(EducationLevelEnum), nullable=False,
|
|
comment='学历层次:1=大专, 2=本科, 3=硕士研究生, 4=博士研究生')
|
|
is_deleted = Column(Enum(IsDeletedEnum), nullable=False, default=IsDeletedEnum.ACTIVE,
|
|
comment='逻辑删除:0=未删除, 1=已删除')
|
|
create_time = Column(DateTime, nullable=False, server_default=func.now(), comment='创建时间')
|
|
update_time = Column(DateTime, nullable=False, server_default=func.now(), onupdate=func.now(), comment='更新时间') |