2025-09-04 12:29:27 +08:00
|
|
|
|
from datetime import datetime
|
|
|
|
|
from typing import Optional, List
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------
|
2025-09-08 17:34:23 +08:00
|
|
|
|
# 请求模型
|
2025-09-04 12:29:27 +08:00
|
|
|
|
# ------------------------------
|
|
|
|
|
class DeviceActionCreate(BaseModel):
|
2025-09-08 17:34:23 +08:00
|
|
|
|
"""设备操作记录创建模型(0=离线、1=上线)"""
|
2025-09-04 12:29:27 +08:00
|
|
|
|
client_ip: str = Field(..., description="客户端IP")
|
2025-09-08 17:34:23 +08:00
|
|
|
|
action: int = Field(..., ge=0, le=1, description="操作状态(0=离线、1=上线)")
|
2025-09-04 12:29:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------
|
|
|
|
|
# 响应模型(单条记录)
|
|
|
|
|
# ------------------------------
|
|
|
|
|
class DeviceActionResponse(BaseModel):
|
|
|
|
|
"""设备操作记录响应模型(与自增表对齐)"""
|
|
|
|
|
id: int = Field(..., description="自增主键ID")
|
|
|
|
|
client_ip: Optional[str] = Field(None, description="客户端IP")
|
2025-09-08 17:34:23 +08:00
|
|
|
|
action: Optional[int] = Field(None, description="操作状态(0=离线、1=上线)")
|
2025-09-04 12:29:27 +08:00
|
|
|
|
created_at: datetime = Field(..., description="记录创建时间")
|
|
|
|
|
updated_at: datetime = Field(..., description="记录更新时间")
|
|
|
|
|
|
|
|
|
|
# 支持从数据库结果直接转换
|
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------
|
|
|
|
|
# 列表响应模型(仅含 total + device_actions)
|
|
|
|
|
# ------------------------------
|
|
|
|
|
class DeviceActionListResponse(BaseModel):
|
|
|
|
|
"""设备操作记录列表(仅核心返回字段)"""
|
|
|
|
|
total: int = Field(..., description="总记录数")
|
|
|
|
|
device_actions: List[DeviceActionResponse] = Field(..., description="操作记录列表")
|