docs+deploy: 元数据同步工作流 v2.1(规格缓存/固定清单/force全表)与治理链路文档
This commit is contained in:
1 parent
880fad1f36
commit
9ae77528f5
37 files changed
+135
-34
No files matched your search
@@ -13,6 +13,7 @@ const N = {
|
||||
exec: "9000000000009",
|
||||
saveState: "9000000000010",
|
||||
endSummary: "9000000000011",
|
||||
ifspec: "9000000000012",
|
||||
};
|
||||
|
||||
const CODE_COLLECT = `import requests, json, hashlib, base64
|
||||
@@ -43,9 +44,12 @@ def main(force: str):
|
||||
global_hash = sha256(json.dumps(tables, ensure_ascii=False, sort_keys=True) + "||" + docs)
|
||||
docs_hash = sha256(docs)
|
||||
prev = state.get("table_hashes", {})
|
||||
changed = sorted([t["table_name"] for t in tables if prev.get(t["table_name"]) != table_hashes[t["table_name"]]])
|
||||
force_on = (force or "").strip().lower() == "true"
|
||||
changed = sorted([t["table_name"] for t in tables if prev.get(t["table_name"]) != table_hashes[t["table_name"]]])
|
||||
if force_on:
|
||||
changed = sorted([t["table_name"] for t in tables])
|
||||
skip = (not force_on) and state.get("global_hash") == global_hash
|
||||
spec_needed = force_on or (not state.get("spec_json")) or state.get("docs_hash") != docs_hash
|
||||
return {
|
||||
"skip": skip,
|
||||
"tables_json": json.dumps(tables, ensure_ascii=False),
|
||||
@@ -56,6 +60,8 @@ def main(force: str):
|
||||
"table_hashes_json": json.dumps(table_hashes),
|
||||
"state_sha": state_sha,
|
||||
"prev_state_json": json.dumps(state, ensure_ascii=False),
|
||||
"prev_spec_json": state.get("spec_json", "") if isinstance(state.get("spec_json", ""), str) else json.dumps(state.get("spec_json", {}), ensure_ascii=False),
|
||||
"spec_needed": spec_needed,
|
||||
}`;
|
||||
|
||||
const SYS_PROMPT = `你是数据治理与 DataHub 元数据专家。阅读【ERP库表结构】(information_schema 导出, 含表/字段中文注释)与【治理底稿】(系统介绍+业务说明, 含状态码映射/指标口径/敏感字段规则), 产出 DataHub 治理规格。
|
||||
@@ -66,13 +72,13 @@ const SYS_PROMPT = `你是数据治理与 DataHub 元数据专家。阅读【ERP
|
||||
"terms":[{"key":"erp_xxx","name":"中文术语名","description":"含口径/枚举值"}],
|
||||
"datasets":[{"table":"表名","description":"2-3句业务描述","domain_key":"master","tags":["tag_key"],"term_fields":[{"field":"字段名","term_key":"term_key"}]}]}
|
||||
|
||||
硬性规则:
|
||||
1. domains 固定5个: master(主数据)/purchase(采购)/sales(销售)/inventory(库存)/governance(治理), key 即上述英文。
|
||||
硬性规则(必须逐字遵守 key/name, 不得增删):
|
||||
1. domains 固定5个: master=ERP主数据域, purchase=ERP采购域, sales=ERP销售域, inventory=ERP库存域, governance=ERP治理域。
|
||||
2. datasets 必须覆盖全部10张表, table 用真实表名, 按前缀归域: md_/mdm_→master, po_→purchase, so_→sales, inv_→inventory。
|
||||
3. tags 至少含: erp_master, erp_purchase, erp_sales, erp_inventory, erp_sensitive(敏感字段表), erp_demo。
|
||||
4. terms 从底稿提炼: 至少包含 状态机术语(主数据状态/采购单状态/销售单状态)与指标口径(采购入库金额/销售出库金额)与敏感字段规则(联系电话脱敏), key 用 erp_ 前缀蛇形英文。
|
||||
5. 含 contact_phone 的表(md_supplier/md_customer)必须打 erp_sensitive 标签, 且该字段关联敏感术语。
|
||||
6. 全部中文描述, 术语口径必须与底稿一致, 禁止编造。`;
|
||||
3. tags 固定7个: erp, erp_master, erp_purchase, erp_sales, erp_inventory, erp_sensitive, erp_demo。
|
||||
4. terms 固定10个(key 逐字): erp_status_master_data(主数据状态), erp_status_purchase_order(采购单状态), erp_status_sales_order(销售单状态), erp_metric_purchase_received_amount(采购入库金额), erp_metric_sales_shipped_amount(销售出库金额), erp_metric_order_total_amount(单据总金额), erp_rule_sensitive_phone(联系电话脱敏规则), erp_rule_no_physical_delete(禁止物理删除被引用记录), erp_rule_code_unique(编码唯一规则), erp_concept_alias_mapping(别名映射)。description 必须取自底稿口径。
|
||||
5. 含 contact_phone 的表(md_supplier/md_customer)打 erp_sensitive 标签, 该字段关联 erp_rule_sensitive_phone。
|
||||
6. datasets 的 tags 只能引用规则3的key, term_fields 只能引用规则4的key。中文描述, 禁止编造。`;
|
||||
|
||||
const CODE_ENSURE = `import requests, json, re
|
||||
|
||||
@@ -96,8 +102,22 @@ def exists_aspect(urn, aspect):
|
||||
r = requests.get(DH + "/aspects/" + quote(urn, safe="") + "?aspect=" + aspect + "&version=0", headers=HDRS, timeout=15)
|
||||
return r.status_code == 200
|
||||
|
||||
def main(spec_text: str, docs_hash: str, prev_state_json: str):
|
||||
spec = parse_json(spec_text)
|
||||
def find_term_by_name(name):
|
||||
d = gql('query($s:String!){ search(input:{query:$s, type:GLOSSARY_TERM, count:20}) { searchResults { entity { ... on GlossaryTerm { urn properties { name } } } } } }', {"s": name})
|
||||
for sr in d["search"]["searchResults"]:
|
||||
e = sr.get("entity") or {}
|
||||
p = e.get("properties") or {}
|
||||
if p.get("name") == name:
|
||||
return e["urn"]
|
||||
return None
|
||||
|
||||
def main(spec_text: str, prev_spec_json: str, docs_hash: str, prev_state_json: str):
|
||||
if spec_text and str(spec_text).strip():
|
||||
spec = parse_json(str(spec_text))
|
||||
elif prev_spec_json and str(prev_spec_json).strip():
|
||||
spec = json.loads(str(prev_spec_json))
|
||||
else:
|
||||
raise Exception("无可用治理规格(LLM输出与缓存规格均为空)")
|
||||
prev = json.loads(prev_state_json) if prev_state_json else {}
|
||||
urns = {"domains": {}, "tags": {}, "terms": {}}
|
||||
created = {"domains": 0, "tags": 0, "terms": 0}
|
||||
@@ -127,14 +147,28 @@ def main(spec_text: str, docs_hash: str, prev_state_json: str):
|
||||
urns["terms"][key] = reuse_terms[key]
|
||||
continue
|
||||
u = "urn:li:glossaryTerm:" + key
|
||||
if not exists_aspect(u, "glossaryTerm"):
|
||||
if exists_aspect(u, "glossaryTerm"):
|
||||
urns["terms"][key] = u
|
||||
continue
|
||||
found = find_term_by_name(tm["name"])
|
||||
if found:
|
||||
urns["terms"][key] = found
|
||||
continue
|
||||
try:
|
||||
gql('mutation($i:CreateGlossaryEntityInput!){ createGlossaryTerm(input:$i) }', {"i": {"id": key, "name": tm["name"], "description": tm.get("description", "")}})
|
||||
created["terms"] += 1
|
||||
urns["terms"][key] = u
|
||||
urns["terms"][key] = u
|
||||
except Exception:
|
||||
found2 = find_term_by_name(tm["name"])
|
||||
if found2:
|
||||
urns["terms"][key] = found2
|
||||
else:
|
||||
raise
|
||||
return {
|
||||
"urns_json": json.dumps(urns),
|
||||
"spec_json": json.dumps(spec, ensure_ascii=False),
|
||||
"created_json": json.dumps(created),
|
||||
"spec_source": "llm" if (spec_text and str(spec_text).strip()) else "cached",
|
||||
}`;
|
||||
|
||||
const CODE_BUILD_OPS = `import json
|
||||
@@ -224,7 +258,7 @@ GITEA = "http://gitea:3000"
|
||||
REPO = "admin/mini-erp-fabric-demo"
|
||||
GH = {"Authorization": "token 77c6bd2fdab535b2720821d36b4cfb74aa3bf87c", "Content-Type": "application/json"}
|
||||
|
||||
def main(global_hash: str, docs_hash: str, table_hashes_json: str, urns_json: str, created_json: str,
|
||||
def main(global_hash: str, docs_hash: str, table_hashes_json: str, urns_json: str, created_json: str, spec_json: str,
|
||||
prev_state_json: str, state_sha: str, sync_results: list, changed_tables: list):
|
||||
prev = json.loads(prev_state_json) if prev_state_json else {}
|
||||
results = [json.loads(x) for x in sync_results if x]
|
||||
@@ -236,6 +270,7 @@ def main(global_hash: str, docs_hash: str, table_hashes_json: str, urns_json: st
|
||||
"term_urns": json.loads(urns_json)["terms"],
|
||||
"last_created": json.loads(created_json),
|
||||
"last_ok_tables": ok_tables,
|
||||
"spec_json": spec_json,
|
||||
"updated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"runs": int(prev.get("runs", 0)) + 1,
|
||||
}
|
||||
@@ -274,13 +309,15 @@ const graph = {
|
||||
variables: [{ type: "text-input", variable: "force", label: "force(填true强制全量重同步)", required: false, options: [], default: "", hint: "", placeholder: "" }] }, 40, 260, { height: 108 }),
|
||||
node(N.collect, codeData("采集输入指纹", CODE_COLLECT,
|
||||
[{ name: "force", sel: [N.start, "force"] }],
|
||||
{ skip: "boolean", tables_json: "string", docs_text: "string", changed_tables: "array[string]", global_hash: "string", docs_hash: "string", table_hashes_json: "string", state_sha: "string", prev_state_json: "string" }), 340, 260, { height: 180 }),
|
||||
{ skip: "boolean", tables_json: "string", docs_text: "string", changed_tables: "array[string]", global_hash: "string", docs_hash: "string", table_hashes_json: "string", state_sha: "string", prev_state_json: "string", prev_spec_json: "string", spec_needed: "boolean" }), 340, 260, { height: 220 }),
|
||||
node(N.ifelse, { type: "if-else", title: "需要更新?", desc: "", selected: false,
|
||||
cases: [{ case_id: "true", logical_operator: "and", conditions: [{ id: "cond_skip", varType: "boolean", variable_selector: [N.collect, "skip"], comparison_operator: "is", value: "false" }] }] }, 700, 260, { height: 130 }),
|
||||
node(N.ifspec, { type: "if-else", title: "规格需重生成?", desc: "", selected: false,
|
||||
cases: [{ case_id: "true", logical_operator: "and", conditions: [{ id: "cond_spec", varType: "boolean", variable_selector: [N.collect, "spec_needed"], comparison_operator: "is", value: "true" }] }] }, 900, 260, { height: 130 }),
|
||||
node(N.endNoChange, { type: "end", title: "无变更结束", desc: "", selected: false,
|
||||
outputs: [{ variable: "result", value_type: "string", value_selector: [N.collect, "global_hash"] }] }, 1040, 460, { height: 100 }),
|
||||
node(N.llm, { type: "llm", title: "生成治理规格", desc: "", selected: false,
|
||||
model: { provider: "langgenius/siliconflow/siliconflow", name: "Pro/moonshotai/Kimi-K2.5", mode: "chat", completion_params: { temperature: 0.1 } },
|
||||
model: { provider: "langgenius/deepseek/deepseek", name: "deepseek-flash", mode: "chat", completion_params: { temperature: 0.1 } },
|
||||
prompt_template: [
|
||||
{ role: "system", text: SYS_PROMPT },
|
||||
{ role: "user", text: "【ERP库表结构】\n{{#" + N.collect + ".tables_json#}}\n\n【治理底稿】\n{{#" + N.collect + ".docs_text#}}" }],
|
||||
@@ -288,8 +325,8 @@ const graph = {
|
||||
reasoning_format: "separated", variables: [],
|
||||
retry_config: { retry_enabled: true, max_retries: 2, retry_interval: 1000 } }, 1040, 180, { height: 120 }),
|
||||
node(N.ensure, codeData("创建治理实体", CODE_ENSURE,
|
||||
[{ name: "spec_text", sel: [N.llm, "text"] }, { name: "docs_hash", sel: [N.collect, "docs_hash"] }, { name: "prev_state_json", sel: [N.collect, "prev_state_json"] }],
|
||||
{ urns_json: "string", spec_json: "string", created_json: "string" }), 1400, 180, { height: 180 }),
|
||||
[{ name: "spec_text", sel: [N.llm, "text"] }, { name: "prev_spec_json", sel: [N.collect, "prev_spec_json"] }, { name: "docs_hash", sel: [N.collect, "docs_hash"] }, { name: "prev_state_json", sel: [N.collect, "prev_state_json"] }],
|
||||
{ urns_json: "string", spec_json: "string", created_json: "string", spec_source: "string" }), 1560, 180, { height: 180 }),
|
||||
node(N.buildOps, codeData("组装同步任务", CODE_BUILD_OPS,
|
||||
[{ name: "tables_json", sel: [N.collect, "tables_json"] }, { name: "spec_json", sel: [N.ensure, "spec_json"] }, { name: "urns_json", sel: [N.ensure, "urns_json"] }, { name: "changed_tables", sel: [N.collect, "changed_tables"], type: "array[string]" }],
|
||||
{ ops: "array[string]" }), 1760, 180, { height: 180 }),
|
||||
@@ -309,20 +346,24 @@ const graph = {
|
||||
node(N.saveState, codeData("回写同步状态", CODE_SAVE_STATE,
|
||||
[{ name: "global_hash", sel: [N.collect, "global_hash"] }, { name: "docs_hash", sel: [N.collect, "docs_hash"] },
|
||||
{ name: "table_hashes_json", sel: [N.collect, "table_hashes_json"] }, { name: "urns_json", sel: [N.ensure, "urns_json"] },
|
||||
{ name: "created_json", sel: [N.ensure, "created_json"] }, { name: "prev_state_json", sel: [N.collect, "prev_state_json"] },
|
||||
{ name: "created_json", sel: [N.ensure, "created_json"] }, { name: "spec_json", sel: [N.ensure, "spec_json"] },
|
||||
{ name: "prev_state_json", sel: [N.collect, "prev_state_json"] },
|
||||
{ name: "state_sha", sel: [N.collect, "state_sha"] }, { name: "sync_results", sel: [N.iteration, "output"], type: "array[string]" },
|
||||
{ name: "changed_tables", sel: [N.collect, "changed_tables"], type: "array[string]" }],
|
||||
{ status: "string" }), 2820, 180, { height: 200 }),
|
||||
{ status: "string" }), 2980, 180, { height: 220 }),
|
||||
node(N.endSummary, { type: "end", title: "同步结果", desc: "", selected: false,
|
||||
outputs: [
|
||||
{ variable: "summary", value_type: "string", value_selector: [N.saveState, "status"] },
|
||||
{ variable: "created", value_type: "string", value_selector: [N.ensure, "created_json"] }] }, 3180, 180, { height: 120 }),
|
||||
{ variable: "created", value_type: "string", value_selector: [N.ensure, "created_json"] },
|
||||
{ variable: "spec_source", value_type: "string", value_selector: [N.ensure, "spec_source"] }] }, 3340, 180, { height: 120 }),
|
||||
],
|
||||
edges: [
|
||||
edge(N.start, N.collect, "source", "target", { st: "start", tt: "code" }),
|
||||
edge(N.collect, N.ifelse, "source", "target", { st: "code", tt: "if-else" }),
|
||||
edge(N.ifelse, N.llm, "true", "target", { st: "if-else", tt: "llm" }),
|
||||
edge(N.ifelse, N.ifspec, "true", "target", { st: "if-else", tt: "if-else" }),
|
||||
edge(N.ifelse, N.endNoChange, "false", "target", { st: "if-else", tt: "end" }),
|
||||
edge(N.ifspec, N.llm, "true", "target", { st: "if-else", tt: "llm" }),
|
||||
edge(N.ifspec, N.ensure, "false", "target", { st: "if-else", tt: "code" }),
|
||||
edge(N.llm, N.ensure, "source", "target", { st: "llm", tt: "code" }),
|
||||
edge(N.ensure, N.buildOps, "source", "target", { st: "code", tt: "code" }),
|
||||
edge(N.buildOps, N.iteration, "source", "target", { st: "code", tt: "iteration" }),
|
||||
|
||||
Reference in new issue
Block a user