user.py 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import datetime
  4. from sqlalchemy import Column, Integer, String, BOOLEAN, DateTime, UniqueConstraint
  5. from db import BaseORMModel
  6. class Teacher(BaseORMModel):
  7. __tablename__ = "teachers"
  8. id = Column(Integer, primary_key=True, autoincrement=True)
  9. username = Column(String(20), nullable=False, comment="用户名")
  10. password = Column(String(64), nullable=False, comment="密码")
  11. name = Column(String(20), nullable=False, comment="姓名")
  12. sex = Column(Integer, default=0, comment="性别,0:女,1:男")
  13. age = Column(Integer, default=0, comment="年龄")
  14. phone = Column(String(11), nullable=False, comment="手机号")
  15. school_id = Column(Integer, nullable=False, comment="所在学校ID")
  16. school_name = Column(String(100), nullable=False, comment="学校名称")
  17. grade_id = Column(Integer, nullable=False, comment="所在年级ID")
  18. grade_name = Column(String(20), nullable=False, comment="年级名称")
  19. class_id = Column(String(50), nullable=False, comment="所在班级ID列表")
  20. class_name = Column(String(50), nullable=False, comment="班级名称列表")
  21. role_id = Column(Integer, nullable=False, comment="角色ID")
  22. role_name = Column(String(20), nullable=False, comment="角色名称")
  23. period = Column(Integer, nullable=False, comment="学段,0:小学,1:初中,2:高中")
  24. subject = Column(String(10), default="", comment="任教学科")
  25. is_first_login = Column(BOOLEAN, default=True, comment="是否第一次登录,用于强制修改密码")
  26. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  27. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  28. created_at = Column(DateTime, default=datetime.datetime.now)
  29. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  30. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  31. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  32. __table_args__ = (UniqueConstraint("phone", name="uix_teacher_phone"),)
  33. class Student(BaseORMModel):
  34. __tablename__ = "students"
  35. id = Column(Integer, primary_key=True, autoincrement=True)
  36. sno = Column(String(20), nullable=False, comment="学号")
  37. username = Column(String(20), nullable=False, comment="用户名")
  38. password = Column(String(64), nullable=False, comment="密码")
  39. name = Column(String(20), nullable=False, comment="姓名")
  40. sex = Column(Integer, default=0, comment="性别,0:女,1:男")
  41. age = Column(Integer, default=0, comment="年龄")
  42. phone = Column(String(11), nullable=False, comment="手机号")
  43. period = Column(Integer, nullable=False, comment="学段,0:小学,1:初中,2:高中")
  44. school_id = Column(Integer, nullable=False, comment="所在学校ID")
  45. school_name = Column(String(100), nullable=False, comment="学校名称")
  46. grade_id = Column(Integer, nullable=False, comment="所在年级ID")
  47. grade_name = Column(String(20), nullable=False, comment="年级名称")
  48. class_id = Column(Integer, nullable=False, comment="所在班级ID")
  49. class_name = Column(String(20), nullable=False, comment="班级名称")
  50. is_first_login = Column(BOOLEAN, default=True, comment="是否第一次登录,用于强制修改密码")
  51. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  52. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  53. created_at = Column(DateTime, default=datetime.datetime.now)
  54. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  55. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  56. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  57. __table_args__ = (
  58. UniqueConstraint("sno", "school_id", name="uix_student_sno_school"),
  59. UniqueConstraint("phone", name="uix_student_phone"),
  60. )
  61. class Admin(BaseORMModel):
  62. __tablename__ = "admins"
  63. id = Column(Integer, primary_key=True, autoincrement=True)
  64. username = Column(String(64), nullable=False)
  65. password = Column(String(64), nullable=False)
  66. name = Column(String(32), default="")
  67. phone = Column(String(32), nullable=False, comment="手机号")
  68. role_id = Column(Integer, nullable=False, comment="角色ID")
  69. is_active = Column(BOOLEAN(), default=True, comment="是否激活")
  70. last_login_time = Column(DateTime, onupdate=datetime.datetime.now, comment="最后登录时间")
  71. last_login_ip = Column(String(15), default="", comment="最后登录IP")
  72. creator_id = Column(Integer, nullable=False, comment="创建人ID")
  73. creator_name = Column(String(32), nullable=False, comment="创建人名称")
  74. created_at = Column(DateTime, default=datetime.datetime.now)
  75. editor_id = Column(Integer, nullable=False, comment="最后编辑人ID")
  76. editor_name = Column(String(32), nullable=False, comment="最后编辑人名称")
  77. updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
  78. __table_args__ = (UniqueConstraint("phone", name="uix_sysuser_phone"),
  79. UniqueConstraint("username", name="uix_sysuser_username"))