diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/UserColumnResolver.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/UserColumnResolver.java index b3815c2..0c46cd1 100644 --- a/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/UserColumnResolver.java +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/flow/UserColumnResolver.java @@ -166,6 +166,7 @@ public class UserColumnResolver { } private Map queryRefColumns(String upperTable) { + Map map = new LinkedHashMap<>(); try { List> rows = jdbcTemplate.queryForList( "SELECT UPPER(ea.columnname) AS col, UPPER(e2.tablename) AS target " @@ -175,10 +176,6 @@ public class UserColumnResolver { + "JOIN eip3.sys_entity e2 ON UPPER(e2.sys_entity_id) = UPPER(r.entityid) " + "WHERE UPPER(e1.tablename) = ?", upperTable); - if (rows.isEmpty()) { - return Collections.emptyMap(); - } - Map map = new LinkedHashMap<>(); for (Map r : rows) { String col = String.valueOf(r.get("col")); String target = String.valueOf(r.get("target")); @@ -187,12 +184,33 @@ public class UserColumnResolver { map.put(col, t); } } - log.debug("[REF-COL] table={} refColumns={}", upperTable, map.keySet()); - return map; } catch (org.springframework.dao.DataAccessException ex) { - // 元数据查询异常 → 视作无引用列,绝不影响主读路径 + // 元数据查询异常 → 不阻断,继续补众所周知列;绝不影响主读路径 log.warn("[REF-COL] 解析引用列失败 table={}: {}", upperTable, ex.getMessage()); - return Collections.emptyMap(); + } + // 补众所周知的部门/组织引用列:DEPARTID/HISDEPARTID/ORGID 在 OA/HR 实体元数据里被登记为 NVARCHAR + // (字符串类型码、非外键)→ 上面 referenceid 链漏掉,但其值实为 SYS_DEPART/SYS_ORG 主键(全库通用, + // 拟稿人部门/组织)。按列名约定统一解析,使 OA/HR/PM 一致显部门/组织名(dogfooding:OA/HR 列表显裸 id 根因)。 + try { + Set srcPhys = physColsCache.get(upperTable, this::queryPhysicalColumns); + addWellKnownRefCol(map, srcPhys, "DEPARTID", "SYS_DEPART"); + addWellKnownRefCol(map, srcPhys, "HISDEPARTID", "SYS_DEPART"); + addWellKnownRefCol(map, srcPhys, "ORGID", "SYS_ORG"); + } catch (RuntimeException ignore) { + // 补列失败不影响已有解析 + } + log.debug("[REF-COL] table={} refColumns={}", upperTable, map.keySet()); + return map.isEmpty() ? Collections.emptyMap() : map; + } + + /** 按列名补众所周知引用列(源表确有该物理列、且未被 referenceid 解析覆盖 → 不动 PM 等已配真外键的)。 */ + private void addWellKnownRefCol(Map map, Set srcPhys, String col, String targetTable) { + if (map.containsKey(col) || srcPhys == null || !srcPhys.contains(col)) { + return; + } + RefTarget t = targetMetaCache.get(targetTable, this::resolveTargetMeta); + if (t != null) { + map.put(col, t); } }