From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-biz-common/jnpf-biz-common-audit/src/main/java/jnpf/bizcommon/audit/service/entry/AuditEntryResolver.java | 89 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/jnpf-biz-common/jnpf-biz-common-audit/src/main/java/jnpf/bizcommon/audit/service/entry/AuditEntryResolver.java b/jnpf-biz-common/jnpf-biz-common-audit/src/main/java/jnpf/bizcommon/audit/service/entry/AuditEntryResolver.java
new file mode 100644
index 0000000..0856b9b
--- /dev/null
+++ b/jnpf-biz-common/jnpf-biz-common-audit/src/main/java/jnpf/bizcommon/audit/service/entry/AuditEntryResolver.java
@@ -0,0 +1,89 @@
+package jnpf.bizcommon.audit.service.entry;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * 銆屾搷浣滃叆鍙c�嶈В鏋愶細鐢ㄦ埛鏄粠鍝釜鑿滃崟鐐硅繘鏉ョ殑銆�
+ *
+ * <p><b>涓轰粈涔堜笉鎸� modelId 鍙嶆煡</b>锛氫竴涓〃鍗曟ā鍨嬪彲浠ユ寕澶氫釜鑿滃崟鈥斺�斿疄娴� modelId
+ * {@code 846320770681526725} 瀵瑰簲 4 涓彍鍗曪紙寰呭彇鏍锋矇闄嶈弻/娴父鑿�/鎮诞绮掑瓙/琛ㄩ潰寰敓鐗╂祴璇曪級銆�
+ * 鍙嶆煡鍙兘鍙栧叾涓竴涓紝鍐欒繘瀹¤灏辨槸<b>璁伴敊浜嬪疄</b>銆傛墍浠ュ叆鍙e繀椤荤敱璇锋眰鎼哄甫
+ * 锛堝墠绔叏灞�鎷︽埅鍣ㄦ敞鍏� {@code Jnpf-Menu-Id} 鈫� 骞冲彴 AUDIT-P1 琛ヤ竵濉炶繘 {@code auditCtx.menuId}锛夛紝
+ * 鏈被鍙礋璐f妸 id 缈昏瘧鎴愬綋鏃剁殑鍚嶅瓧銆�
+ *
+ * <p>缂撳瓨鍙e緞涓� {@code AuditFormRegistry} 鍚屾棌锛氬彧缂撳瓨纭畾鎬х粨鏋滐紙绌轰覆 = 纭畾鍦版煡涓嶅埌锛夛紝
+ * 鐬椂鏁呴殰涓嶇紦瀛橈紙L061 鈶狅級鈥斺�斾竴娆¤繛鎺ユ姈鍔ㄨ嫢琚案涔呰礋缂撳瓨锛岃鑿滃崟浠庢鍒伴噸鍚墠閮芥病鏈夊悕瀛椼��
+ *
+ * <p><b>杩斿洖 null 鐨勪笁绉嶆垚鍥犵敱璋冪敤鏂瑰尯鍒�</b>锛歮enuId 涓虹┖锛堣姹傛病甯︼級銆佺‘瀹氬湴鏌ヤ笉鍒般�佺灛鏃舵晠闅溿��
+ * 鏈被鍙繚璇併�屾煡涓嶅埌灏辫繑鍥� null锛岀粷涓嶇紪涓�涓悕瀛椼�嶏紱銆屾病甯︺�嶄笌銆屽甫浜嗕絾鏌ヤ笉鍒般�嶅啓鎴愪袱绉�
+ * {@code entrySource} 鐣欑棔锛屾槸缂栨帓渚э紙Task 6锛夌殑浜嬧�斺�斿叡鐢ㄤ竴涓〃绀哄氨浼氶伄浣忎竴澶勬紡璁般��
+ */
+@Slf4j
+@Component
+public class AuditEntryResolver {
+
+ /** 鍏ュ彛绫诲瀷锛氳彍鍗曘�傞鐣� FORM / FLOW 绛夛紝鐢ㄤ簬瑙i噴 entry_id 鎸囧悜鍝紶琛ㄣ�� */
+ public static final String TYPE_MENU = "MENU";
+
+ private final Map<String, CacheValue> cache = new ConcurrentHashMap<String, CacheValue>();
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ @Value("${audit.layer0.metadata-cache-ttl-ms:300000}")
+ private long ttlMs = 300_000L;
+
+ /** 鑿滃崟鍚嶏紱menuId 涓虹┖銆佹煡涓嶅埌銆佹垨鐬椂鏁呴殰鏃惰繑鍥� null锛堣皟鐢ㄦ柟鎹鍐� entrySource锛夈�� */
+ public String resolveMenuName(String menuId) {
+ if (menuId == null || menuId.trim().isEmpty()) {
+ return null;
+ }
+ String key = menuId.trim();
+ CacheValue cached = cache.get(key);
+ if (cached != null && ttlMs > 0L
+ && System.currentTimeMillis() - cached.createdAt < ttlMs) {
+ return cached.value.isEmpty() ? null : cached.value;
+ }
+ String name;
+ try {
+ // 鎺掗櫎宸插垹鑿滃崟锛氳彍鍗曡鍒犲悗 f_id 浠嶆槸鍙拷婧殑浜嬪疄锛屼絾瀹冪殑鍚嶅瓧涓嶈鍐嶈褰撴垚"褰撴椂鐨勫叆鍙e悕"
+ // 鍐欒繘鏂拌褰曘�俧_delete_mark 鍦� PG 閲屾槸 integer锛屾湭鍒犻櫎鏃朵负 NULL 鎴� 0銆�
+ name = jdbcTemplate.queryForObject(
+ "SELECT f_full_name FROM base_module WHERE f_id = ? "
+ + "AND (f_delete_mark IS NULL OR f_delete_mark <> 1) LIMIT 1",
+ String.class, key);
+ } catch (org.springframework.dao.EmptyResultDataAccessException e) {
+ // 纭畾鎬э細杩欎釜 menuId 娌℃湁鑿滃崟琛岋紝鍐嶆煡涓�涓囨涔熶竴鏍�
+ put(key, "");
+ return null;
+ } catch (Throwable t) {
+ log.warn("[AUDIT-L0] 鍙嶆煡鑿滃崟鍚嶅け璐ワ紙鐬椂锛屼笉缂撳瓨锛塵enuId={} err={}", key, t.toString());
+ return null;
+ }
+ String normalized = name == null ? "" : name.trim();
+ put(key, normalized);
+ return normalized.isEmpty() ? null : normalized;
+ }
+
+ private void put(String key, String value) {
+ if (ttlMs > 0L) {
+ cache.put(key, new CacheValue(value));
+ }
+ }
+
+ private static final class CacheValue {
+ private final String value;
+ private final long createdAt = System.currentTimeMillis();
+
+ private CacheValue(String value) {
+ this.value = value;
+ }
+ }
+}
--
Gitblit v1.8.0