feat: initial commit
This commit is contained in:
commit
539b115e38
232 files changed
+31223
No files matched your search
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env python3
|
||||
"""数据源管理功能 - 完整部署脚本
|
||||
|
||||
执行步骤:
|
||||
1. 创建 VisualDev 表单
|
||||
2. 发布表单
|
||||
3. 创建目录菜单和功能菜单
|
||||
4. 生成前后端代码
|
||||
|
||||
用法:
|
||||
python3 aibridge/scripts/deploy_data_source.py
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.environ.get("ccWorkDir", "/home/ubuntu/ccWorkDir"))
|
||||
|
||||
from aibridge import JNPFClient, JNPFConfig
|
||||
from aibridge.builders.full_config import build_full_config, build_create_payload
|
||||
from aibridge.models import FieldDef
|
||||
|
||||
|
||||
def main():
|
||||
print("=" * 60)
|
||||
print("数据源管理功能部署")
|
||||
print("=" * 60)
|
||||
|
||||
# 1. 初始化客户端
|
||||
config = JNPFConfig(app_code="dr")
|
||||
print(f"应用: {config.app_code} ({config.system_title})")
|
||||
print(f"system_id: {config.system_id}")
|
||||
print(f"db_link_id: {config.db_link_id}")
|
||||
print(f"business_category_id: {config.business_category_id}")
|
||||
|
||||
client = JNPFClient.from_config(config)
|
||||
client.login()
|
||||
print("登录成功")
|
||||
|
||||
# 2. 检查表单是否已存在
|
||||
resp = client.visual_dev.get_list({"currentPage": 1, "pageSize": 100})
|
||||
existing_forms = {}
|
||||
for item in (resp.data or {}).get("list", []):
|
||||
existing_forms[item.get("enCode")] = item.get("id")
|
||||
|
||||
# 3. 定义字段
|
||||
fields = [
|
||||
FieldDef(field="f_source_name", field_name="数据源名称", required=True),
|
||||
FieldDef(field="f_source_type", field_name="数据源类型", jnpf_key="select", options=[
|
||||
{"fullName": "MySQL", "id": "MySQL"},
|
||||
{"fullName": "Oracle", "id": "Oracle"},
|
||||
{"fullName": "PostgreSQL", "id": "PostgreSQL"},
|
||||
{"fullName": "MongoDB", "id": "MongoDB"},
|
||||
{"fullName": "API", "id": "API"},
|
||||
{"fullName": "文件", "id": "文件"},
|
||||
]),
|
||||
FieldDef(field="f_connection_config", field_name="连接配置", jnpf_key="textarea"),
|
||||
FieldDef(field="f_database_name", field_name="数据库名称"),
|
||||
FieldDef(field="f_connection_status", field_name="连接状态", jnpf_key="select", options=[
|
||||
{"fullName": "未连接", "id": "0"},
|
||||
{"fullName": "已连接", "id": "1"},
|
||||
{"fullName": "连接失败", "id": "2"},
|
||||
]),
|
||||
FieldDef(field="f_last_test_time", field_name="最后测试时间", jnpf_key="datePicker", format="yyyy-MM-dd HH:mm:ss"),
|
||||
]
|
||||
|
||||
# 4. 创建表单
|
||||
en_code = "dataSource"
|
||||
if en_code in existing_forms:
|
||||
func_id = existing_forms[en_code]
|
||||
print(f"\n表单已存在: {en_code} (func_id={func_id})")
|
||||
else:
|
||||
print(f"\n[Step 1] 创建表单: {en_code}")
|
||||
config_obj = build_full_config(
|
||||
full_name="数据源管理",
|
||||
en_code=en_code,
|
||||
table_name="data_source",
|
||||
table_label="数据源表",
|
||||
description="数据源配置管理",
|
||||
category=config.business_category_id,
|
||||
fields=[f.to_dict() for f in fields],
|
||||
web_type=2,
|
||||
)
|
||||
payload = build_create_payload(config_obj, dynamic_table=True)
|
||||
|
||||
resp = client.visual_dev.create(payload)
|
||||
func_id = resp.id
|
||||
if not func_id:
|
||||
print(f"创建失败: {resp.msg}")
|
||||
return
|
||||
|
||||
print(f"表单创建成功: func_id={func_id}")
|
||||
|
||||
# 5. 发布表单
|
||||
print(f"\n[Step 2] 发布表单...")
|
||||
rel = client.visual_dev.release(func_id)
|
||||
if rel.code != 200:
|
||||
print(f"发布失败: {rel.msg}")
|
||||
return
|
||||
print("表单发布成功")
|
||||
|
||||
# 6. 创建菜单
|
||||
print(f"\n[Step 3] 创建菜单...")
|
||||
|
||||
# 查找或创建"系统管理"目录
|
||||
resp = client.menu.get_list({"currentPage": 1, "pageSize": 500})
|
||||
parent_dir_id = None
|
||||
for m in (resp.data or {}).get("list", []):
|
||||
if m.get("fullName") in ["系统管理", "系统支撑", "系统配置"]:
|
||||
parent_dir_id = m.get("id")
|
||||
break
|
||||
|
||||
if not parent_dir_id:
|
||||
# 创建系统管理目录
|
||||
dir_resp = client.menu.create_directory_menu(
|
||||
full_name="系统管理",
|
||||
en_code="sys_mgmt",
|
||||
parent_id="-1",
|
||||
sort_code=99,
|
||||
)
|
||||
parent_dir_id = dir_resp.id
|
||||
if not parent_dir_id:
|
||||
parent_dir_id = resp.data["list"][0]["id"] if resp.data["list"] else None
|
||||
|
||||
if not parent_dir_id:
|
||||
print("无法创建菜单:找不到父级目录")
|
||||
return
|
||||
|
||||
# 创建数据源管理子目录
|
||||
dir_resp = client.menu.create_directory_menu(
|
||||
full_name="数据源管理",
|
||||
en_code="data_source_dir",
|
||||
parent_id=str(parent_dir_id),
|
||||
sort_code=1,
|
||||
)
|
||||
dir_id = dir_resp.id
|
||||
if not dir_id:
|
||||
# 目录可能已存在,查找它
|
||||
for m in (resp.data or {}).get("list", []):
|
||||
if m.get("id") == parent_dir_id:
|
||||
for c in (m.get("children") or []):
|
||||
if c.get("fullName") == "数据源管理":
|
||||
dir_id = c.get("id")
|
||||
break
|
||||
|
||||
if not dir_id:
|
||||
print("无法创建数据源管理目录")
|
||||
return
|
||||
|
||||
# 创建功能菜单
|
||||
menu_resp = client.menu.create_form_menu(
|
||||
full_name="数据源配置",
|
||||
en_code=en_code,
|
||||
visual_dev_id=func_id,
|
||||
parent_id=str(dir_id),
|
||||
sort_code=1,
|
||||
)
|
||||
menu_id = menu_resp.id
|
||||
if not menu_id:
|
||||
print("功能菜单可能已存在")
|
||||
else:
|
||||
print(f"功能菜单创建成功: menu_id={menu_id}")
|
||||
|
||||
print(f"\n✅ 部署完成!")
|
||||
print(f" func_id: {func_id}")
|
||||
print(f" menu_id: {menu_id}")
|
||||
print(f"\n下一步: 使用 CodeGenerator 生成代码")
|
||||
print(f" from aibridge.utils.code_generator import CodeGenerator")
|
||||
print(f" gen = CodeGenerator(client, config)")
|
||||
print(f" result = gen.generate(func_id='{func_id}', module_name='DataSource', auto_fix_names=True)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user