Task Schema 更新: - TaskResponse/TaskSummaryResponse 新增 is_rework, reject_reason, received_at, completed_at 字段 - 新增 TaskRejectRequest (品质驳回请求, reason 必填) - 新增 TaskTransferRequest (裂变转交请求, next_assignees + next_task_name 必填) - 新增 TaskTransferResponse (裂变转交响应) - TaskCreate 新增 is_rework 字段 Product Schema 更新: - ProductResponse/ProductScanResponse 新增 current_location_id 字段 - ProductScanResponse 新增 task_tree 字段 (递归任务树,供十字矩阵树状图)
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""产品 Pydantic Schemas"""
|
|
from __future__ import annotations
|
|
import uuid
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ProductCreate(BaseModel):
|
|
"""创建产品"""
|
|
serial_number: str = Field(..., min_length=16, max_length=16, description="产品序列号(16位)")
|
|
order_id: uuid.UUID = Field(..., description="所属订单ID")
|
|
material_id: str | None = Field(None, max_length=64, description="物料ID(逻辑外键→老系统)")
|
|
parent_product_id: uuid.UUID | None = Field(None, description="父产品ID")
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class ProductUpdate(BaseModel):
|
|
"""更新产品"""
|
|
serial_number: str | None = Field(None, min_length=16, max_length=16)
|
|
material_id: str | None = Field(None, max_length=64)
|
|
status: str | None = Field(None, max_length=50, description="产品状态")
|
|
parent_product_id: uuid.UUID | None = Field(None)
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class ProductResponse(BaseModel):
|
|
"""产品响应"""
|
|
id: uuid.UUID
|
|
serial_number: str
|
|
order_id: uuid.UUID
|
|
material_id: str | None
|
|
parent_product_id: uuid.UUID | None
|
|
current_location_id: str | None = None
|
|
status: str
|
|
created_at: datetime
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class ProductScanResponse(BaseModel):
|
|
"""扫码查询响应 — 产品信息 + 完整任务树(递归嵌套)"""
|
|
id: uuid.UUID
|
|
serial_number: str
|
|
order_id: uuid.UUID
|
|
order_no: str = ""
|
|
material_id: str | None
|
|
parent_product_id: uuid.UUID | None
|
|
current_location_id: str | None = None
|
|
status: str
|
|
created_at: datetime
|
|
top_level_tasks: list[TaskSummaryResponse] = []
|
|
task_tree: list[TaskResponse] = []
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
# 延迟导入,避免循环引用 — TaskSummaryResponse 在 tasks.py 中定义
|
|
from app.schemas.task import TaskSummaryResponse # noqa: E402
|
|
ProductScanResponse.model_rebuild()
|