|
|
@@ -0,0 +1,222 @@
|
|
|
+-- ============================================================================
|
|
|
+-- AI 清洗链路(module/aiclean)元数据表 —— SQLite 方言
|
|
|
+--
|
|
|
+-- 落在 master:加密 SQLite 平台库 qingjian/system/db/plat
|
|
|
+-- (cipher=aes256cbc,驱动 io.github.willena:sqlite-jdbc / org.sqlite.JDBC)。
|
|
|
+-- 与 table_info / table_field 同库,但一张都不碰模板库:AI 生成的模板、字段、
|
|
|
+-- 清洗函数链、任务轨迹全部存这六张表。之所以不写 table_info:一旦写行并打开
|
|
|
+-- table_field.matched,既有匹配器就会命中该模板,进而走到
|
|
|
+-- StrategyType.fromCode(main_id) 抛异常(StrategyType.java:82)。
|
|
|
+--
|
|
|
+-- 列集合与 sql/ai_clean.sql(PG 时代参考)完全一致,仅改写方言:
|
|
|
+-- bigint / integer / smallint -> INTEGER
|
|
|
+-- varchar(n) / text -> TEXT
|
|
|
+-- numeric(6,4) -> REAL
|
|
|
+-- timestamp default current_timestamp -> TEXT default (strftime(...localtime))
|
|
|
+-- 主键一律 INTEGER not null primary key(rowid 别名):id 由应用侧雪花算法供给,
|
|
|
+-- 不需要 AUTOINCREMENT。不含 case_id_src —— 那是 PG 侧未执行补丁
|
|
|
+-- ai_clean_template_drop_case_src.sql 的残留,实体无此字段,模板跨案件共享。
|
|
|
+--
|
|
|
+-- 全部语句幂等(if not exists / on conflict do nothing),可重复执行。
|
|
|
+-- plat 中已存在的表一律不动,本脚本只补建缺失的六张表。
|
|
|
+--
|
|
|
+-- 执行方式(本机无 sqlite3 CLI,Python 打不开加密库,用驱动 jar + jshell):
|
|
|
+-- 见 QUICK_START「平台库初始化」。执行前先停服务并备份 plat 文件。
|
|
|
+--
|
|
|
+-- 设计文档:docs/design/ai-clean-parallel.md
|
|
|
+-- ============================================================================
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 1. AI 模板(等价于 table_info 的角色,但完全独立)
|
|
|
+-- header_md5 唯一键是「零模型重放」的收口:同一张表头签名第二次上传直接命中,
|
|
|
+-- 不再调用大模型。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+create table if not exists ai_clean_template
|
|
|
+(
|
|
|
+ id INTEGER not null primary key,
|
|
|
+ table_name_cn TEXT not null,
|
|
|
+ table_name_en TEXT not null,
|
|
|
+ headers TEXT,
|
|
|
+ header_md5 TEXT not null,
|
|
|
+ header_line_no INTEGER,
|
|
|
+ func_regex TEXT,
|
|
|
+ block_no INTEGER,
|
|
|
+ struct_ops TEXT,
|
|
|
+ needs_struct INTEGER default 0,
|
|
|
+ category TEXT,
|
|
|
+ category_l2 TEXT,
|
|
|
+ main_ref_template_id INTEGER,
|
|
|
+ match_tier TEXT,
|
|
|
+ status TEXT default 'DRAFT',
|
|
|
+ ver INTEGER default 1,
|
|
|
+ confidence REAL,
|
|
|
+ create_by INTEGER,
|
|
|
+ create_time TEXT default (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')),
|
|
|
+ update_time TEXT
|
|
|
+);
|
|
|
+create unique index if not exists uk_ai_clean_tpl_md5 on ai_clean_template (header_md5);
|
|
|
+create index if not exists idx_ai_clean_tpl_status on ai_clean_template (status);
|
|
|
+create index if not exists idx_ai_clean_tpl_category on ai_clean_template (category);
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 2. AI 模板字段(等价于 table_field 的角色)
|
|
|
+-- 既是动态表 DDL 的真源(field_type/field_len -> DuckDB 类型),
|
|
|
+-- 也是前端列表头的真源(field_name_cn + field_sort)。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+create table if not exists ai_clean_field
|
|
|
+(
|
|
|
+ id INTEGER not null primary key,
|
|
|
+ ai_template_id INTEGER not null,
|
|
|
+ column_name TEXT not null,
|
|
|
+ field_name_cn TEXT,
|
|
|
+ field_name_en TEXT,
|
|
|
+ field_type TEXT,
|
|
|
+ required INTEGER default 0,
|
|
|
+ field_len INTEGER default 0,
|
|
|
+ field_sort INTEGER default 0,
|
|
|
+ direction_conf TEXT,
|
|
|
+ col_index INTEGER,
|
|
|
+ matched INTEGER default 1,
|
|
|
+ create_time TEXT default (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime'))
|
|
|
+);
|
|
|
+create index if not exists idx_ai_clean_field_tpl on ai_clean_field (ai_template_id);
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 3. AI 清洗规则(函数链快照)
|
|
|
+-- 只存扁平枚举 hint,绝不存带 @class 的多态 JSON:TableRuleDTO/Fun 用的是
|
|
|
+-- Jackson @JsonTypeInfo(use=CLASS),让模型输出它等于开放任意类名反序列化攻击面。
|
|
|
+-- 加载时由 AiRuleCompiler 在内存里把 hint 还原成 Fun 对象。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+create table if not exists ai_clean_rule
|
|
|
+(
|
|
|
+ id INTEGER not null primary key,
|
|
|
+ ai_template_id INTEGER,
|
|
|
+ col_index INTEGER not null,
|
|
|
+ field_name_en TEXT,
|
|
|
+ field_name_cn TEXT,
|
|
|
+ hints TEXT,
|
|
|
+ ref_template_id INTEGER,
|
|
|
+ ver INTEGER default 1,
|
|
|
+ create_time TEXT default (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime'))
|
|
|
+);
|
|
|
+create index if not exists idx_ai_clean_rule_tpl on ai_clean_rule (ai_template_id);
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 4. AI 清洗任务(幂等游标 + 状态线 + 成本埋点)
|
|
|
+-- 唯一键 (case_id,file_id,sheet_id,block_no,ver) 就是「同一块只被处理一次」的保证。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+create table if not exists ai_clean_job
|
|
|
+(
|
|
|
+ id INTEGER not null primary key,
|
|
|
+ case_id INTEGER not null,
|
|
|
+ file_id INTEGER not null,
|
|
|
+ sheet_id INTEGER not null,
|
|
|
+ block_no INTEGER default 0,
|
|
|
+ ver INTEGER default 1,
|
|
|
+ batch_id INTEGER,
|
|
|
+ file_name TEXT,
|
|
|
+ sheet_name TEXT,
|
|
|
+ status TEXT not null,
|
|
|
+ exit_code TEXT,
|
|
|
+ matched_by TEXT,
|
|
|
+ match_tier TEXT,
|
|
|
+ ref_template_id INTEGER,
|
|
|
+ ai_template_id INTEGER,
|
|
|
+ header_md5 TEXT,
|
|
|
+ header_row INTEGER,
|
|
|
+ confidence REAL,
|
|
|
+ detail TEXT,
|
|
|
+ draft TEXT,
|
|
|
+ model_name TEXT,
|
|
|
+ token_in INTEGER,
|
|
|
+ token_out INTEGER,
|
|
|
+ llm_calls INTEGER default 0,
|
|
|
+ cost_ms INTEGER,
|
|
|
+ row_total INTEGER,
|
|
|
+ row_loaded INTEGER,
|
|
|
+ row_rejected INTEGER,
|
|
|
+ row_warned INTEGER,
|
|
|
+ row_unprocessed INTEGER,
|
|
|
+ fail_reason TEXT,
|
|
|
+ create_time TEXT default (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')),
|
|
|
+ update_time TEXT
|
|
|
+);
|
|
|
+create unique index if not exists uk_ai_clean_job on ai_clean_job (case_id, file_id, sheet_id, block_no, ver);
|
|
|
+create index if not exists idx_ai_clean_job_status on ai_clean_job (status);
|
|
|
+create index if not exists idx_ai_clean_job_file on ai_clean_job (file_id);
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 5. 智能清洗批次(融合入口的状态机与幂等锚点)
|
|
|
+-- 唯一键 (case_id, batch_id) 让重复点按钮返回同一批次而不是重跑一遍。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+create table if not exists ai_clean_batch
|
|
|
+(
|
|
|
+ id INTEGER not null primary key,
|
|
|
+ case_id INTEGER not null,
|
|
|
+ batch_id INTEGER not null,
|
|
|
+ stage TEXT not null,
|
|
|
+ file_count INTEGER default 0,
|
|
|
+ sheet_total INTEGER default 0,
|
|
|
+ matched_count INTEGER default 0,
|
|
|
+ ai_judged_count INTEGER default 0,
|
|
|
+ existing_hit_count INTEGER default 0,
|
|
|
+ ai_load_count INTEGER default 0,
|
|
|
+ loaded_rows INTEGER default 0,
|
|
|
+ rejected_rows INTEGER default 0,
|
|
|
+ unprocessed_rows INTEGER default 0,
|
|
|
+ self_built_count INTEGER default 0,
|
|
|
+ need_review_count INTEGER default 0,
|
|
|
+ failed_count INTEGER default 0,
|
|
|
+ need_review_detail TEXT,
|
|
|
+ last_error TEXT,
|
|
|
+ create_time TEXT default (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')),
|
|
|
+ update_time TEXT
|
|
|
+);
|
|
|
+create unique index if not exists uk_ai_clean_batch on ai_clean_batch (case_id, batch_id);
|
|
|
+create index if not exists idx_ai_clean_batch_stage on ai_clean_batch (stage);
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 6. 表头同义词库(评分归一 + 绑定域)
|
|
|
+-- 星型词组:alias_word -> std_word。只进 HeaderScorer 评分与 filterBinds 绑定域,
|
|
|
+-- 绝不进 HeaderFingerprint 指纹 —— 同义词一旦折叠指纹,存量模板 header_md5
|
|
|
+-- 会随词条配置漂移。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+create table if not exists ai_clean_synonym
|
|
|
+(
|
|
|
+ id INTEGER not null primary key,
|
|
|
+ std_word TEXT not null,
|
|
|
+ alias_word TEXT not null,
|
|
|
+ remark TEXT,
|
|
|
+ status INTEGER default 1,
|
|
|
+ create_by INTEGER,
|
|
|
+ create_time TEXT default (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')),
|
|
|
+ update_time TEXT
|
|
|
+);
|
|
|
+create unique index if not exists uk_ai_clean_synonym on ai_clean_synonym (std_word, alias_word);
|
|
|
+
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+-- 内置词条(建表脚本自带的引导数据,不是从 PG 搬的业务数据)
|
|
|
+--
|
|
|
+-- 必须写入:GlobalCache.synonymMap 初值为空 Map,loadSynonymMap() 遇空表返回 null
|
|
|
+-- 从而保留空快照,且 HeaderScorer 已无硬编码 SYNONYMS 兜底 —— 空表会静默丢失
|
|
|
+-- EXACT 同义词归一(户名↔姓名、交易金额↔发生额、账号↔卡号…),只剩代码内模糊规则。
|
|
|
+-- ----------------------------------------------------------------------------
|
|
|
+insert into ai_clean_synonym (id, std_word, alias_word, remark) values
|
|
|
+ (1, '户名', '账户名称', '内置:户名系'),
|
|
|
+ (2, '户名', '客户名称', '内置:户名系'),
|
|
|
+ (3, '户名', '姓名', '内置:户名系'),
|
|
|
+ (4, '交易金额', '发生额', '内置:金额系'),
|
|
|
+ (5, '交易金额', '交易额', '内置:金额系'),
|
|
|
+ (6, '交易金额', '金额', '内置:金额系'),
|
|
|
+ (7, '日期', '交易日期', '内置:日期系'),
|
|
|
+ (8, '时间', '交易时间', '内置:时间系'),
|
|
|
+ (9, '账号', '卡号', '内置:账号系'),
|
|
|
+ (10, '账号', '银行账号', '内置:账号系'),
|
|
|
+ (11, '账号', '账户', '内置:账号系'),
|
|
|
+ (12, '电话', '手机号', '内置:电话系'),
|
|
|
+ (13, '电话', '手机', '内置:电话系'),
|
|
|
+ (14, '电话', '联系电话', '内置:电话系'),
|
|
|
+ (15, '身份证号', '身份证', '内置:证件系'),
|
|
|
+ (16, '身份证号', '身份证号码', '内置:证件系'),
|
|
|
+ (17, '身份证号', '证件号码', '内置:证件系')
|
|
|
+on conflict (std_word, alias_word) do nothing;
|