From 7f5bedf87c0b06bfcde87577040ce4b17cbd76e3 Mon Sep 17 00:00:00 2001 From: duxingchen Date: Mon, 31 Aug 2026 17:38:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=81=E8=BD=AC=E6=A0=91):=20=E5=9C=A8?= =?UTF-8?q?=E5=BA=93=E8=AE=BE=E5=A4=87=E6=97=A0=E5=9C=A8=E5=BA=93=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=B6=E8=BF=BD=E5=8A=A0=E8=99=9A=E6=8B=9F=E5=9C=A8?= =?UTF-8?q?=E5=BA=93=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 设备在库(virtual_warehouse)但无在库任务时,流转树追加虚拟「在库」节点 - 转入人用最后一道主工序负责人兜底(近似),显示在库归属 - 递归检查任务树避免重复追加(在库任务可能是子任务) --- backend/app/services/product_service.py | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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))