model.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. from datetime import datetime
  2. from typing import TYPE_CHECKING
  3. from sqlalchemy import JSON, DateTime, ForeignKey, Integer, String, Text
  4. from sqlalchemy.orm import Mapped, mapped_column, relationship
  5. from app.common.enums import PermissionFilterStrategy
  6. from app.core.base_model import PaymentModelMixin, TenantMixin, EnterpriseMixin
  7. if TYPE_CHECKING:
  8. from app.api.v1.module_system.user.model import UserModel
  9. class EmployeeModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  10. """员工模型"""
  11. __tablename__ = "pay_employee"
  12. __table_args__ = {"comment": "员工表"}
  13. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  14. employee_id: Mapped[str | None] = mapped_column(
  15. String(64), unique=True, comment="员工ID(业务主键)"
  16. )
  17. employee_name: Mapped[str | None] = mapped_column(String(128), comment="员工姓名")
  18. employee_no: Mapped[str | None] = mapped_column(
  19. String(64), index=True, comment="员工工号"
  20. )
  21. identity_type: Mapped[str | None] = mapped_column(
  22. String(32), comment="身份类型: ALIPAY_USER_ID/ALIPAY_LOGON_ID/ENTERPRISE_USER_ID"
  23. )
  24. identity: Mapped[str | None] = mapped_column(
  25. String(64), comment="身份标识"
  26. )
  27. identity_open_id: Mapped[str | None] = mapped_column(
  28. String(128), comment="员工openId"
  29. )
  30. employee_mobile: Mapped[str | None] = mapped_column(
  31. String(32), comment="员工手机号"
  32. )
  33. employee_email: Mapped[str | None] = mapped_column(
  34. String(128), comment="员工邮箱"
  35. )
  36. employee_cert_type: Mapped[str | None] = mapped_column(
  37. String(32), comment="证件类型: IDENTITY_CARD/PASSPORT/DRIVER_LICENSE"
  38. )
  39. employee_cert_no: Mapped[str | None] = mapped_column(
  40. String(64), comment="证件号码"
  41. )
  42. status: Mapped[str] = mapped_column(
  43. String(32),
  44. default="EMPLOYEE_CREATE",
  45. comment="状态: EMPLOYEE_CREATE/EMPLOYEE_ACTIVATED/EMPLOYEE_UNSIGN"
  46. )
  47. iot_check_type: Mapped[str | None] = mapped_column(
  48. String(64), comment="IoT核身方式"
  49. )
  50. department_ids: Mapped[list | None] = mapped_column(
  51. JSON, comment="部门ID列表"
  52. )
  53. accounting_entity_ids: Mapped[list | None] = mapped_column(
  54. JSON, comment="核算主体ID列表"
  55. )
  56. label_names: Mapped[list | None] = mapped_column(
  57. JSON, comment="标签名称列表"
  58. )
  59. sign_return_url: Mapped[str | None] = mapped_column(
  60. Text, comment="签约跳转URL"
  61. )
  62. create_share_code: Mapped[bool | None] = mapped_column(
  63. default=False, comment="是否创建分享码"
  64. )
  65. sign_url_carry_info: Mapped[bool | None] = mapped_column(
  66. default=False, comment="签约链接是否携带信息"
  67. )
  68. sign_url: Mapped[str | None] = mapped_column(
  69. Text, comment="邀请链接"
  70. )
  71. share_code: Mapped[str | None] = mapped_column(
  72. String(128), comment="分享码"
  73. )
  74. iot_unique_id: Mapped[str | None] = mapped_column(
  75. String(64), comment="IoT唯一标识"
  76. )
  77. profiles: Mapped[dict | None] = mapped_column(
  78. JSON, comment="扩展参数"
  79. )
  80. withholding_sign_str: Mapped[str | None] = mapped_column(
  81. Text, comment="代扣签约串"
  82. )
  83. free_sign_token: Mapped[str | None] = mapped_column(
  84. String(256), comment="免登签约token"
  85. )
  86. department_list: Mapped[JSON | None] = mapped_column(
  87. JSON, comment="部门列表"
  88. )
  89. role_list: Mapped[JSON | None] = mapped_column(
  90. JSON, comment="角色列表"
  91. )
  92. user_id: Mapped[int | None] = mapped_column(
  93. Integer,
  94. ForeignKey("sys_user.id", ondelete="SET NULL", onupdate="CASCADE"),
  95. nullable=True,
  96. comment="关联的系统用户ID"
  97. )
  98. user: Mapped["UserModel | None"] = relationship(
  99. "UserModel",
  100. foreign_keys="EmployeeModel.user_id",
  101. lazy="selectin",
  102. viewonly=True
  103. )