v3.1 + 批次0: 智能回复重构基线 - ApprovalMatcher + 关键词降级 + 文档速修 + v4.0任务书面化
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
# =============================================================================
|
||||
# 企微IT智能服务台 — 欢迎与引导配置模型
|
||||
# =============================================================================
|
||||
# 说明:存储员工端H5的欢迎页、引导视频、互动教学、主题模板配置
|
||||
# 使用 SystemConfig 表存储,config_key 为 welcome_config
|
||||
# =============================================================================
|
||||
|
||||
import json
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any, Optional
|
||||
|
||||
from sqlalchemy import DateTime, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class WelcomeConfig:
|
||||
"""欢迎与引导配置数据类。
|
||||
|
||||
用于在内存中处理配置数据,不直接对应数据库表。
|
||||
实际存储使用 SystemConfig 表,config_key 为 "welcome_config"。
|
||||
|
||||
Attributes:
|
||||
welcome_page: 欢迎页配置
|
||||
welcome_video: 引导视频配置
|
||||
tutorial: 互动教学配置
|
||||
theme: 主题模板配置
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
welcome_page: Optional[dict[str, Any]] = None,
|
||||
welcome_video: Optional[dict[str, Any]] = None,
|
||||
tutorial: Optional[dict[str, Any]] = None,
|
||||
theme: Optional[dict[str, Any]] = None,
|
||||
):
|
||||
self.welcome_page = welcome_page or {
|
||||
"enabled": False,
|
||||
"title": "欢迎使用IT服务台",
|
||||
"content": "在这里您可以提交IT问题申请,获取快速支持",
|
||||
"background_color": "#07C160",
|
||||
}
|
||||
self.welcome_video = welcome_video
|
||||
self.tutorial = tutorial or {
|
||||
"enabled": False,
|
||||
"steps": [],
|
||||
}
|
||||
self.theme = theme or {
|
||||
"theme": "default",
|
||||
}
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
"""转换为字典格式。"""
|
||||
return {
|
||||
"welcome_page": self.welcome_page,
|
||||
"welcome_video": self.welcome_video,
|
||||
"tutorial": self.tutorial,
|
||||
"theme": self.theme,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "WelcomeConfig":
|
||||
"""从字典创建配置对象。"""
|
||||
return cls(
|
||||
welcome_page=data.get("welcome_page"),
|
||||
welcome_video=data.get("welcome_video"),
|
||||
tutorial=data.get("tutorial"),
|
||||
theme=data.get("theme"),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_default(cls) -> "WelcomeConfig":
|
||||
"""获取默认配置。"""
|
||||
return cls()
|
||||
|
||||
# 静态方法:用于从 SystemConfig 读取和保存
|
||||
CONFIG_KEY = "welcome_config"
|
||||
|
||||
@staticmethod
|
||||
def serialize(config: "WelcomeConfig") -> str:
|
||||
"""序列化配置为 JSON 字符串。"""
|
||||
return json.dumps(config.to_dict(), ensure_ascii=False)
|
||||
|
||||
@staticmethod
|
||||
def deserialize(config_value: str) -> "WelcomeConfig":
|
||||
"""从 JSON 字符串反序列化配置。"""
|
||||
try:
|
||||
data = json.loads(config_value)
|
||||
return WelcomeConfig.from_dict(data)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
return WelcomeConfig.get_default()
|
||||
Reference in New Issue
Block a user