Files
wecom_it_smart_desk/backend/app/models/system_config.py
T

84 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# =============================================================================
# 企微IT智能服务台 — 系统配置模型
# =============================================================================
# 说明:对应数据库 system_configs 表,存储系统级配置项
# 包括:关键词列表、评分阈值、话术模板等
# 优势:配置存在数据库中,支持后台动态修改,无需重启服务
# =============================================================================
import uuid
from datetime import datetime
from sqlalchemy import DateTime, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class SystemConfig(Base):
"""系统配置模型 — 对应 system_configs 表。
将可动态修改的配置项存储在数据库中,
支持后台修改后立即生效,无需重启服务。
Attributes:
id: 配置唯一标识(UUID,数据库自动生成)
config_key: 配置键(唯一,如 "hand_raise_keywords"
config_value: 配置值(JSON 字符串或纯文本)
description: 配置说明
updated_at: 更新时间
"""
# 表名(必须和架构文档 DDL 一致)
__tablename__ = "system_configs"
# --------------------------------------------------------------------------
# 字段定义
# --------------------------------------------------------------------------
# 主键:UUIDPython端生成(兼容PostgreSQL和SQLite
id: Mapped[str] = mapped_column(
String(36),
primary_key=True,
default=lambda: str(uuid.uuid4()),
)
# 配置键(唯一,用于查找配置项)
# 示例:hand_raise_keywords, emotion_keywords_angry, polling_interval_seconds
config_key: Mapped[str] = mapped_column(
String(128),
unique=True,
nullable=False,
comment="配置键",
)
# 配置值(存储 JSON 字符串或纯文本)
# JSON 示例:'["转人工","人工","人工服务"]'
# 纯文本示例:'3'(表示阈值)
config_value: Mapped[str] = mapped_column(
Text,
nullable=False,
comment="配置值(JSON字符串或纯文本)",
)
# 配置说明(方便管理员理解配置用途)
description: Mapped[str] = mapped_column(
String(256),
nullable=False,
default="",
comment="配置说明",
)
# 更新时间(配置修改时自动更新)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
default=datetime.now,
onupdate=datetime.now,
comment="更新时间",
)
def __repr__(self) -> str:
"""配置对象的字符串表示,方便调试。"""
return f"<SystemConfig(key={self.config_key}, value={self.config_value})>"