finalize medical consultation agent backend

This commit is contained in:
刘金宝
2026-06-03 15:51:46 +08:00
parent 93d9e1c6a5
commit eb43573a44
33 changed files with 1063 additions and 281 deletions
+34 -21
View File
@@ -1,33 +1,46 @@
from datetime import datetime
from sqlalchemy import DateTime, Integer, JSON, Numeric, String
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):
"""宿主用户引用:保存外部 user_id,不承担登录注册职责。"""
"""用户端用户表:按 Django 用户中心确定字段建模,只读取不承担登录注册职责。"""
__tablename__ = "users"
__tablename__ = "user"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
external_user_id: Mapped[str] = mapped_column(String(128), nullable=False, unique=True, index=True)
display_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
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")
class UserLearningProfile(TimestampMixin, Base):
"""学习档案模型:聚合完整评价记录形成用户能力画像。"""
__tablename__ = "user_learning_profiles"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
user_id: Mapped[str] = mapped_column(String(128), nullable=False, index=True)
tenant_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
total_evaluations: Mapped[int] = mapped_column(Integer, default=0)
avg_score_percentage: Mapped[float | None] = mapped_column(Numeric(6, 2))
avg_score_five_point: Mapped[float | None] = mapped_column(Numeric(4, 2))
weak_dimensions: Mapped[list | None] = mapped_column(JSON)
last_evaluation_id: Mapped[int | None] = mapped_column(Integer)
last_trained_at: Mapped[datetime | None] = mapped_column(DateTime, index=True)
__table_args__ = {"comment": "用户表"}