From 4f14a40bd9502ed79aff005c2fc4f18db4356a73 Mon Sep 17 00:00:00 2001 From: duxingchen Date: Wed, 5 Aug 2026 16:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E9=A9=B3=E5=9B=9E?= =?UTF-8?q?=E8=BF=94=E5=B7=A5=E4=BB=BB=E5=8A=A1=E8=BF=BD=E6=BA=AF=E4=B8=8A?= =?UTF-8?q?=E4=B8=80=E7=8E=AF=E8=BD=AC=E4=BA=A4=E4=BA=BA=20=E2=80=94=20par?= =?UTF-8?q?ent.assignee=20=E2=86=92=20TaskLog.operator=5Fid=20=E4=B8=89?= =?UTF-8?q?=E5=B1=82=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/task_service.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index e928ab5..6464f1f 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -302,18 +302,31 @@ async def reject_task( remark=f"品质驳回: {request.reason}", ) - # --- 2. 确定返工任务的负责人(上一道工序的负责人) --- + # --- 2. 确定返工任务的负责人(追溯上一道工序的转交人) --- rework_assignee_id: str | None = None if task.parent_task_id: - # 有父任务:查父任务的 assignee + # 有父任务:返工给父任务的负责人(即上一环的转交人 A) parent_result = await db.execute( select(Task).where(Task.id == task.parent_task_id) ) parent_task = parent_result.scalar_one_or_none() if parent_task: rework_assignee_id = parent_task.assignee_id - else: - # 无父任务(顶层):返工给自己 + + if not rework_assignee_id: + # 无父任务(顶层转交):从任务日志追溯创建人(转交发起者 A) + log_result = await db.execute( + select(TaskLog).where( + TaskLog.task_id == task_id, + TaskLog.action_type == "create", + ).order_by(TaskLog.created_at.asc()).limit(1) + ) + create_log = log_result.scalar_one_or_none() + if create_log and create_log.operator_id: + rework_assignee_id = create_log.operator_id + + if not rework_assignee_id: + # 最后兜底:用当前任务的负责人(通常不应该走到这里) rework_assignee_id = task.assignee_id # --- 3. 创建返工任务 ---