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

115 lines
3.4 KiB
Python
Raw Normal View History

# =============================================================================
# 企微IT智能服务台 — 排障模板模型
# =============================================================================
# 说明:对应数据库 troubleshooting_templates 表,存储常见问题的排障模板
# 包含排障步骤路径和流程图定义
# =============================================================================
import uuid
from datetime import datetime
from typing import Any, Dict, Optional
from sqlalchemy import Boolean, DateTime, JSON, String
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class TroubleshootingTemplate(Base):
"""排障模板模型 — 对应 troubleshooting_templates 表。
存储常见 IT 问题的标准化排障模板,包括步骤路径和流程图。
分类:vpn/email/system/account 等。
Attributes:
id: 模板唯一标识(UUID,数据库自动生成)
name: 模板名称
category: 分类(vpn/email/system/account
path_steps: 排障步骤路径(JSON,存储步骤序列)
flowchart: 流程图定义(JSON,存储节点和连线)
is_active: 是否启用
created_at: 创建时间
updated_at: 更新时间
"""
# 表名
__tablename__ = "troubleshooting_templates"
# --------------------------------------------------------------------------
# 字段定义
# --------------------------------------------------------------------------
# 主键:UUID
id: Mapped[str] = mapped_column(
String(36),
primary_key=True,
default=lambda: str(uuid.uuid4()),
comment="模板唯一标识",
)
# 模板名称
name: Mapped[str] = mapped_column(
String(256),
nullable=False,
default="",
comment="模板名称",
)
# 分类
category: Mapped[str] = mapped_column(
String(20),
nullable=False,
default="system",
comment="分类: vpn/email/system/account",
)
# 排障步骤路径(JSON 格式)
# 示例:[{"step": 1, "title": "检查VPN连接状态", "action": "..."}, ...]
path_steps: Mapped[list] = mapped_column(
JSON,
nullable=False,
default=list,
comment="排障步骤路径",
)
# 流程图定义(JSON 格式)
# 示例:{"nodes": [...], "edges": [...]}
flowchart: Mapped[Dict[str, Any]] = mapped_column(
JSON,
nullable=False,
default=dict,
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="创建时间",
)
# 更新时间
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
default=datetime.now,
onupdate=datetime.now,
comment="更新时间",
)
def __repr__(self) -> str:
"""排障模板对象的字符串表示。"""
return (
f"<TroubleshootingTemplate(id={self.id}, name={self.name}, "
f"category={self.category}, is_active={self.is_active})>"
)