修复撤回: 移除parent_task_id空校验+兼容无父任务场景(仅删除)

This commit is contained in:
2026-08-06 12:39:47 +08:00
parent 58cb9a23ef
commit eb97c12bed

View File

@ -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)
# ============================================================