33 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from datetime import datetime
 | ||
| from typing import Optional, List
 | ||
| from pydantic import BaseModel, Field
 | ||
| 
 | ||
| 
 | ||
| # ------------------------------
 | ||
| # 请求模型
 | ||
| # ------------------------------
 | ||
| class DeviceDangerCreateRequest(BaseModel):
 | ||
|     """设备危险记录创建请求模型"""
 | ||
|     client_ip: str = Field(..., max_length=100, description="设备IP地址(必须与devices表中IP对应)")
 | ||
|     type: str = Field(..., max_length=255, description="危险类型(如:病毒检测、端口异常、权限泄露等)")
 | ||
|     result: str = Field(..., description="危险检测结果/处理结果(如:检测到木马病毒、已隔离;端口22异常开放、已关闭)")
 | ||
| 
 | ||
| 
 | ||
| # ------------------------------
 | ||
| # 响应模型
 | ||
| # ------------------------------
 | ||
| class DeviceDangerResponse(BaseModel):
 | ||
|     """单条设备危险记录响应模型(与device_danger表字段对齐、updated_at允许为null)"""
 | ||
|     id: int = Field(..., description="危险记录主键ID")
 | ||
|     client_ip: str = Field(..., max_length=100, description="设备IP地址")
 | ||
|     type: str = Field(..., max_length=255, description="危险类型")
 | ||
|     result: str = Field(..., description="危险检测结果/处理结果")
 | ||
|     created_at: datetime = Field(..., description="记录创建时间(危险发生/检测时间)")
 | ||
|     updated_at: Optional[datetime] = Field(None, description="记录更新时间(数据库中该字段当前为null)")
 | ||
|     model_config = {"from_attributes": True}
 | ||
| 
 | ||
| 
 | ||
| class DeviceDangerListResponse(BaseModel):
 | ||
|     """设备危险记录列表响应模型(带分页)"""
 | ||
|     total: int = Field(..., description="危险记录总数")
 | ||
|     dangers: List[DeviceDangerResponse] = Field(..., description="设备危险记录列表") |