From 39019f43125e86624f91b17d60ac4d0abb4a155c Mon Sep 17 00:00:00 2001 From: duxingchen Date: Mon, 31 Aug 2026 17:26:57 +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=E4=BB=BB=E5=8A=A1=E6=97=A0=E5=88=9B=E5=BB=BA=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=97=B6=E5=85=9C=E5=BA=95=E6=98=BE=E7=A4=BA=E8=BD=AC?= =?UTF-8?q?=E5=85=A5=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 有 create 日志的在库任务用真实转入人(张欣欣/孔贺等) - 无日志的历史在库任务,用该产品在库前最近一道主工序的负责人兜底 - 解决『流转树到负责人就结束、不显示谁入库』的问题 --- backend/app/services/product_service.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/app/services/product_service.py b/backend/app/services/product_service.py index f661562..a304140 100644 --- a/backend/app/services/product_service.py +++ b/backend/app/services/product_service.py @@ -136,6 +136,24 @@ async def get_product_by_serial(db: AsyncSession, serial_number: str) -> Product t.created_by = creator_map.get(t.id) if t.created_by: assignee_ids.add(t.created_by) + # 🔧 兜底:在库/入库任务无创建日志时,用该产品在库前最近一道主工序的负责人作为「转入人」 + all_mains: list = [] + def _collect_main(tasks): + for t in tasks: + if not t.parent_task_id or t.task_type in ("TRANSFER", "RECOVERY"): + all_mains.append(t) + if t.child_tasks: + _collect_main(t.child_tasks) + _collect_main(task_tree) + all_mains.sort(key=lambda t: t.created_at) + for t in all_mains: + is_w = t.task_name and ("在库" in t.task_name or "入库" in t.task_name) + if is_w and not t.created_by: + prev = [m for m in all_mains if m.created_at < t.created_at and m.assignee_id] + if prev: + t.created_by = prev[-1].assignee_id + assignee_ids.add(t.created_by) + # 🔧 中文名映射(负责人 + 创建人,供前端显示"谁转入在库"等) assignee_names = _lookup_display_names(list(assignee_ids))