撤回转交: recall接口删除子任务恢复父WIP + 前端canRecall判断 + 红色撤回按钮

This commit is contained in:
2026-08-06 11:39:22 +08:00
parent 8be06bcd43
commit 57884d7baa
4 changed files with 68 additions and 0 deletions

View File

@ -306,6 +306,48 @@ async def end_task(
return _to_response(task)
# ============================================================
# 核心业务 0.3:撤回转交
# ============================================================
async def recall_task(
db: AsyncSession, task_id: uuid.UUID, operator_id: str | None = None
) -> TaskResponse:
"""撤回 PENDING 转交任务,恢复父任务为 WIP。"""
task = await _get_task_or_404(db, task_id)
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="顶层任务无法撤回")
parent = await _get_task_or_404(db, task.parent_task_id)
if parent.status != TASK_STATUS_COMPLETED:
raise HTTPException(status_code=409, detail="父任务状态异常,无法撤回")
# 恢复父任务
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
# 删除 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)
# ============================================================
# 核心业务 0.5:派发协助分支(不改变父任务状态)
# ============================================================