From 1205d9c7e87ea594f928b3d3141fbb2bcad4be25 Mon Sep 17 00:00:00 2001 From: DXC Date: Wed, 22 Apr 2026 10:44:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(audit):=20=E4=BC=98=E5=8C=96=E5=AE=A1?= =?UTF-8?q?=E8=AE=A1=E6=97=A5=E5=BF=97=E7=9A=84=E4=BA=BA=E6=80=A7=E5=8C=96?= =?UTF-8?q?=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-backend/app/utils/audit_events.py | 23 +++++++- inventory-web/src/views/system/AuditLog.vue | 60 ++++++++++++++++++--- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/inventory-backend/app/utils/audit_events.py b/inventory-backend/app/utils/audit_events.py index 6b033ea..0227587 100644 --- a/inventory-backend/app/utils/audit_events.py +++ b/inventory-backend/app/utils/audit_events.py @@ -118,7 +118,7 @@ def insert_audit_log(connection, action, target, details): target_id = str(target.bom_no) # 获取目标名称(用于展示) - target_name = target_id + target_name = '' for name_field in ['name', 'title', 'material_name', 'product_name', 'display_name', 'username']: if hasattr(target, name_field): val = getattr(target, name_field) @@ -126,6 +126,27 @@ def insert_audit_log(connection, action, target, details): target_name = str(val) break + # 如果当前表没名字,但它有关联的物料对象 (比如 material.name) + if not target_name and hasattr(target, 'material') and target.material: + target_name = getattr(target.material, 'name', '') + + # 如果当前表有 material_id,尝试从关联的 material 表查询名称 + if not target_name and hasattr(target, 'material_id') and target.material_id: + try: + # 使用 connection 查询物料表获取名称 + result = connection.execute( + text("SELECT name FROM material_base WHERE id = :id"), + {'id': target.material_id} + ).fetchone() + if result: + target_name = str(result[0]) + except Exception: + pass + + # 如果实在找不到名字,再用 表名 + ID 兜底 + if not target_name: + target_name = f"{tablename} ID:{target_id}" + user_info = get_current_user_info() # 推断模块名称 diff --git a/inventory-web/src/views/system/AuditLog.vue b/inventory-web/src/views/system/AuditLog.vue index 5a931ce..266c1cf 100644 --- a/inventory-web/src/views/system/AuditLog.vue +++ b/inventory-web/src/views/system/AuditLog.vue @@ -55,12 +55,16 @@ - + + +