|
@@ -21,14 +21,16 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 可查表目录:<b>只来自模板库元数据</b>,不扫描案件 DuckDB。
|
|
|
|
|
|
|
+ * 可查表目录:<b>只来自已登记的元数据 / 结构文件</b>,不扫描案件 DuckDB。
|
|
|
*
|
|
*
|
|
|
- * <h3>事实来源(且仅此两个)</h3>
|
|
|
|
|
|
|
+ * <h3>事实来源(且仅此三个)</h3>
|
|
|
* <ul>
|
|
* <ul>
|
|
|
* <li>既有模板库:{@code table_info} + {@code table_field};</li>
|
|
* <li>既有模板库:{@code table_info} + {@code table_field};</li>
|
|
|
- * <li>AI 模板库:{@code ai_clean_template} + {@code ai_clean_field}(AI 智能清洗出口 B 新建的动态表)。</li>
|
|
|
|
|
|
|
+ * <li>AI 模板库:{@code ai_clean_template} + {@code ai_clean_field}(AI 智能清洗出口 B 新建的动态表);</li>
|
|
|
|
|
+ * <li>电子数据取证表:{@link WaForensicsSchemaCatalog} 读取的 {@code schema/wa_mforensics_duckdb.json}
|
|
|
|
|
+ * ({@code wa_mforensics_*} 有 100+ 张、不落模板库,理由见该类说明)。</li>
|
|
|
* </ul>
|
|
* </ul>
|
|
|
- * 业务约定:<b>不读取 DuckDB 系统表 / 不做任何表扫描</b>。DuckDB 里的表必须先在两套元数据里登记,
|
|
|
|
|
|
|
+ * 业务约定:<b>不读取 DuckDB 系统表 / 不做任何表扫描</b>。DuckDB 里的表必须先在这三套元数据里登记,
|
|
|
* 才算「可被 Agent 使用的表」——这样表清单与模板库、治理树、AI 模板匹配保持同一口径,
|
|
* 才算「可被 Agent 使用的表」——这样表清单与模板库、治理树、AI 模板匹配保持同一口径,
|
|
|
* 也不会把 {@code govern_tree}/{@code raw_*} 之类的内部表暴露给模型。
|
|
* 也不会把 {@code govern_tree}/{@code raw_*} 之类的内部表暴露给模型。
|
|
|
*
|
|
*
|
|
@@ -40,6 +42,7 @@ import java.util.Map;
|
|
|
* AI 模板取 {@code ai_clean_field.column_name}(AI 动态表的物理列是 c0..cN,
|
|
* AI 模板取 {@code ai_clean_field.column_name}(AI 动态表的物理列是 c0..cN,
|
|
|
* 语义英文名只在模板匹配/展示里用);</li>
|
|
* 语义英文名只在模板匹配/展示里用);</li>
|
|
|
* <li>{@code type} 取元数据 {@code field_type}(如 MONEY/DATE_TIME,缺省 TEXT);
|
|
* <li>{@code type} 取元数据 {@code field_type}(如 MONEY/DATE_TIME,缺省 TEXT);
|
|
|
|
|
+ * 取证表取<b>原始 SQL 类型</b>(VARCHAR/BIGINT/DECIMAL(18,2)),与语义检索的 DDL 文档同口径;
|
|
|
* {@code comment} 取 {@code field_name_cn};{@code required} 取 {@code required==1}。</li>
|
|
* {@code comment} 取 {@code field_name_cn};{@code required} 取 {@code required==1}。</li>
|
|
|
* </ul>
|
|
* </ul>
|
|
|
*
|
|
*
|
|
@@ -47,8 +50,11 @@ import java.util.Map;
|
|
|
* <ul>
|
|
* <ul>
|
|
|
* <li>没有字段的表跳过:无字段既不能打分也不能清洗,列进目录只会让模型去查一张空表;</li>
|
|
* <li>没有字段的表跳过:无字段既不能打分也不能清洗,列进目录只会让模型去查一张空表;</li>
|
|
|
* <li>物理列名为空的字段跳过(历史脏数据):它无法出现在 SQL 里,输出只会误导模型;</li>
|
|
* <li>物理列名为空的字段跳过(历史脏数据):它无法出现在 SQL 里,输出只会误导模型;</li>
|
|
|
- * <li>输出按物理表名排序,列严格按元数据顺序({@code field_sort} → {@code id});</li>
|
|
|
|
|
- * <li>两套元数据理论上不会重名;真出现同名时以 {@code table_info} 为准(先把既有模板写进结果)。</li>
|
|
|
|
|
|
|
+ * <li>取证表只取 {@code vectorize=true} 的({@code wa_mforensics_ext_*} 是「展示未使用」的扩展表,
|
|
|
|
|
+ * 与向量索引同一口径,不进 Agent 选表);</li>
|
|
|
|
|
+ * <li>输出按物理表名排序,列严格按元数据顺序({@code field_sort} → {@code id};取证表按 DDL 顺序);</li>
|
|
|
|
|
+ * <li>三套元数据理论上不会重名;真出现同名时按 {@code table_info} → {@code ai_clean_template}
|
|
|
|
|
+ * → 取证表 的顺序先到先得(模板库口径优先)。</li>
|
|
|
* </ul>
|
|
* </ul>
|
|
|
*
|
|
*
|
|
|
* <h3>失败语义</h3>
|
|
* <h3>失败语义</h3>
|
|
@@ -83,15 +89,19 @@ public class WorkspaceSchemaCatalog {
|
|
|
private final TableFieldMapper tableFieldMapper;
|
|
private final TableFieldMapper tableFieldMapper;
|
|
|
private final AiCleanTemplateMapper aiCleanTemplateMapper;
|
|
private final AiCleanTemplateMapper aiCleanTemplateMapper;
|
|
|
private final AiCleanFieldMapper aiCleanFieldMapper;
|
|
private final AiCleanFieldMapper aiCleanFieldMapper;
|
|
|
|
|
+ /** 取证数据表结构(文件驱动):{@code wa_mforensics_*} 的唯一事实来源 */
|
|
|
|
|
+ private final WaForensicsSchemaCatalog waForensicsSchemaCatalog;
|
|
|
|
|
|
|
|
public WorkspaceSchemaCatalog(TableInfoMapper tableInfoMapper,
|
|
public WorkspaceSchemaCatalog(TableInfoMapper tableInfoMapper,
|
|
|
TableFieldMapper tableFieldMapper,
|
|
TableFieldMapper tableFieldMapper,
|
|
|
AiCleanTemplateMapper aiCleanTemplateMapper,
|
|
AiCleanTemplateMapper aiCleanTemplateMapper,
|
|
|
- AiCleanFieldMapper aiCleanFieldMapper) {
|
|
|
|
|
|
|
+ AiCleanFieldMapper aiCleanFieldMapper,
|
|
|
|
|
+ WaForensicsSchemaCatalog waForensicsSchemaCatalog) {
|
|
|
this.tableInfoMapper = tableInfoMapper;
|
|
this.tableInfoMapper = tableInfoMapper;
|
|
|
this.tableFieldMapper = tableFieldMapper;
|
|
this.tableFieldMapper = tableFieldMapper;
|
|
|
this.aiCleanTemplateMapper = aiCleanTemplateMapper;
|
|
this.aiCleanTemplateMapper = aiCleanTemplateMapper;
|
|
|
this.aiCleanFieldMapper = aiCleanFieldMapper;
|
|
this.aiCleanFieldMapper = aiCleanFieldMapper;
|
|
|
|
|
+ this.waForensicsSchemaCatalog = waForensicsSchemaCatalog;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -107,7 +117,7 @@ public class WorkspaceSchemaCatalog {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 全部可查表(既有模板库 + AI 模板库),按物理表名排序、列按字段顺序排列。
|
|
|
|
|
|
|
+ * 全部可查表(既有模板库 + AI 模板库 + 电子数据取证表),按物理表名排序、列按字段顺序排列。
|
|
|
*
|
|
*
|
|
|
* @throws org.springframework.dao.DataAccessException 元数据查询失败时直接上抛,不降级为空列表
|
|
* @throws org.springframework.dao.DataAccessException 元数据查询失败时直接上抛,不降级为空列表
|
|
|
*/
|
|
*/
|
|
@@ -119,10 +129,11 @@ public class WorkspaceSchemaCatalog {
|
|
|
List<AiCleanTemplate> aiTemplates = nullSafe(aiCleanTemplateMapper.selectList(Wrappers.emptyWrapper()));
|
|
List<AiCleanTemplate> aiTemplates = nullSafe(aiCleanTemplateMapper.selectList(Wrappers.emptyWrapper()));
|
|
|
List<AiCleanField> aiFields = nullSafe(aiCleanFieldMapper.selectList(Wrappers.emptyWrapper()));
|
|
List<AiCleanField> aiFields = nullSafe(aiCleanFieldMapper.selectList(Wrappers.emptyWrapper()));
|
|
|
|
|
|
|
|
- // LinkedHashMap 用于「先到先得」:既有模板先写入,AI 模板 putIfAbsent,天然实现同名以 table_info 优先
|
|
|
|
|
|
|
+ // LinkedHashMap 用于「先到先得」:模板库先写入,后面的 putIfAbsent 不覆盖,天然实现同名优先模板库口径
|
|
|
Map<String, TableSchema> byTableName = new LinkedHashMap<>();
|
|
Map<String, TableSchema> byTableName = new LinkedHashMap<>();
|
|
|
appendTemplateTables(byTableName, tables, tableFields);
|
|
appendTemplateTables(byTableName, tables, tableFields);
|
|
|
appendAiTemplateTables(byTableName, aiTemplates, aiFields);
|
|
appendAiTemplateTables(byTableName, aiTemplates, aiFields);
|
|
|
|
|
+ appendForensicsTables(byTableName);
|
|
|
|
|
|
|
|
List<TableSchema> result = new ArrayList<>(byTableName.values());
|
|
List<TableSchema> result = new ArrayList<>(byTableName.values());
|
|
|
result.sort(Comparator.comparing(TableSchema::tableName,
|
|
result.sort(Comparator.comparing(TableSchema::tableName,
|
|
@@ -226,6 +237,56 @@ public class WorkspaceSchemaCatalog {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // ==================== 电子数据取证表:wa_mforensics_*(文件驱动) ====================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 装配电子数据取证表({@code wa_mforensics_*})。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>这些表<b>不在</b> {@code table_info}/{@code table_field} 里:100+ 张 DDL 表落模板库会稀释
|
|
|
|
|
+ * 模板匹配候选池、污染模板库页面,所以由 {@link WaForensicsSchemaCatalog} 直接读
|
|
|
|
|
+ * {@code schema/wa_mforensics_duckdb.json}(与语义检索索引同一份事实来源)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p><b>只取 {@link WaForensicsSchemaCatalog#usable()}</b>:{@code wa_mforensics_ext_*} 在文件里标了
|
|
|
|
|
+ * {@code vectorize=false}(展示未使用),与向量索引保持同一口径,不进 Agent 选表。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>类型用<b>原始 SQL 类型</b>而不是平台枚举:取证表由模型直接查 DuckDB,
|
|
|
|
|
+ * {@code DECIMAL(18,2)} / {@code BIGINT} 比 NUMBER 更能防止把数值列当字符串处理
|
|
|
|
|
+ * (与 {@code AiCleanTemplateVectorIndex#buildDdlDoc} 的 DDL 文档同口径)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>文件缺失 / 解析失败时 {@code usable()} 返回空列表(catalog 内部 fail-open),
|
|
|
|
|
+ * 不影响模板表清单。
|
|
|
|
|
+ */
|
|
|
|
|
+ private void appendForensicsTables(Map<String, TableSchema> target) {
|
|
|
|
|
+ for (WaForensicsSchemaCatalog.TableSchema table : waForensicsSchemaCatalog.usable()) {
|
|
|
|
|
+ if (table == null || !StringUtils.hasText(table.tableNameEn())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<WaForensicsSchemaCatalog.ColumnSchema> forensicsColumns =
|
|
|
|
|
+ table.columns() == null ? List.of() : table.columns();
|
|
|
|
|
+ List<ColumnSchema> columns = forensicsColumns.stream()
|
|
|
|
|
+ .filter(column -> column != null && StringUtils.hasText(column.name()))
|
|
|
|
|
+ .map(column -> new ColumnSchema(
|
|
|
|
|
+ column.name(),
|
|
|
|
|
+ forensicsType(column),
|
|
|
|
|
+ column.comment(),
|
|
|
|
|
+ column.required()))
|
|
|
|
|
+ .toList();
|
|
|
|
|
+ if (columns.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ target.putIfAbsent(table.tableNameEn(),
|
|
|
|
|
+ new TableSchema(table.tableNameEn(), table.tableNameCn(), columns));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 取证列类型:优先原始 SQL 类型,缺失时退回平台元数据类型,再缺省 TEXT。 */
|
|
|
|
|
+ private static String forensicsType(WaForensicsSchemaCatalog.ColumnSchema column) {
|
|
|
|
|
+ if (StringUtils.hasText(column.sqlType())) {
|
|
|
|
|
+ return column.sqlType();
|
|
|
|
|
+ }
|
|
|
|
|
+ return StringUtils.hasText(column.fieldType()) ? column.fieldType() : DEFAULT_TYPE;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== 测试辅助 ====================
|
|
// ==================== 测试辅助 ====================
|
|
|
|
|
|
|
|
private static <T> List<T> nullSafe(List<T> list) {
|
|
private static <T> List<T> nullSafe(List<T> list) {
|