2024-07-31 04:58:29 +08:00
|
|
|
from datetime import datetime
|
2024-09-29 20:47:58 +08:00
|
|
|
from typing import Any, Generic, TypeVar
|
2024-07-31 04:58:29 +08:00
|
|
|
|
|
|
|
|
from pydantic import BaseModel, validator
|
|
|
|
|
|
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
2024-10-15 03:44:30 +08:00
|
|
|
RT = TypeVar("RT")
|
|
|
|
|
|
2024-07-31 04:58:29 +08:00
|
|
|
|
|
|
|
|
class User(BaseModel):
|
|
|
|
|
username: str
|
|
|
|
|
password: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Token(BaseModel):
|
|
|
|
|
access_token: str
|
|
|
|
|
token_type: str
|
|
|
|
|
|
|
|
|
|
|
2024-10-15 03:44:30 +08:00
|
|
|
class Result(Generic[RT], BaseModel):
|
2024-07-31 04:58:29 +08:00
|
|
|
"""
|
|
|
|
|
总体返回
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
suc: bool
|
|
|
|
|
"""调用状态"""
|
|
|
|
|
code: int = 200
|
|
|
|
|
"""code"""
|
|
|
|
|
info: str = "操作成功"
|
|
|
|
|
"""info"""
|
2024-09-29 20:47:58 +08:00
|
|
|
warning: str | None = None
|
2024-07-31 04:58:29 +08:00
|
|
|
"""警告信息"""
|
2024-12-25 12:03:49 +08:00
|
|
|
data: RT | None = None
|
2024-07-31 04:58:29 +08:00
|
|
|
"""返回数据"""
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2024-10-15 03:44:30 +08:00
|
|
|
def warning_(cls, info: str, code: int = 200) -> "Result[RT]":
|
2024-07-31 04:58:29 +08:00
|
|
|
return cls(suc=True, warning=info, code=code)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2024-10-15 03:44:30 +08:00
|
|
|
def fail(cls, info: str = "异常错误", code: int = 500) -> "Result[RT]":
|
2024-07-31 04:58:29 +08:00
|
|
|
return cls(suc=False, info=info, code=code)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2024-10-15 03:44:30 +08:00
|
|
|
def ok(
|
|
|
|
|
cls, data: Any = None, info: str = "操作成功", code: int = 200
|
|
|
|
|
) -> "Result[RT]":
|
2024-07-31 04:58:29 +08:00
|
|
|
return cls(suc=True, info=info, code=code, data=data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QueryModel(BaseModel, Generic[T]):
|
|
|
|
|
"""
|
|
|
|
|
基本查询条件
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
index: int
|
|
|
|
|
"""页数"""
|
|
|
|
|
size: int
|
|
|
|
|
"""每页数量"""
|
|
|
|
|
data: T
|
|
|
|
|
"""携带数据"""
|
|
|
|
|
|
|
|
|
|
@validator("index")
|
|
|
|
|
def index_validator(cls, index):
|
|
|
|
|
if index < 1:
|
|
|
|
|
raise ValueError("查询下标小于1...")
|
|
|
|
|
return index
|
|
|
|
|
|
|
|
|
|
@validator("size")
|
|
|
|
|
def size_validator(cls, size):
|
|
|
|
|
if size < 1:
|
|
|
|
|
raise ValueError("每页数量小于1...")
|
|
|
|
|
return size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseResultModel(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
基础返回
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
total: int
|
|
|
|
|
"""总页数"""
|
|
|
|
|
data: Any
|
|
|
|
|
"""数据"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemStatus(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
系统状态
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
cpu: float
|
|
|
|
|
memory: float
|
|
|
|
|
disk: float
|
|
|
|
|
check_time: datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemFolderSize(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
资源文件占比
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
name: str
|
|
|
|
|
"""名称"""
|
|
|
|
|
size: float
|
|
|
|
|
"""大小"""
|
2024-09-29 20:47:58 +08:00
|
|
|
full_path: str | None
|
2024-07-31 04:58:29 +08:00
|
|
|
"""完整路径"""
|
|
|
|
|
is_dir: bool
|
|
|
|
|
"""是否为文件夹"""
|