Files
video/schema/device_schema.py
ZZX9599 b5d870a19c 优化
2025-09-04 12:29:27 +08:00

40 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from datetime import datetime
from typing import Optional, List, Dict
from pydantic import BaseModel, Field
# ------------------------------
# 请求模型
# ------------------------------
class DeviceCreateRequest(BaseModel):
"""设备流信息创建请求模型(与数据库表字段对齐)"""
ip: Optional[str] = Field(..., max_length=100, description="设备IP地址")
hostname: Optional[str] = Field(None, max_length=100, description="设备别名")
params: Optional[Dict] = Field(None, description="设备详细信息JSON格式")
# ------------------------------
# 响应模型(后端返回数据)- 严格对齐数据库表字段
# ------------------------------
class DeviceResponse(BaseModel):
"""设备流信息响应模型(与数据库表字段完全一致)"""
id: int = Field(..., description="设备主键ID")
client_ip: Optional[str] = Field(None, max_length=100, description="设备IP地址")
hostname: Optional[str] = Field(None, max_length=100, description="设备别名")
device_online_status: int = Field(..., description="设备在线状态1-在线、0-离线)")
device_type: Optional[str] = Field(None, description="设备类型")
alarm_count: int = Field(..., description="报警次数")
params: Optional[str] = Field(None, description="设备详细信息JSON字符串")
created_at: datetime = Field(..., description="记录创建时间")
updated_at: datetime = Field(..., description="记录更新时间")
# 支持从数据库查询结果直接转换
model_config = {"from_attributes": True}
class DeviceListResponse(BaseModel):
"""设备流信息列表响应模型"""
total: int = Field(..., description="设备总数")
devices: List[DeviceResponse] = Field(..., description="设备列表")