2023-02-07 08:48:41 +08:00
|
|
|
import uuid
|
|
|
|
from sqlalchemy.orm import relationship
|
2023-02-07 16:09:57 +08:00
|
|
|
from sqlalchemy import Column, String, Boolean, ForeignKey, Enum, Text, DateTime, func, Integer
|
2023-02-07 08:48:41 +08:00
|
|
|
|
|
|
|
from Utils.SqlAlchemyUtils import Base
|
|
|
|
|
|
|
|
|
|
|
|
class User(Base):
|
|
|
|
__tablename__ = "USER_TABLE"
|
2023-02-07 16:09:57 +08:00
|
|
|
id = Column(String(32), primary_key=True, default=lambda: uuid.uuid4().hex, comment="用户ID")
|
2023-02-07 08:48:41 +08:00
|
|
|
email = Column(String(64), unique=True, index=True, comment="邮箱")
|
|
|
|
password = Column(String(255))
|
2023-02-07 16:09:57 +08:00
|
|
|
name = Column(String(32), comment="用户名")
|
2023-02-07 08:48:41 +08:00
|
|
|
avatar = Column(String(255), comment="头像路径")
|
|
|
|
role = Column(Enum('admin', 'normal'), default="normal", comment="角色")
|
|
|
|
department = Column(Text, comment="部门")
|
|
|
|
post = Column(Text, comment="职务")
|
|
|
|
disable = Column(Boolean, default=False, comment="禁用时间")
|
|
|
|
auth_data = Column(Text, comment="权限数据")
|
|
|
|
create_time = Column(DateTime, server_default=func.now(), comment='创建时间')
|
|
|
|
update_time = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment='修改时间')
|
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
|
|
|
|
|
|
|
def as_info(self):
|
|
|
|
org_info = self.to_dict()
|
|
|
|
info = org_info.copy()
|
|
|
|
for key in org_info:
|
2023-02-07 16:09:57 +08:00
|
|
|
if key not in ["password", "create_time", "update_time"]:
|
2023-02-07 08:48:41 +08:00
|
|
|
info[key] = org_info[key]
|
|
|
|
return info
|
2023-02-07 16:09:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|