# ============================================================================= # 角色映射规则模型 — role_mapping_rules 表 # ============================================================================= # 说明:定义角色自动映射规则,支持企微标签和eHR字段两种来源 # ============================================================================= import uuid from datetime import datetime from sqlalchemy import String, Boolean, DateTime, Integer, ForeignKey, Index from sqlalchemy.orm import Mapped, mapped_column from app.database import Base class RoleMappingRule(Base): """角色映射规则模型 — 对应 role_mapping_rules 表。 定义自动映射规则,当用户满足条件时自动获得对应角色: - wecom_tag: 企微标签匹配(如标签包含"IT坐席") - ehr_position: eHR岗位关键词匹配(如岗位包含"IT支持") """ __tablename__ = "role_mapping_rules" __table_args__ = ( # 按 role_id 查询优化 Index("idx_role_mapping_rules_role_id", "role_id"), # 按 source_type 查询优化 Index("idx_role_mapping_rules_source_type", "source_type"), ) # 主键:UUID id: Mapped[str] = mapped_column( String(36), primary_key=True, default=lambda: str(uuid.uuid4()), ) # 角色 ID(外键) role_id: Mapped[str] = mapped_column( String(36), ForeignKey("roles.id", ondelete="CASCADE"), nullable=False, comment="目标角色 ID", ) # 来源类型:wecom_tag/ehr_position source_type: Mapped[str] = mapped_column( String(50), nullable=False, comment="来源类型:wecom_tag/ehr_position", ) # 来源值:标签名/岗位关键词 source_value: Mapped[str] = mapped_column( String(200), nullable=False, comment="来源值:标签名/岗位关键词", ) # 优先级(数值越大优先级越高) priority: Mapped[int] = mapped_column( Integer, nullable=False, default=0, comment="优先级(数值越大优先级越高)", ) # 是否启用 is_active: Mapped[bool] = mapped_column( Boolean, nullable=False, default=True, comment="是否启用", ) # 创建时间 created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, default=datetime.now, comment="创建时间", ) def __repr__(self) -> str: return ( f"" )