| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  | from datetime import datetime | 
					
						
							|  |  |  |  | from typing import Optional, List, Dict | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | from pydantic import BaseModel, Field | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # ------------------------------ | 
					
						
							| 
									
										
										
										
											2025-09-04 12:29:27 +08:00
										 |  |  |  | # 请求模型 | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  | # ------------------------------ | 
					
						
							|  |  |  |  | class DeviceCreateRequest(BaseModel): | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     """设备创建请求模型""" | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  |     ip: Optional[str] = Field(..., max_length=100, description="设备IP地址") | 
					
						
							|  |  |  |  |     hostname: Optional[str] = Field(None, max_length=100, description="设备别名") | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     params: Optional[Dict] = Field(None, description="设备扩展参数(JSON格式)") | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # ------------------------------ | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  | # 响应模型 | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  | # ------------------------------ | 
					
						
							|  |  |  |  | class DeviceResponse(BaseModel): | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     """单设备信息响应模型(与数据库表字段对齐)""" | 
					
						
							| 
									
										
										
										
											2025-09-04 12:29:27 +08:00
										 |  |  |  |     id: int = Field(..., description="设备主键ID") | 
					
						
							|  |  |  |  |     client_ip: Optional[str] = Field(None, max_length=100, description="设备IP地址") | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  |     hostname: Optional[str] = Field(None, max_length=100, description="设备别名") | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     device_online_status: int = Field(..., description="在线状态(1-在线、0-离线)") | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  |     device_type: Optional[str] = Field(None, description="设备类型") | 
					
						
							|  |  |  |  |     alarm_count: int = Field(..., description="报警次数") | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     params: Optional[str] = Field(None, description="扩展参数(JSON字符串)") | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  |     created_at: datetime = Field(..., description="记录创建时间") | 
					
						
							|  |  |  |  |     updated_at: datetime = Field(..., description="记录更新时间") | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     model_config = {"from_attributes": True}  # 支持从数据库结果直接转换 | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class DeviceListResponse(BaseModel): | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  |     """设备列表响应模型""" | 
					
						
							| 
									
										
										
										
											2025-09-02 18:51:50 +08:00
										 |  |  |  |     total: int = Field(..., description="设备总数") | 
					
						
							|  |  |  |  |     devices: List[DeviceResponse] = Field(..., description="设备列表") | 
					
						
							| 
									
										
										
										
											2025-09-12 18:28:43 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class DeviceStatusHistoryResponse(BaseModel): | 
					
						
							|  |  |  |  |     """设备上下线记录响应模型""" | 
					
						
							|  |  |  |  |     id: int = Field(..., description="记录ID") | 
					
						
							|  |  |  |  |     device_id: int = Field(..., description="关联设备ID") | 
					
						
							|  |  |  |  |     client_ip: Optional[str] = Field(None, description="设备IP地址") | 
					
						
							|  |  |  |  |     status: int = Field(..., description="状态(1-在线、0-离线)") | 
					
						
							|  |  |  |  |     status_time: datetime = Field(..., description="状态变更时间") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     model_config = {"from_attributes": True} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class DeviceStatusHistoryListResponse(BaseModel): | 
					
						
							|  |  |  |  |     """设备上下线记录列表响应模型""" | 
					
						
							|  |  |  |  |     total: int = Field(..., description="记录总数") | 
					
						
							|  |  |  |  |     history: List[DeviceStatusHistoryResponse] = Field(..., description="上下线记录列表") |