diff --git a/backend/app/services/product_service.py b/backend/app/services/product_service.py index a304140..2f3b6a7 100644 --- a/backend/app/services/product_service.py +++ b/backend/app/services/product_service.py @@ -154,6 +154,43 @@ async def get_product_by_serial(db: AsyncSession, serial_number: str) -> Product t.created_by = prev[-1].assignee_id assignee_ids.add(t.created_by) + # 🔧 在库设备若无「在库」任务,追加虚拟「在库」节点(展示谁转入在库) + def _has_warehouse_task(tasks): + for t in tasks: + if t.task_name and ("在库" in t.task_name or "入库" in t.task_name): + return True + if t.child_tasks and _has_warehouse_task(t.child_tasks): + return True + return False + has_warehouse_task = _has_warehouse_task(task_tree) + if product.current_location_id == "virtual_warehouse" and not has_warehouse_task and all_mains: + from app.schemas.task import TaskResponse + last_main = all_mains[-1] + virtual = TaskResponse( + id=uuid.uuid4(), + product_id=product.id, + product_sn=product.serial_number, + product_material=product.material_name or product.material_id or "", + parent_task_id=None, + task_name="在库", + assignee_id="virtual_warehouse", + status="COMPLETED", + notify_parent_on_complete=False, + is_rework=False, + task_type=None, + remark=None, + reject_reason=None, + received_at=last_main.received_at or last_main.created_at, + completed_at=last_main.completed_at, + created_at=last_main.created_at, + child_tasks=[], + records=[], + created_by=last_main.assignee_id, # 最后一道主工序负责人(近似转入人) + ) + task_tree.append(virtual) + if virtual.created_by: + assignee_ids.add(virtual.created_by) + # 🔧 中文名映射(负责人 + 创建人,供前端显示"谁转入在库"等) assignee_names = _lookup_display_names(list(assignee_ids))