feat(backend): 流转树 created_by 加入中文名映射

- get_product_by_serial 把任务创建人(created_by)纳入 assignee_names 中文名映射
- 前端可显示『谁转入在库』等创建人信息
This commit is contained in:
2026-08-31 17:20:41 +08:00
parent c19dbc2e7a
commit 0dea116faa

View File

@ -96,7 +96,6 @@ async def get_product_by_serial(db: AsyncSession, serial_number: str) -> Product
all_task_ids.append(t.id)
if t.assignee_id: assignee_ids.add(t.assignee_id)
_collect_ids(task_tree)
assignee_names = _lookup_display_names(list(assignee_ids))
# 🔧 批量查 task_logs: 谁创建了每个任务
creator_map: dict[uuid.UUID, str] = {}
@ -125,15 +124,20 @@ async def get_product_by_serial(db: AsyncSession, serial_number: str) -> Product
if row[1]:
creator_map[row[0]] = row[1]
# 注入 created_by 到 task_tree 和 top_tasks
# 注入 created_by 到 task_tree 和 top_tasks(并收集 created_by 到中文名映射)
def _inject_creator(tasks):
for t in tasks:
t.created_by = creator_map.get(t.id)
if t.created_by: assignee_ids.add(t.created_by)
if t.child_tasks:
_inject_creator(t.child_tasks)
_inject_creator(task_tree)
for t in top_tasks:
t.created_by = creator_map.get(t.id)
if t.created_by: assignee_ids.add(t.created_by)
# 🔧 中文名映射(负责人 + 创建人,供前端显示"谁转入在库"等)
assignee_names = _lookup_display_names(list(assignee_ids))
return ProductScanResponse(
id=product.id,