66 lines
1.6 KiB
Python
66 lines
1.6 KiB
Python
"""用户模型
|
||
|
||
与门户系统关联的用户信息
|
||
"""
|
||
|
||
from typing import List
|
||
|
||
from sqlalchemy import BigInteger, String, Boolean
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from app.models.base import BaseModel
|
||
|
||
|
||
class User(BaseModel):
|
||
"""用户表"""
|
||
|
||
__tablename__ = "users"
|
||
|
||
portal_user_id: Mapped[int] = mapped_column(
|
||
BigInteger,
|
||
unique=True,
|
||
nullable=False,
|
||
index=True,
|
||
comment="门户用户ID"
|
||
)
|
||
username: Mapped[str] = mapped_column(
|
||
String(50),
|
||
nullable=False,
|
||
comment="用户名"
|
||
)
|
||
role: Mapped[str] = mapped_column(
|
||
String(20),
|
||
nullable=False,
|
||
comment="角色:admin-管理员, manager-经理, operator-操作员"
|
||
)
|
||
is_active: Mapped[bool] = mapped_column(
|
||
Boolean,
|
||
nullable=False,
|
||
default=True,
|
||
comment="是否启用"
|
||
)
|
||
|
||
# 关系
|
||
created_projects: Mapped[List["Project"]] = relationship(
|
||
"Project",
|
||
back_populates="creator"
|
||
)
|
||
operation_logs: Mapped[List["OperationLog"]] = relationship(
|
||
"OperationLog",
|
||
back_populates="user"
|
||
)
|
||
created_pricing_plans: Mapped[List["PricingPlan"]] = relationship(
|
||
"PricingPlan",
|
||
back_populates="creator"
|
||
)
|
||
created_profit_simulations: Mapped[List["ProfitSimulation"]] = relationship(
|
||
"ProfitSimulation",
|
||
back_populates="creator"
|
||
)
|
||
|
||
|
||
# 避免循环导入
|
||
from app.models.project import Project
|
||
from app.models.operation_log import OperationLog
|
||
from app.models.pricing_plan import PricingPlan
|
||
from app.models.profit_simulation import ProfitSimulation |