全栈修复: remark字段全链路打通 — TaskCreate+TransferRequest+transfer_task+前端Payload

This commit is contained in:
2026-08-05 15:59:20 +08:00
parent 30d35d7fa2
commit 7810097b39
4 changed files with 36 additions and 19 deletions

View File

@ -397,35 +397,44 @@ async def transfer_task(
)
# --- 动作 2解析下家 & 裂变 ---
has_warehouse = VIRTUAL_WAREHOUSE in request.next_assignees
real_assignees = [a for a in request.next_assignees if a != VIRTUAL_WAREHOUSE]
# 兼容新旧格式
if request.next_tasks:
branches = [
(b.task_name, a)
for b in request.next_tasks
for a in (b.assignees or [])
]
else:
branches = [
(request.next_task_name, a)
for a in (request.next_assignees or [])
]
# 判断是否需要裂变(树状结构)
is_fission = len(real_assignees) > 1
has_warehouse = any(a == VIRTUAL_WAREHOUSE for _, a in branches)
real_branches = [(tn, a) for tn, a in branches if a != VIRTUAL_WAREHOUSE]
is_fission = len(real_branches) > 1 or (request.next_tasks and len(request.next_tasks) > 1)
is_child_task = task.parent_task_id is not None
created_tasks: list[Task] = []
for assignee_id in real_assignees:
# 确定新任务的 parent_task_id裂变逻辑
for task_name, assignee_id in real_branches:
if is_fission:
# 多路裂变:所有新任务挂在当前任务下,形成树状分支
new_parent_task_id = task.id
elif is_child_task:
# 当前任务是子任务,单路转交也保持在同一父任务下
new_parent_task_id = task.parent_task_id
else:
# 顶层单路转交:同级
new_parent_task_id = None
new_task = Task(
product_id=task.product_id,
parent_task_id=new_parent_task_id,
task_name=request.next_task_name,
task_name=task_name,
assignee_id=assignee_id,
status=TASK_STATUS_PENDING,
notify_parent_on_complete=False,
is_rework=False,
remark=request.note or None,
)
db.add(new_task)
created_tasks.append(new_task)
@ -438,7 +447,7 @@ async def transfer_task(
db, nt.id,
action_type="create",
operator_id=operator_id,
remark=f"由任务「{task.task_name}」裂变转交创建,分配给 {nt.assignee_id}",
remark=request.note or f"由任务「{task.task_name}」裂变转交创建,分配给 {nt.assignee_id}",
)
# --- 更新 Product 的 current_location_id ---
@ -447,12 +456,10 @@ async def transfer_task(
)
product = product_result.scalar_one_or_none()
if product:
if has_warehouse and not real_assignees:
# 只有仓库,没有实际人员 → 入库
if has_warehouse and not real_branches:
product.current_location_id = VIRTUAL_WAREHOUSE
elif real_assignees:
# 有实际人员 → 指向第一个人员(或可考虑指向多人中的主负责人)
product.current_location_id = real_assignees[0]
elif real_branches:
product.current_location_id = real_branches[0][1]
await db.commit()