From 2d9f157032974ee01c4cc37ba6d7dccd217019a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E9=87=91=E6=B3=BD?= <1098696801@qq.com> Date: Tue, 31 May 2022 19:12:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=95=B0=E6=8D=AE=E6=BA=90=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/系统管理/代码生成/所有数据源.ms | 103 ++++++++++++++++++ .../api/系统管理/代码生成/执行生成.ms | 16 +-- .../api/系统管理/代码生成/查出所有表.ms | 10 +- .../系统管理/代码生成/根据表名查出所有列.ms | 4 +- .../src/views/lowcode/code-gen-form.vue | 46 +++++++- 5 files changed, 159 insertions(+), 20 deletions(-) create mode 100644 data/magic-api/api/系统管理/代码生成/所有数据源.ms diff --git a/data/magic-api/api/系统管理/代码生成/所有数据源.ms b/data/magic-api/api/系统管理/代码生成/所有数据源.ms new file mode 100644 index 0000000..5463c38 --- /dev/null +++ b/data/magic-api/api/系统管理/代码生成/所有数据源.ms @@ -0,0 +1,103 @@ +{ + "properties" : { }, + "id" : "600d13f5cf6d4c3496da2764045c2ac6", + "script" : null, + "groupId" : "f2538e0f370a4cabab0ae920f5e77ae7", + "name" : "所有数据源", + "createTime" : null, + "updateTime" : 1653990520715, + "lock" : null, + "createBy" : null, + "updateBy" : null, + "path" : "/database", + "method" : "GET", + "parameters" : [ ], + "options" : [ ], + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": null,\n \"timestamp\": 1653990517813,\n \"executeTime\": 8\n}", + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "code", + "value" : "200", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "message", + "value" : "success", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "data", + "value" : "null", + "description" : "", + "required" : false, + "dataType" : "Array", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "timestamp", + "value" : "1653990517813", + "description" : "", + "required" : false, + "dataType" : "Long", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "executeTime", + "value" : "8", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } +} +================================ +import org.ssssssss.magicapi.datasource.model.MagicDynamicDataSource +return MagicDynamicDataSource.datasources().map(it => { + return { + label: it == '' ? '默认数据源' : it, + value: it + } +}) \ No newline at end of file diff --git a/data/magic-api/api/系统管理/代码生成/执行生成.ms b/data/magic-api/api/系统管理/代码生成/执行生成.ms index 0fffac5..2aa4e24 100644 --- a/data/magic-api/api/系统管理/代码生成/执行生成.ms +++ b/data/magic-api/api/系统管理/代码生成/执行生成.ms @@ -5,7 +5,7 @@ "groupId" : "f2538e0f370a4cabab0ae920f5e77ae7", "name" : "执行生成", "createTime" : null, - "updateTime" : 1652170746742, + "updateTime" : 1653992145291, "lock" : null, "createBy" : null, "updateBy" : null, @@ -325,7 +325,7 @@ columns.forEach(it => { } }) -var commonField = db.select(""" +var commonField = db[datasource].select(""" SELECT column_name FROM @@ -334,7 +334,7 @@ var commonField = db.select(""" table_name = #{tableName} AND column_name IN ( 'is_del', 'create_by', 'create_date', 'update_by', 'update_date' ) AND table_schema = DATABASE() """) commonField = commonField.map(it => it.columnName) -var primary = db.selectValue("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = #{tableName} and column_key = 'PRI' and table_schema = database() limit 1") +var primary = db[datasource].selectValue("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = #{tableName} and column_key = 'PRI' and table_schema = database() limit 1") var primaryLowerCamelCase = primary.replace(/([A-Z])/g,"_$1").toLowerCase() var logic = '' @@ -344,12 +344,14 @@ if(commonField.contains('is_del')){ } wheres = wheres.substring(0,wheres.length() - 1) +var datasourceScript = datasource ? `.${datasource}` : ''; + ApiInfo listApi = new ApiInfo() listApi.setName("列表") listApi.setPath("/list") listApi.setMethod("POST") listApi.setGroupId(businessGroup.getId()) -listApi.setScript(`return db.page(""" +listApi.setScript(`return db${datasourceScript}.page(""" select ${primary},${listFields} from ${tableName} where 1=1 ${wheres} """)`) @@ -366,7 +368,7 @@ saveApi.setName("保存") saveApi.setPath("/save") saveApi.setMethod("POST") saveApi.setGroupId(businessGroup.getId()) -saveApi.setScript(`return db.table('${tableName}').primary('${primary}').${saveMethod}`) +saveApi.setScript(`return db${datasourceScript}.table('${tableName}').primary('${primary}').${saveMethod}`) saveApi.setOption([new Option('wrap_request_parameter', 'data'), new Option('permission', `${permissionPrefix}:save`, '允许拥有该权限的访问')]) MagicResourceService.saveFile(saveApi) @@ -375,7 +377,7 @@ deleteApi.setName("删除") deleteApi.setPath("/delete") deleteApi.setMethod("DELETE") deleteApi.setGroupId(businessGroup.getId()) -deleteApi.setScript(`return db.table('${tableName}')${logic}.where().eq('${primary}', ${primaryLowerCamelCase}).delete()`) +deleteApi.setScript(`return db${datasourceScript}.table('${tableName}')${logic}.where().eq('${primary}', ${primaryLowerCamelCase}).delete()`) deleteApi.setOption([new Option('permission', `${permissionPrefix}:delete`, '允许拥有该权限的访问')]) MagicResourceService.saveFile(deleteApi) @@ -386,7 +388,7 @@ getApi.setName("详情") getApi.setPath("/get") getApi.setMethod("GET") getApi.setGroupId(businessGroup.getId()) -getApi.setScript(`return db.selectOne(""" +getApi.setScript(`return db${datasourceScript}.selectOne(""" select ${primary},${saveFields} from ${tableName} where ${primary} = #{${primaryLowerCamelCase}} """)`) getApi.setOption([new Option('permission', `${permissionPrefix}:view`, '允许拥有该权限的访问')]) diff --git a/data/magic-api/api/系统管理/代码生成/查出所有表.ms b/data/magic-api/api/系统管理/代码生成/查出所有表.ms index ff9afa4..87437eb 100644 --- a/data/magic-api/api/系统管理/代码生成/查出所有表.ms +++ b/data/magic-api/api/系统管理/代码生成/查出所有表.ms @@ -5,7 +5,7 @@ "groupId" : "f2538e0f370a4cabab0ae920f5e77ae7", "name" : "查出所有表", "createTime" : null, - "updateTime" : 1648389273779, + "updateTime" : 1653990626738, "lock" : null, "createBy" : null, "updateBy" : null, @@ -16,7 +16,7 @@ "requestBody" : "", "headers" : [ ], "paths" : [ ], - "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"label\": \"magic_backup_record_v2()\",\n \"value\": \"magic_backup_record_v2\"\n }, {\n \"label\": \"sys_dict(字典表)\",\n \"value\": \"sys_dict\"\n }, {\n \"label\": \"sys_dict_items(字典项表)\",\n \"value\": \"sys_dict_items\"\n }, {\n \"label\": \"sys_file(文件表)\",\n \"value\": \"sys_file\"\n }, {\n \"label\": \"sys_gen_info(生成表信息)\",\n \"value\": \"sys_gen_info\"\n }, {\n \"label\": \"sys_gen_test()\",\n \"value\": \"sys_gen_test\"\n }, {\n \"label\": \"sys_login_log()\",\n \"value\": \"sys_login_log\"\n }, {\n \"label\": \"sys_menu(菜单表)\",\n \"value\": \"sys_menu\"\n }, {\n \"label\": \"sys_office(组织机构表)\",\n \"value\": \"sys_office\"\n }, {\n \"label\": \"sys_oper_log(操作日志)\",\n \"value\": \"sys_oper_log\"\n }, {\n \"label\": \"sys_permission_code(权限code表)\",\n \"value\": \"sys_permission_code\"\n }, {\n \"label\": \"sys_role(角色表)\",\n \"value\": \"sys_role\"\n }, {\n \"label\": \"sys_role_menu(角色和菜单关联表)\",\n \"value\": \"sys_role_menu\"\n }, {\n \"label\": \"sys_role_office(用户组织机构关联表)\",\n \"value\": \"sys_role_office\"\n }, {\n \"label\": \"sys_test_data()\",\n \"value\": \"sys_test_data\"\n }, {\n \"label\": \"sys_user(用户表)\",\n \"value\": \"sys_user\"\n }, {\n \"label\": \"sys_user_code(用户权限code关联表)\",\n \"value\": \"sys_user_code\"\n }, {\n \"label\": \"sys_user_role(用户与角色关联表)\",\n \"value\": \"sys_user_role\"\n }],\n \"timestamp\": 1648372075872,\n \"executeTime\": 24\n}", + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"label\": \"magic_backup_record_v2()\",\n \"value\": \"magic_backup_record_v2\"\n }, {\n \"label\": \"sys_configure(配置中心)\",\n \"value\": \"sys_configure\"\n }, {\n \"label\": \"sys_dict(字典表)\",\n \"value\": \"sys_dict\"\n }, {\n \"label\": \"sys_dict_items(字典项表)\",\n \"value\": \"sys_dict_items\"\n }, {\n \"label\": \"sys_file(文件表)\",\n \"value\": \"sys_file\"\n }, {\n \"label\": \"sys_gen_info(生成表信息)\",\n \"value\": \"sys_gen_info\"\n }, {\n \"label\": \"sys_login_log()\",\n \"value\": \"sys_login_log\"\n }, {\n \"label\": \"sys_menu(菜单表)\",\n \"value\": \"sys_menu\"\n }, {\n \"label\": \"sys_office(组织机构表)\",\n \"value\": \"sys_office\"\n }, {\n \"label\": \"sys_oper_log(操作日志)\",\n \"value\": \"sys_oper_log\"\n }, {\n \"label\": \"sys_permission_code(权限code表)\",\n \"value\": \"sys_permission_code\"\n }, {\n \"label\": \"sys_role(角色表)\",\n \"value\": \"sys_role\"\n }, {\n \"label\": \"sys_role_menu(角色和菜单关联表)\",\n \"value\": \"sys_role_menu\"\n }, {\n \"label\": \"sys_role_office(用户组织机构关联表)\",\n \"value\": \"sys_role_office\"\n }, {\n \"label\": \"sys_test_data()\",\n \"value\": \"sys_test_data\"\n }, {\n \"label\": \"sys_user(用户表)\",\n \"value\": \"sys_user\"\n }, {\n \"label\": \"sys_user_code(用户权限code关联表)\",\n \"value\": \"sys_user_code\"\n }, {\n \"label\": \"sys_user_role(用户与角色关联表)\",\n \"value\": \"sys_user_role\"\n }, {\n \"label\": \"t_data_test(测试生成)\",\n \"value\": \"t_data_test\"\n }],\n \"timestamp\": 1653990585569,\n \"executeTime\": 11\n}", "description" : null, "requestBodyDefinition" : null, "responseBodyDefinition" : { @@ -104,7 +104,7 @@ } ] }, { "name" : "timestamp", - "value" : "1648372075872", + "value" : "1653990585569", "description" : "", "required" : false, "dataType" : "Long", @@ -116,7 +116,7 @@ "children" : [ ] }, { "name" : "executeTime", - "value" : "24", + "value" : "11", "description" : "", "required" : false, "dataType" : "Object", @@ -130,6 +130,6 @@ } } ================================ -return db.select(""" +return db[datasource].select(""" select table_name, table_comment from information_schema.tables where table_schema = database() """).map(it => { label: it.tableName + `(${it.tableComment})`, value: it.tableName }) \ No newline at end of file diff --git a/data/magic-api/api/系统管理/代码生成/根据表名查出所有列.ms b/data/magic-api/api/系统管理/代码生成/根据表名查出所有列.ms index 81d6b6b..168b11d 100644 --- a/data/magic-api/api/系统管理/代码生成/根据表名查出所有列.ms +++ b/data/magic-api/api/系统管理/代码生成/根据表名查出所有列.ms @@ -5,7 +5,7 @@ "groupId" : "f2538e0f370a4cabab0ae920f5e77ae7", "name" : "根据表名查出所有列", "createTime" : null, - "updateTime" : 1648484373195, + "updateTime" : 1653991292310, "lock" : null, "createBy" : null, "updateBy" : null, @@ -191,7 +191,7 @@ } ================================ return { - columns: db.select(""" + columns: db[datasource].select(""" SELECT column_name, column_comment, diff --git a/magic-boot-ui/src/views/lowcode/code-gen-form.vue b/magic-boot-ui/src/views/lowcode/code-gen-form.vue index d68ef42..dc3512f 100644 --- a/magic-boot-ui/src/views/lowcode/code-gen-form.vue +++ b/magic-boot-ui/src/views/lowcode/code-gen-form.vue @@ -3,12 +3,17 @@ - + + + + + + - + @@ -92,7 +97,7 @@