103 lines
3.0 KiB
Python
103 lines
3.0 KiB
Python
|
|
"""
|
||
|
|
系统配置相关Schema
|
||
|
|
"""
|
||
|
|
from pydantic import BaseModel, Field, validator
|
||
|
|
from typing import Optional, Dict, Any, List
|
||
|
|
from datetime import datetime
|
||
|
|
from enum import Enum
|
||
|
|
|
||
|
|
|
||
|
|
class ConfigType(str, Enum):
|
||
|
|
"""配置类型"""
|
||
|
|
STRING = "STRING"
|
||
|
|
NUMBER = "NUMBER"
|
||
|
|
BOOLEAN = "BOOLEAN"
|
||
|
|
JSON = "JSON"
|
||
|
|
|
||
|
|
|
||
|
|
class ConfigCategory(str, Enum):
|
||
|
|
"""配置分类"""
|
||
|
|
GAME_ECONOMY = "GAME_ECONOMY" # 游戏经济配置
|
||
|
|
GAME_LOGIC = "GAME_LOGIC" # 游戏逻辑配置
|
||
|
|
SYSTEM_OPERATIONS = "SYSTEM_OPERATIONS" # 系统运维配置
|
||
|
|
UI_DISPLAY = "UI_DISPLAY" # 界面显示配置
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigBase(BaseModel):
|
||
|
|
config_key: str = Field(..., min_length=1, max_length=64, description="配置键")
|
||
|
|
config_value: str = Field(..., min_length=1, description="配置值")
|
||
|
|
config_type: ConfigType = Field(default=ConfigType.STRING, description="配置类型")
|
||
|
|
category: ConfigCategory = Field(default=ConfigCategory.SYSTEM_OPERATIONS, description="配置分类")
|
||
|
|
description: Optional[str] = Field(None, max_length=255, description="配置描述")
|
||
|
|
is_editable: bool = Field(default=True, description="是否可编辑")
|
||
|
|
is_public: bool = Field(default=False, description="是否对前端公开")
|
||
|
|
display_order: int = Field(default=0, ge=0, le=999, description="显示顺序")
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigCreate(SystemConfigBase):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigUpdate(BaseModel):
|
||
|
|
config_value: Optional[str] = Field(None, min_length=1, description="配置值")
|
||
|
|
description: Optional[str] = Field(None, max_length=255, description="配置描述")
|
||
|
|
is_editable: Optional[bool] = Field(None, description="是否可编辑")
|
||
|
|
is_public: Optional[bool] = Field(None, description="是否对前端公开")
|
||
|
|
display_order: Optional[int] = Field(None, ge=0, le=999, description="显示顺序")
|
||
|
|
|
||
|
|
@validator('config_value')
|
||
|
|
def validate_config_value(cls, v):
|
||
|
|
if v is not None and len(v.strip()) == 0:
|
||
|
|
raise ValueError('配置值不能为空')
|
||
|
|
return v
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigResponse(SystemConfigBase):
|
||
|
|
id: int
|
||
|
|
created_at: datetime
|
||
|
|
updated_at: datetime
|
||
|
|
|
||
|
|
class Config:
|
||
|
|
from_attributes = True
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigGroup(BaseModel):
|
||
|
|
"""配置分组"""
|
||
|
|
category: ConfigCategory
|
||
|
|
category_name: str
|
||
|
|
category_description: str
|
||
|
|
configs: List[SystemConfigResponse]
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigBatchUpdate(BaseModel):
|
||
|
|
"""批量更新配置"""
|
||
|
|
configs: Dict[str, Any] = Field(..., description="配置项字典")
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigInit(BaseModel):
|
||
|
|
"""初始化系统配置"""
|
||
|
|
configs: Dict[str, Dict[str, Any]] = Field(
|
||
|
|
...,
|
||
|
|
description="初始配置项字典,格式:{key: {value, type, description, category}}"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigValue(BaseModel):
|
||
|
|
"""配置值"""
|
||
|
|
key: str
|
||
|
|
value: str
|
||
|
|
type: str
|
||
|
|
|
||
|
|
|
||
|
|
class ConfigValueUpdate(BaseModel):
|
||
|
|
"""更新配置值"""
|
||
|
|
value: str
|
||
|
|
|
||
|
|
|
||
|
|
class SystemConfigSummary(BaseModel):
|
||
|
|
"""配置概览"""
|
||
|
|
total_configs: int
|
||
|
|
editable_configs: int
|
||
|
|
public_configs: int
|
||
|
|
category_counts: Dict[str, int]
|