增加后台管理项目;
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from .base import BaseOut
|
||||
from .message import Message
|
||||
from .glm_role import GLMRole
|
||||
|
||||
models = [Message]
|
||||
models = [Message, GLMRole]
|
||||
|
||||
# 在所有模型导入后调用 model_rebuild 来解决循环导入问题
|
||||
# Message.model_rebuild()
|
||||
|
||||
56
backend/app/models/glm_role.py
Normal file
56
backend/app/models/glm_role.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from pydantic import Field
|
||||
from beanie import Document
|
||||
import arrow
|
||||
|
||||
|
||||
class GLMRole(Document):
|
||||
"""GLM角色配置模型"""
|
||||
|
||||
# 基本信息
|
||||
name: str = Field(..., description="角色名称")
|
||||
description: str = Field(..., description="角色描述")
|
||||
skills: str = Field(default="", description="技能列表(多行文本字符串)")
|
||||
restrictions: str = Field(default="", description="限制列表(多行文本字符串)")
|
||||
|
||||
# 状态管理
|
||||
is_active: bool = Field(default=True, description="是否激活")
|
||||
is_default: bool = Field(default=False, description="是否为默认角色")
|
||||
|
||||
# 时间戳
|
||||
created_at: datetime = Field(default_factory=lambda: arrow.now().datetime)
|
||||
updated_at: datetime = Field(default_factory=lambda: arrow.now().datetime)
|
||||
|
||||
class Settings:
|
||||
name = "glm_roles" # MongoDB集合名称
|
||||
indexes = [
|
||||
[("is_active", 1)], # 按激活状态查询
|
||||
[("is_default", 1)], # 按默认状态查询
|
||||
[("created_at", -1)], # 按创建时间排序
|
||||
]
|
||||
|
||||
def update_timestamp(self):
|
||||
"""更新更新时间戳"""
|
||||
self.updated_at = arrow.now().datetime
|
||||
|
||||
@classmethod
|
||||
def from_role_config(cls, role_config: dict) -> "GLMRole":
|
||||
"""从角色配置字典创建GLMRole实例"""
|
||||
return cls(
|
||||
name=role_config.get("name", ""),
|
||||
description=role_config.get("description", ""),
|
||||
skills=role_config.get("skills", ""),
|
||||
restrictions=role_config.get("restrictions", ""),
|
||||
is_active=True,
|
||||
is_default=True,
|
||||
)
|
||||
|
||||
def to_role_config_dict(self) -> dict:
|
||||
"""转换为角色配置字典"""
|
||||
return {
|
||||
"name": self.name,
|
||||
"description": self.description,
|
||||
"skills": self.skills,
|
||||
"restrictions": self.restrictions,
|
||||
}
|
||||
Reference in New Issue
Block a user