mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
refactor(base_crud): 优化数据权限过滤逻辑 fix(user): 修正用户详情部门查询错误 feat(menu): 添加菜单标题字段并优化路由更新 style(auth): 优化登录页面背景样式 fix(profile): 修复表单样式问题 perf(redis): 优化缓存清除逻辑 fix(role): 移除默认角色操作限制 chore: 清理无用导入和注释
119 lines
3.8 KiB
Python
119 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from datetime import datetime
|
|
from sqlalchemy import Boolean, Column, String, Integer, DateTime, ForeignKey, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.core.base_model import ModelBase
|
|
|
|
|
|
class UserRolesModel(ModelBase):
|
|
"""
|
|
用户角色关联表
|
|
"""
|
|
__tablename__ = "system_user_roles"
|
|
__table_args__ = ({'comment': '用户角色关联表'})
|
|
|
|
user_id = Column(
|
|
Integer,
|
|
ForeignKey("system_users.id", ondelete="CASCADE", onupdate="CASCADE"),
|
|
primary_key=True,
|
|
comment="用户ID",
|
|
index=True
|
|
)
|
|
role_id = Column(
|
|
Integer,
|
|
ForeignKey("system_role.id", ondelete="CASCADE", onupdate="CASCADE"),
|
|
primary_key=True,
|
|
comment="角色ID",
|
|
index=True
|
|
)
|
|
|
|
class UserPositionsModel(ModelBase):
|
|
"""
|
|
用户岗位关联表
|
|
"""
|
|
__tablename__ = "system_user_positions"
|
|
__table_args__ = ({'comment': '用户岗位关联表'})
|
|
|
|
user_id = Column(
|
|
Integer,
|
|
ForeignKey("system_users.id", ondelete="CASCADE", onupdate="CASCADE"),
|
|
primary_key=True,
|
|
comment="用户ID",
|
|
index=True
|
|
)
|
|
position_id = Column(
|
|
Integer,
|
|
ForeignKey("system_position.id", ondelete="CASCADE", onupdate="CASCADE"),
|
|
primary_key=True,
|
|
comment="岗位ID",
|
|
index=True
|
|
)
|
|
|
|
class UserModel(ModelBase):
|
|
"""
|
|
用户表 - 存储系统用户基本信息
|
|
"""
|
|
__tablename__ = "system_users"
|
|
__table_args__ = ({'comment': '用户表'})
|
|
|
|
# 基础字段
|
|
id = Column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
|
|
username = Column(String(150), nullable=False, unique=True, comment="用户名/登录账号")
|
|
password = Column(String(128), nullable=False, comment="密码")
|
|
name = Column(String(40), nullable=False, comment="姓名")
|
|
|
|
# 联系信息
|
|
mobile = Column(String(20), nullable=True, comment="手机号")
|
|
email = Column(String(255), nullable=True, comment="邮箱")
|
|
|
|
# 个人信息
|
|
gender = Column(String(20), default=2, nullable=True, comment="性别(0:男 1:女 2:未知)")
|
|
avatar = Column(String(255), nullable=True, comment="头像地址")
|
|
|
|
# 账号状态
|
|
status = Column(Boolean, default=True, nullable=False, comment="是否启用(True:启用 False:禁用)")
|
|
is_superuser = Column(Boolean, default=False, nullable=False, comment="是否为超级管理员")
|
|
last_login = Column(DateTime, nullable=True, comment="最后登录时间")
|
|
|
|
# 组织信息
|
|
dept_id = Column(
|
|
Integer,
|
|
ForeignKey('system_dept.id', ondelete="SET NULL", onupdate="CASCADE"),
|
|
nullable=True, index=True, comment="部门ID"
|
|
)
|
|
dept = relationship(
|
|
'DeptModel',
|
|
primaryjoin="UserModel.dept_id == DeptModel.id",
|
|
lazy="select",
|
|
uselist=False)
|
|
roles = relationship(
|
|
"RoleModel",
|
|
secondary=UserRolesModel.__tablename__,
|
|
lazy="joined",
|
|
uselist=True)
|
|
positions = relationship(
|
|
"PositionModel",
|
|
secondary=UserPositionsModel.__tablename__,
|
|
lazy="joined",
|
|
uselist=True)
|
|
|
|
# 审计字段
|
|
description = Column(Text, nullable=True, comment="备注说明")
|
|
created_at = Column(DateTime, default=datetime.now, comment='创建时间')
|
|
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
|
|
creator_id = Column(
|
|
Integer,
|
|
ForeignKey("system_users.id", ondelete="SET NULL", onupdate="CASCADE"),
|
|
nullable=True,
|
|
index=True,
|
|
comment="创建人ID"
|
|
)
|
|
creator = relationship(
|
|
"UserModel",
|
|
remote_side=[id],
|
|
foreign_keys=[creator_id],
|
|
lazy="selectin",
|
|
uselist=False
|
|
) |