From eb52e2fd48e30c972b881bef0f92a26bcd8ecf05 Mon Sep 17 00:00:00 2001 From: duxingchen Date: Thu, 6 Aug 2026 09:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20create=5Ftask=E5=90=8C?= =?UTF-8?q?=E6=AD=A5current=5Flocation=5Fid=E5=88=B0=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E4=BA=BA=20+=20receive=5Ftask=E5=85=9C=E5=BA=95=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BA=A7=E5=93=81=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/task_service.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index 6891320..01284a8 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -184,12 +184,15 @@ async def create_task(db: AsyncSession, data: TaskCreate) -> TaskResponse: task = Task(**data.model_dump()) db.add(task) - # 同步产品宏观状态 - if data.task_name: - product_result = await db.execute(select(Product).where(Product.id == data.product_id)) - product = product_result.scalar_one_or_none() - if product: + # 同步产品宏观状态 + 当前位置 + product_result = await db.execute(select(Product).where(Product.id == data.product_id)) + product = product_result.scalar_one_or_none() + if product: + if data.task_name: product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name + # 派发给人 → 产品离开仓库 + if data.assignee_id and data.assignee_id != VIRTUAL_WAREHOUSE: + product.current_location_id = data.assignee_id await db.commit() await db.refresh(task) @@ -369,6 +372,12 @@ async def receive_task( remark=remark or f"操作员确认接收任务「{task.task_name}」", ) + # 接收时同步产品位置到接收人 + product_result = await db.execute(select(Product).where(Product.id == task.product_id)) + product = product_result.scalar_one_or_none() + if product and task.assignee_id: + product.current_location_id = task.assignee_id + await db.commit() await db.refresh(task)