user.py 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.base import Base
  6. class Teacher(Base):
  7. id = Column(Integer, primary_key=True, autoincrement=True)
  8. username = Column(String(20), nullable=False, comment="用户名")
  9. password = Column(String(64), nullable=False, comment="密码")
  10. name = Column(String(20), nullable=False, comment="姓名")
  11. sex = Column(Integer, default=0, comment="性别,0:女,1:男")
  12. age = Column(Integer, default=0, comment="年龄")
  13. phone = Column(String(11), nullable=False, comment="手机号")
  14. school_id = Column(Integer, nullable=False, comment="所在学校ID")
  15. school_name = Column(String(100), nullable=False, comment="学校名称")
  16. grade_id = Column(Integer, nullable=False, comment="所在年级ID")
  17. grade_name = Column(String(20), nullable=False, comment="年级名称")
  18. class_id = Column(String(50), nullable=False, comment="所在班级ID列表")
  19. class_name = Column(String(50), nullable=False, comment="班级名称列表")
  20. role_id = Column(Integer, nullable=False, comment="角色ID")
  21. role_name = Column(String(20), nullable=False, comment="角色名称")
  22. subject = Column(String(10), comment="任教学科")
  23. is_first_login = Column(BOOLEAN, default=True, comment="是否第一次登录,用于强制修改密码")
  24. creator_id = Column(Integer, comment="创建人ID")
  25. creator_name = Column(String(32), comment="创建人名称")
  26. created_at = Column(DateTime, default=datetime.datetime.now)
  27. editor_id = Column(Integer, comment="最后编辑人ID")
  28. editor_name = Column(String(32), comment="最后编辑人名称")
  29. updated_at = Column(DateTime,
  30. default=datetime.datetime.now,
  31. onupdate=datetime.datetime.now)
  32. __table_args__ = (UniqueConstraint("phone", name="uix_teacher_phone"),)
  33. class Student(Base):
  34. id = Column(Integer, primary_key=True, autoincrement=True)
  35. sno = Column(String(20), nullable=False, comment="学号")
  36. username = Column(String(20), nullable=False, comment="用户名")
  37. password = Column(String(64), nullable=False, comment="密码")
  38. name = Column(String(20), nullable=False, comment="姓名")
  39. sex = Column(Integer, default=0, comment="性别,0:女,1:男")
  40. age = Column(Integer, default=0, comment="年龄")
  41. phone = Column(String(11), nullable=False, comment="手机号")
  42. school_id = Column(Integer, nullable=False, comment="所在学校ID")
  43. school_name = Column(String(100), nullable=False, comment="学校名称")
  44. grade_id = Column(Integer, nullable=False, comment="所在年级ID")
  45. grade_name = Column(String(20), nullable=False, comment="年级名称")
  46. class_id = Column(Integer, nullable=False, comment="所在班级ID")
  47. class_name = Column(String(20), nullable=False, comment="班级名称")
  48. is_first_login = Column(BOOLEAN, default=True, comment="是否第一次登录,用于强制修改密码")
  49. creator_id = Column(Integer, comment="创建人ID")
  50. creator_name = Column(String(32), comment="创建人名称")
  51. created_at = Column(DateTime, default=datetime.datetime.now)
  52. editor_id = Column(Integer, comment="最后编辑人ID")
  53. editor_name = Column(String(32), comment="最后编辑人名称")
  54. updated_at = Column(DateTime,
  55. default=datetime.datetime.now,
  56. 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 SysUser(Base):
  62. id = Column(Integer, primary_key=True, autoincrement=True)
  63. username = Column(String(64), nullable=False)
  64. password = Column(String(64), nullable=False)
  65. name = Column(String(32), default="")
  66. phone = Column(String(32), nullable=False, comment="手机号")
  67. role_id = Column(Integer, nullable=False, comment="角色ID")
  68. is_active = Column(BOOLEAN(), default=True, comment="是否激活")
  69. last_login_time = Column(DateTime, comment="最后登录时间")
  70. last_login_ip = Column(String(15), comment="最后登录IP")
  71. creator_id = Column(Integer, comment="创建人ID")
  72. creator_name = Column(String(32), comment="创建人名称")
  73. created_at = Column(DateTime, default=datetime.datetime.now)
  74. editor_id = Column(Integer, comment="最后编辑人ID")
  75. editor_name = Column(String(32), comment="最后编辑人名称")
  76. updated_at = Column(DateTime,
  77. default=datetime.datetime.now,
  78. onupdate=datetime.datetime.now)
  79. __tablename__ = "sys_user"
  80. __table_args__ = (UniqueConstraint("phone", name="uix_sysuser_phone"),
  81. UniqueConstraint("username", name="uix_sysuser_username"))