from datetime import datetime from sqlalchemy import BigInteger, Boolean, DateTime, Integer, JSON, SmallInteger, String from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base from app.models.mixins import TimestampMixin BIGINT_PK = BigInteger().with_variant(Integer, "sqlite") class User(TimestampMixin, Base): """用户端用户表:按 Django 用户中心确定字段建模,只读取不承担登录注册职责。""" __tablename__ = "user" id: Mapped[int] = mapped_column(BIGINT_PK, primary_key=True, autoincrement=True, comment="用户ID") username: Mapped[str] = mapped_column(String(50), nullable=False, unique=True, index=True, comment="用户名") password: Mapped[str] = mapped_column(String(255), nullable=False, comment="密码哈希") real_name: Mapped[str] = mapped_column(String(50), nullable=False, comment="真实姓名") phone: Mapped[str] = mapped_column(String(20), nullable=False, unique=True, index=True, comment="手机号") avatar: Mapped[str] = mapped_column(String(255), nullable=False, default="", comment="头像") gender: Mapped[int] = mapped_column(SmallInteger, nullable=False, default=0, comment="性别") role_type: Mapped[str] = mapped_column(String(30), nullable=False, comment="角色类型") title_name: Mapped[str] = mapped_column(String(50), nullable=False, default="", comment="职称") major: Mapped[str] = mapped_column(String(100), nullable=False, default="", comment="专业") training_stage: Mapped[str] = mapped_column(String(50), nullable=False, default="", comment="培训阶段") learning_target: Mapped[str] = mapped_column(String(255), nullable=False, default="", comment="学习目标") competency_profile: Mapped[dict] = mapped_column(JSON, nullable=False, default=dict, comment="能力画像") weak_dimensions: Mapped[list] = mapped_column(JSON, nullable=False, default=list, comment="薄弱维度") strong_dimensions: Mapped[list] = mapped_column(JSON, nullable=False, default=list, comment="优势维度") ai_preference: Mapped[dict] = mapped_column(JSON, nullable=False, default=dict, comment="AI偏好") total_training_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0, comment="训练次数") total_case_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0, comment="病例数") current_level: Mapped[str] = mapped_column(String(30), nullable=False, default="", comment="当前等级") status: Mapped[int] = mapped_column(SmallInteger, nullable=False, default=1, comment="状态") last_login: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="最后登录") last_login_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="最后登录时间") is_superuser: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, comment="是否超级用户") is_staff: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, comment="是否员工") is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, comment="是否激活") date_joined: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, comment="加入时间") department_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="科室ID") institution_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True, comment="机构ID") __table_args__ = {"comment": "用户表"}