本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
228 lines
8.8 KiB
Bash
Executable File
228 lines
8.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# dacli drift loop - Phase 1: 直读 JNPF DB 拉 baseline JSON
|
|
#
|
|
# 用途:
|
|
# 把 developSystem + workSystem 的官方示例 (form/workflow/di/menu/dict/role/report/datascreen)
|
|
# schema 拉成 JSON 文件,供 /loop 的 Phase 2-5 AI 推理使用。
|
|
#
|
|
# 前提:
|
|
# - JNPF PostgreSQL DB 可达 (host=postgres port=5432 db=j62 user=dacli)
|
|
# - Python 3 + psycopg2 已装
|
|
#
|
|
# 用法:
|
|
# bash fetch-baseline.sh # 拉所有模块 baseline
|
|
# bash fetch-baseline.sh --module=form # 只拉 form
|
|
# bash fetch-baseline.sh --module=form,workflow # 拉多个模块
|
|
# bash fetch-baseline.sh --output=/tmp/my.json # 自定义输出
|
|
#
|
|
# 已知 JNPF 表结构 (基于 j62 库验证):
|
|
# - base_system : apps (developSystem/workSystem/testspace)
|
|
# - base_visual_dev : form (f_state=1 已发布)
|
|
# - workflow_template : workflow
|
|
# - base_data_interface : di (平台级,无 f_system_id)
|
|
# - base_module : menu
|
|
# - base_dictionary_type : dict 类型
|
|
# - base_dictionary_data : dict 数据
|
|
# - base_role : role
|
|
# - data_report : report
|
|
# - blade_visual : datascreen/bigscreen (id 列无 f_ 前缀, system_id 列无 f_ 前缀)
|
|
set -euo pipefail
|
|
|
|
# ========== 配置 ==========
|
|
DEFAULT_MODULE="all"
|
|
DEFAULT_OUTPUT="/tmp/dacli-loop/baseline-$(date +%Y%m%d-%H%M%S).json"
|
|
|
|
# JNPF DB 配置 (跟 boot/jnpf-admin/src/main/resources/application-dev.yml 一致)
|
|
export PG_HOST="${PG_HOST:-postgres}"
|
|
export PG_PORT="${PG_PORT:-5432}"
|
|
export PG_USER="${PG_USER:-dacli}"
|
|
export PGPASSWORD="${PGPASSWORD:-dacli123}" # default dev password
|
|
export PG_DB="${PG_DB:-j62}"
|
|
|
|
# ========== 参数解析 ==========
|
|
MODULE="$DEFAULT_MODULE"
|
|
OUTPUT="$DEFAULT_OUTPUT"
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--module=*) MODULE="${1#*=}"; shift ;;
|
|
--output=*) OUTPUT="${1#*=}"; shift ;;
|
|
-h|--help)
|
|
sed -n '2,20p' "$0" | sed 's/^# \?//'
|
|
exit 0
|
|
;;
|
|
*) echo "Unknown arg: $1"; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
mkdir -p "$(dirname "$OUTPUT")"
|
|
|
|
# ========== 主逻辑 (python 跑 SQL) ==========
|
|
python3 <<PYEOF
|
|
import psycopg2, os, json, sys
|
|
|
|
MODULES = "$MODULE".split(",") if "$MODULE" != "all" else [
|
|
"form", "workflow", "di", "menu", "dict", "role", "report", "datascreen"
|
|
]
|
|
|
|
conn = psycopg2.connect(
|
|
host=os.environ["PG_HOST"],
|
|
port=int(os.environ["PG_PORT"]),
|
|
user=os.environ["PG_USER"],
|
|
password=os.environ["PGPASSWORD"],
|
|
database=os.environ["PG_DB"],
|
|
)
|
|
cur = conn.cursor()
|
|
|
|
# 拿 baseline apps 的 system_id (只读 developSystem + workSystem)
|
|
cur.execute("SELECT f_id, f_en_code, f_full_name FROM base_system WHERE f_en_code IN ('developSystem', 'workSystem')")
|
|
apps = {row[1]: {"id": row[0], "full_name": row[2]} for row in cur.fetchall()}
|
|
sysids = [a["id"] for a in apps.values()]
|
|
print(f"baseline apps: {list(apps.keys())} system_ids={sysids}", file=sys.stderr)
|
|
|
|
result = {"_meta": {"apps": apps, "modules": MODULES, "fetched_at": __import__("datetime").datetime.now().isoformat()}}
|
|
|
|
# ---- form ----
|
|
if "form" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_en_code, f_full_name, f_type, f_web_type, f_category, f_db_link_id,
|
|
f_form_data, f_column_data, f_tables_data, f_enable_flow, f_state,
|
|
f_creator_time, f_system_id
|
|
FROM base_visual_dev
|
|
WHERE f_system_id = ANY(%s) AND f_state = 1
|
|
ORDER BY f_creator_time
|
|
""", (sysids,))
|
|
cols = [d[0] for d in cur.description]
|
|
result["forms"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" forms: {len(result['forms'])}", file=sys.stderr)
|
|
|
|
# ---- workflow ----
|
|
if "workflow" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_en_code, f_full_name, f_type, f_category, f_flow_id,
|
|
f_configuration, f_enabled_mark, f_creator_time, f_system_id
|
|
FROM workflow_template
|
|
WHERE f_system_id = ANY(%s) AND f_enabled_mark = 1
|
|
ORDER BY f_creator_time
|
|
""", (sysids,))
|
|
cols = [d[0] for d in cur.description]
|
|
result["workflows"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" workflows: {len(result['workflows'])}", file=sys.stderr)
|
|
|
|
# ---- di (platform-level, no system_id) ----
|
|
if "di" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_en_code, f_full_name, f_category, f_type, f_action,
|
|
f_parameter_json, f_field_json, f_data_config_json, f_enabled_mark,
|
|
f_creator_time
|
|
FROM base_data_interface
|
|
WHERE f_enabled_mark = 1
|
|
ORDER BY f_creator_time
|
|
""")
|
|
cols = [d[0] for d in cur.description]
|
|
result["data_interfaces"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" data_interfaces: {len(result['data_interfaces'])} (platform-level)", file=sys.stderr)
|
|
|
|
# ---- menu ----
|
|
if "menu" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_parent_id, f_type, f_full_name, f_en_code, f_category,
|
|
f_url_address, f_icon, f_module_id, f_property_json,
|
|
f_enabled_mark, f_creator_time, f_system_id
|
|
FROM base_module
|
|
WHERE f_system_id = ANY(%s) AND f_enabled_mark = 1
|
|
ORDER BY f_creator_time
|
|
""", (sysids,))
|
|
cols = [d[0] for d in cur.description]
|
|
result["menus"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" menus: {len(result['menus'])}", file=sys.stderr)
|
|
|
|
# ---- dict ----
|
|
if "dict" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_parent_id, f_full_name, f_en_code, f_is_tree, f_type,
|
|
f_enabled_mark, f_creator_time
|
|
FROM base_dictionary_type
|
|
WHERE f_enabled_mark = 1
|
|
ORDER BY f_creator_time
|
|
""")
|
|
cols = [d[0] for d in cur.description]
|
|
result["dict_types"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" dict_types: {len(result['dict_types'])} (platform-level)", file=sys.stderr)
|
|
|
|
# ---- role (platform-level, no f_system_id) ----
|
|
if "role" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_full_name, f_en_code, f_type, f_global_mark,
|
|
f_property_json, f_enabled_mark, f_creator_time
|
|
FROM base_role
|
|
WHERE f_enabled_mark = 1
|
|
ORDER BY f_creator_time
|
|
""")
|
|
cols = [d[0] for d in cur.description]
|
|
result["roles"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" roles: {len(result['roles'])} (platform-level)", file=sys.stderr)
|
|
|
|
# ---- report ----
|
|
if "report" in MODULES:
|
|
cur.execute("""
|
|
SELECT f_id, f_fullname, f_encode, f_categoryid, f_content,
|
|
f_enabledmark, f_creatortime, f_system_id
|
|
FROM data_report
|
|
WHERE f_system_id = ANY(%s) AND f_enabledmark = 1
|
|
ORDER BY f_creatortime
|
|
""", (sysids,))
|
|
cols = [d[0] for d in cur.description]
|
|
result["reports"] = [dict(zip(cols, row)) for row in cur.fetchall()]
|
|
print(f" reports: {len(result['reports'])}", file=sys.stderr)
|
|
|
|
# ---- datascreen (大屏,独立子项目 blade_visual) ----
|
|
# Round 15 (2026-07-15): 增补 config/component 字段
|
|
# - baseline JSON 仅含元数据时, 组件级 diff 不可行 (BS-drift-DS-1 持久化问题无法定位)
|
|
# - 加 config (blade_visual_config) + component (blade_visual_component) 后
|
|
# 可派生组件数 + 组件 name/title/prop/type
|
|
if "datascreen" in MODULES:
|
|
cur.execute("""
|
|
SELECT id, title, category, status, password, create_user, create_time, system_id
|
|
FROM blade_visual
|
|
WHERE system_id = ANY(%s) AND is_deleted = 0
|
|
ORDER BY create_time
|
|
""", (sysids,))
|
|
cols = [d[0] for d in cur.description]
|
|
ds_rows = []
|
|
for row in cur.fetchall():
|
|
d = dict(zip(cols, row))
|
|
visual_id = d["id"]
|
|
# 拉 config JSON
|
|
cur.execute("SELECT content FROM blade_visual_config WHERE visual_id = %s", (visual_id,))
|
|
cfg_row = cur.fetchone()
|
|
cfg = None
|
|
if cfg_row and cfg_row[0]:
|
|
try: cfg = json.loads(cfg_row[0]) if isinstance(cfg_row[0], str) else cfg_row[0]
|
|
except: cfg = {"_raw": str(cfg_row[0])[:200]}
|
|
d["config"] = cfg
|
|
# 拉组件列表
|
|
cur.execute("""
|
|
SELECT name, component_type, prop_value
|
|
FROM blade_visual_component
|
|
WHERE visual_id = %s
|
|
ORDER BY name
|
|
""", (visual_id,))
|
|
comps = []
|
|
for crow in cur.fetchall():
|
|
comps.append({"name": crow[0], "component_type": crow[1], "prop_value": crow[2]})
|
|
d["components"] = comps
|
|
d["componentCount"] = len(comps)
|
|
d["componentNames"] = [c["name"] for c in comps][:50]
|
|
ds_rows.append(d)
|
|
result["datascreens"] = ds_rows
|
|
print(f" datascreens: {len(result['datascreens'])} (含 config + components)", file=sys.stderr)
|
|
|
|
# 输出
|
|
with open("$OUTPUT", "w", encoding="utf-8") as f:
|
|
json.dump(result, f, ensure_ascii=False, indent=2, default=str)
|
|
|
|
print(f"\n✓ baseline written to: $OUTPUT", file=sys.stderr)
|
|
print(f" size: {os.path.getsize('$OUTPUT')} bytes", file=sys.stderr)
|
|
PYEOF
|
|
|
|
echo "$OUTPUT" |