duty_models.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """值班排班模型 — docs/superpowers/specs/2026-08-14-duty-schedule-design.md"""
  2. from datetime import datetime
  3. from sqlalchemy import Column, Date, DateTime, Integer, SmallInteger, String
  4. from app.core.database import Base
  5. SHIFT_MORNING = "morning"
  6. SHIFT_EVENING = "evening"
  7. SHIFT_DUTY = "duty"
  8. SHIFT_LABELS = {
  9. SHIFT_MORNING: "早班",
  10. SHIFT_EVENING: "晚班",
  11. SHIFT_DUTY: "值班",
  12. }
  13. LINK_OPEN = "open"
  14. LINK_CLOSED = "closed"
  15. SOURCE_ASSIGN = "assign"
  16. SOURCE_GRAB = "grab"
  17. # 可排班名单角色(sys_role 固定 id;无菜单,仅标签)
  18. DUTY_STAFF_ROLE_ID = "R65CAAE057914CCCAE2A81BE627A5101"
  19. DUTY_STAFF_ROLE_NAME = "值班人员"
  20. class DutyDay(Base):
  21. __tablename__ = "duty_day"
  22. id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
  23. duty_date = Column(Date, nullable=False, comment="值班日期")
  24. access_token = Column(String(64), nullable=False, comment="公开访问令牌")
  25. link_status = Column(String(16), nullable=False, default=LINK_OPEN, comment="open/closed")
  26. tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
  27. order_num = Column(Integer, nullable=True, comment="排序号")
  28. remark = Column(String(500), nullable=True, comment="备注")
  29. create_by = Column(String(64), nullable=True, comment="创建者")
  30. create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
  31. create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
  32. update_by = Column(String(64), nullable=True, comment="更新者")
  33. update_time = Column(
  34. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  35. )
  36. del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标志")
  37. class DutySlot(Base):
  38. __tablename__ = "duty_slot"
  39. id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
  40. duty_day_id = Column(String(64), nullable=False, comment="值班日ID")
  41. shift_type = Column(String(32), nullable=False, comment="morning/evening/duty")
  42. capacity = Column(Integer, nullable=False, default=1, comment="名额")
  43. tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
  44. order_num = Column(Integer, nullable=True, comment="排序号")
  45. remark = Column(String(500), nullable=True, comment="班次工作安排")
  46. create_by = Column(String(64), nullable=True, comment="创建者")
  47. create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
  48. create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
  49. update_by = Column(String(64), nullable=True, comment="更新者")
  50. update_time = Column(
  51. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  52. )
  53. del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标志")
  54. class DutyAssignment(Base):
  55. __tablename__ = "duty_assignment"
  56. id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
  57. duty_slot_id = Column(String(64), nullable=False, comment="班次名额ID")
  58. source = Column(String(16), nullable=False, comment="assign/grab")
  59. user_id = Column(String(64), nullable=True, comment="系统用户ID(指定时)")
  60. person_name = Column(String(64), nullable=False, comment="展示姓名")
  61. tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
  62. order_num = Column(Integer, nullable=True, comment="排序号")
  63. remark = Column(String(500), nullable=True, comment="备注")
  64. create_by = Column(String(64), nullable=True, comment="创建者")
  65. create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
  66. create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
  67. update_by = Column(String(64), nullable=True, comment="更新者")
  68. update_time = Column(
  69. DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
  70. )
  71. del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标志")