feat(schemas): 扩充 Task/Product Pydantic Schema
Task Schema: - TaskResponse 新增 is_rework, reject_reason, received_at, completed_at, records, product_sn - 新增 TaskRejectRequest, TaskTransferRequest, TaskRecordCreate, TaskRecordResponse - TaskRecordResponse 含 json.loads 反序列化 images Product Schema: - ProductResponse/ProductScanResponse 新增 external_serial, current_location_id, overall_status - ProductScanResponse 新增 task_tree (递归任务树) - ProductCreate 改为 material_id/material_name/spec_model + external_serial + order_no 自由文本 - ProductUpdate 新增 order_no
This commit is contained in:
@ -59,6 +59,35 @@ class TaskTransferRequest(BaseModel):
|
||||
note: str | None = Field(None, description="交接备注")
|
||||
|
||||
|
||||
class TaskRecordCreate(BaseModel):
|
||||
"""任务进度记录 — 备注 + 图片"""
|
||||
remark: str = Field("", max_length=2000, description="备注文本")
|
||||
images: list[str] = Field(default_factory=list, description="图片 URL 列表")
|
||||
|
||||
|
||||
class TaskRecordResponse(BaseModel):
|
||||
id: int
|
||||
task_id: uuid.UUID
|
||||
remark: str | None = None
|
||||
images: list[str] = []
|
||||
created_at: datetime | None = None
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
@classmethod
|
||||
def model_validate(cls, obj, **kwargs):
|
||||
"""处理 DB 中 images 的 JSON 字符串 → list 反序列化"""
|
||||
import json
|
||||
if hasattr(obj, "images") and isinstance(obj.images, str):
|
||||
try:
|
||||
obj.images = json.loads(obj.images)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
obj.images = []
|
||||
elif hasattr(obj, "images") and obj.images is None:
|
||||
obj.images = []
|
||||
return super().model_validate(obj, **kwargs)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 响应模型
|
||||
# ============================================================
|
||||
@ -85,6 +114,8 @@ class TaskResponse(BaseModel):
|
||||
"""任务详情响应 — 递归包含所有子任务"""
|
||||
id: uuid.UUID
|
||||
product_id: uuid.UUID
|
||||
product_sn: str = ""
|
||||
product_material: str = ""
|
||||
parent_task_id: uuid.UUID | None
|
||||
task_name: str
|
||||
assignee_id: str | None
|
||||
@ -96,6 +127,7 @@ class TaskResponse(BaseModel):
|
||||
completed_at: datetime | None = None
|
||||
created_at: datetime
|
||||
child_tasks: list[TaskResponse] = []
|
||||
records: list[TaskRecordResponse] = []
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user