From eb97c12bed275e60569e0fc52b4743168f31b4f9 Mon Sep 17 00:00:00 2001 From: duxingchen Date: Thu, 6 Aug 2026 12:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=92=A4=E5=9B=9E:=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4parent=5Ftask=5Fid=E7=A9=BA=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?+=E5=85=BC=E5=AE=B9=E6=97=A0=E7=88=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9C=BA=E6=99=AF(=E4=BB=85=E5=88=A0=E9=99=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/task_service.py | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index feaccf9..3d07c95 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -319,23 +319,21 @@ async def recall_task( if task.status != TASK_STATUS_PENDING: raise HTTPException(status_code=409, detail="只有待接收(PENDING)的任务可以撤回") - if not task.parent_task_id: - raise HTTPException(status_code=400, detail="顶层任务无法撤回") + # 如果有父任务,恢复父任务状态 + if task.parent_task_id: + parent = await _get_task_or_404(db, task.parent_task_id) + if parent.status == TASK_STATUS_COMPLETED: + parent.status = TASK_STATUS_WIP + parent.completed_at = None - parent = await _get_task_or_404(db, task.parent_task_id) - if parent.status != TASK_STATUS_COMPLETED: - raise HTTPException(status_code=409, detail="父任务状态异常,无法撤回") + product_result = await db.execute(select(Product).where(Product.id == parent.product_id)) + product = product_result.scalar_one_or_none() + if product and parent.assignee_id: + product.current_location_id = parent.assignee_id + product.overall_status = parent.task_name - # 恢复父任务 - parent.status = TASK_STATUS_WIP - parent.completed_at = None - - # 更新产品位置到父任务负责人 - product_result = await db.execute(select(Product).where(Product.id == parent.product_id)) - product = product_result.scalar_one_or_none() - if product and parent.assignee_id: - product.current_location_id = parent.assignee_id - product.overall_status = parent.task_name + await _create_task_log(db, parent.id, action_type="recall", operator_id=operator_id, + remark=f"撤回转交「{task.task_name}」→ {task.assignee_id},恢复父任务为 WIP") # 先删除关联的 task_logs 和 task_records await db.execute(delete(TaskLog).where(TaskLog.task_id == task_id)) @@ -345,12 +343,13 @@ async def recall_task( # 删除 PENDING 子任务 await db.delete(task) - await _create_task_log(db, parent.id, action_type="recall", operator_id=operator_id, - remark=f"撤回转交「{task.task_name}」→ {task.assignee_id},恢复父任务为 WIP") - await db.commit() - await db.refresh(parent) - return _to_response(parent) + + if task.parent_task_id: + parent = await _get_task_or_404(db, task.parent_task_id) + return _to_response(parent) + else: + return _to_response(task) # ============================================================