133 lines
3.1 KiB
Python
133 lines
3.1 KiB
Python
|
|
"""ODF 光纤配线单元管理系统 - Pydantic 请求/响应模型定义。
|
|||
|
|
|
|||
|
|
定义了 API 接口使用的数据验证和序列化模型。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from datetime import datetime
|
|||
|
|
from typing import Optional
|
|||
|
|
|
|||
|
|
from pydantic import BaseModel, Field
|
|||
|
|
|
|||
|
|
from app.models import PortType, PortStatus
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ========== 端口相关 ==========
|
|||
|
|
|
|||
|
|
class PortCreate(BaseModel):
|
|||
|
|
"""创建端口请求模型。"""
|
|||
|
|
port_number: int = Field(..., ge=1, description="端口编号")
|
|||
|
|
port_type: PortType = PortType.LC
|
|||
|
|
label: str = ""
|
|||
|
|
|
|||
|
|
|
|||
|
|
class PortResponse(BaseModel):
|
|||
|
|
"""端口响应模型。"""
|
|||
|
|
port_id: str
|
|||
|
|
unit_id: str
|
|||
|
|
port_number: int
|
|||
|
|
port_type: PortType
|
|||
|
|
status: PortStatus
|
|||
|
|
label: str
|
|||
|
|
|
|||
|
|
model_config = {"from_attributes": True}
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ========== 配线单元相关 ==========
|
|||
|
|
|
|||
|
|
class UnitCreate(BaseModel):
|
|||
|
|
"""创建配线单元请求模型。"""
|
|||
|
|
unit_number: int = Field(..., ge=1, description="单元编号")
|
|||
|
|
unit_name: str = ""
|
|||
|
|
position: str = ""
|
|||
|
|
port_count: int = Field(12, ge=1, le=48, description="端口数量")
|
|||
|
|
port_type: PortType = PortType.LC
|
|||
|
|
|
|||
|
|
|
|||
|
|
class UnitResponse(BaseModel):
|
|||
|
|
"""配线单元响应模型。"""
|
|||
|
|
unit_id: str
|
|||
|
|
rack_id: str
|
|||
|
|
unit_number: int
|
|||
|
|
unit_name: str
|
|||
|
|
position: str
|
|||
|
|
ports: list[PortResponse]
|
|||
|
|
|
|||
|
|
model_config = {"from_attributes": True}
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ========== 机架相关 ==========
|
|||
|
|
|
|||
|
|
class RackCreate(BaseModel):
|
|||
|
|
"""创建机架请求模型。"""
|
|||
|
|
rack_name: str = Field(..., min_length=1, max_length=64, description="机架名称/编号")
|
|||
|
|
location: str = ""
|
|||
|
|
|
|||
|
|
|
|||
|
|
class RackResponse(BaseModel):
|
|||
|
|
"""机架响应模型。"""
|
|||
|
|
rack_id: str
|
|||
|
|
rack_name: str
|
|||
|
|
location: str
|
|||
|
|
units: list[UnitResponse]
|
|||
|
|
|
|||
|
|
model_config = {"from_attributes": True}
|
|||
|
|
|
|||
|
|
|
|||
|
|
class RackListResponse(BaseModel):
|
|||
|
|
"""机架列表响应模型(不包含嵌套单元)。"""
|
|||
|
|
rack_id: str
|
|||
|
|
rack_name: str
|
|||
|
|
location: str
|
|||
|
|
unit_count: int = 0
|
|||
|
|
|
|||
|
|
model_config = {"from_attributes": True}
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ========== 连接相关 ==========
|
|||
|
|
|
|||
|
|
class ConnectionCreate(BaseModel):
|
|||
|
|
"""创建跳接连接请求模型。"""
|
|||
|
|
port_a_id: str = Field(..., description="起始端口 ID(A端)")
|
|||
|
|
port_b_id: str = Field(..., description="终止端口 ID(B端)")
|
|||
|
|
fiber_length: float = Field(0.0, ge=0, description="光纤长度(米)")
|
|||
|
|
remark: str = ""
|
|||
|
|
|
|||
|
|
|
|||
|
|
class ConnectionResponse(BaseModel):
|
|||
|
|
"""跳接连接响应模型。"""
|
|||
|
|
connection_id: str
|
|||
|
|
port_a_id: str
|
|||
|
|
port_b_id: str
|
|||
|
|
fiber_length: float
|
|||
|
|
create_time: str
|
|||
|
|
remark: str
|
|||
|
|
|
|||
|
|
model_config = {"from_attributes": True}
|
|||
|
|
|
|||
|
|
|
|||
|
|
class PortDetail(BaseModel):
|
|||
|
|
"""端口详细信息(含所属单元和机架)。"""
|
|||
|
|
port_id: str
|
|||
|
|
port_number: int
|
|||
|
|
port_type: PortType
|
|||
|
|
status: PortStatus
|
|||
|
|
label: str
|
|||
|
|
unit_id: str
|
|||
|
|
unit_number: int
|
|||
|
|
rack_id: str
|
|||
|
|
rack_name: str
|
|||
|
|
|
|||
|
|
|
|||
|
|
class FreePortResponse(BaseModel):
|
|||
|
|
"""空闲端口列表响应元素。"""
|
|||
|
|
port_id: str
|
|||
|
|
port_number: int
|
|||
|
|
port_type: PortType
|
|||
|
|
label: str
|
|||
|
|
unit_id: str
|
|||
|
|
unit_number: int
|
|||
|
|
rack_id: str
|
|||
|
|
rack_name: str
|
|||
|
|
|
|||
|
|
model_config = {"from_attributes": True}
|