From f3fb000bda8dca8c5d4dbebb253104bdc2fd0483 Mon Sep 17 00:00:00 2001 From: duxingchen Date: Thu, 6 Aug 2026 09:06:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E5=AE=8F=E8=A7=82=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E8=87=AA=E5=8A=A8=E5=90=8C=E6=AD=A5:=20create=5Ftask/?= =?UTF-8?q?transfer=5Ftask/spawn=5Fsubtask=E5=9D=87=E6=9B=B4=E6=96=B0overa?= =?UTF-8?q?ll=5Fstatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/task_service.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index ccfec42..6891320 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -180,9 +180,17 @@ async def get_top_level_tasks(db: AsyncSession, product_id: uuid.UUID) -> list[T 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.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name + await db.commit() await db.refresh(task) return _to_response(task) @@ -284,6 +292,12 @@ async def spawn_subtask( db.add(child) await db.flush() + # 同步产品宏观状态 + product_result = await db.execute(select(Product).where(Product.id == task.product_id)) + product = product_result.scalar_one_or_none() + if product and data.task_name: + product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name + await _create_task_log(db, child.id, action_type="create", operator_id=operator_id, remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id})") await db.commit() @@ -587,8 +601,10 @@ async def transfer_task( if product: if has_warehouse and not real_branches: product.current_location_id = VIRTUAL_WAREHOUSE + product.overall_status = "在库" elif real_branches: product.current_location_id = real_branches[0][1] + product.overall_status = real_branches[0][0] await db.commit()