优化一波生成,加载组件等

This commit is contained in:
吕金泽
2022-03-30 23:54:24 +08:00
parent 2e19ca3493
commit b91328dcc7
35 changed files with 460 additions and 547 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"properties" : { },
"id" : "20316fcfa94644d685fa1b464f135f9a",
"id" : "8d60ba6788ef4a75b93f3c77683c7f89",
"name" : "数据管理",
"type" : "api",
"parentId" : "0",
@@ -1,9 +1,9 @@
{
"properties" : { },
"id" : "152b9ad78aaf49a7a8945b5de088c1da",
"id" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "测试生成",
"type" : "api",
"parentId" : "20316fcfa94644d685fa1b464f135f9a",
"parentId" : "8d60ba6788ef4a75b93f3c77683c7f89",
"path" : "/test",
"paths" : [ ],
"options" : [ ]
@@ -1,77 +1,17 @@
{
"properties" : { },
"id" : "d6c54f1563964523b601bd03d32e1bf0",
"id" : "46a5f8f41666462987ae042469b99ff4",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "保存",
"createTime" : null,
"updateTime" : 1648486126527,
"createTime" : 1648655132918,
"updateTime" : null,
"lock" : null,
"createBy" : null,
"updateBy" : null,
"path" : "/save",
"method" : "POST",
"parameters" : [ {
"name" : "name",
"value" : "111111",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "sex",
"value" : "222222",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "head_portrait",
"value" : "333333",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "remarks",
"value" : "444444",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
}, {
"name" : "id",
"value" : "09c850212e1740e99485a850b90825a5",
"description" : null,
"required" : false,
"dataType" : "String",
"type" : null,
"defaultValue" : null,
"validateType" : null,
"error" : null,
"expression" : null,
"children" : null
} ],
"parameters" : [ ],
"options" : [ {
"name" : "wrap_request_parameter",
"value" : "data",
@@ -85,85 +25,13 @@
"expression" : null,
"children" : null
} ],
"requestBody" : "",
"requestBody" : null,
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"09c850212e1740e99485a850b90825a5\",\n \"timestamp\": 1648486104458,\n \"executeTime\": 12\n}",
"responseBody" : null,
"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" : "09c850212e1740e99485a850b90825a5",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "timestamp",
"value" : "1648486104458",
"description" : "",
"required" : false,
"dataType" : "Long",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "12",
"description" : "",
"required" : false,
"dataType" : "Integer",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
} ]
}
"responseBodyDefinition" : null
}
================================
return db.table('t_data_test').primary('id').saveOrUpdate(data)
@@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "90986654bb2d4560ada10c309195f500",
"id" : "d94a4788e17a4e0f9b67ca86b171e231",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "列表",
"createTime" : 1648486052761,
"createTime" : 1648655132912,
"updateTime" : null,
"lock" : null,
"createBy" : null,
@@ -28,4 +28,5 @@ return db.page("""
?{sex, and sex = #{sex} }
?{headPortrait, and head_portrait in(#{headPortrait.split(',')}) }
?{remarks, and remarks <= #{remarks} }
and is_del = 0
""")
@@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "7443f294349446289c25d4ef6fe2b499",
"id" : "e1df886fe7604810b495d555abaa6200",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "删除",
"createTime" : 1648486052772,
"createTime" : 1648655132924,
"updateTime" : null,
"lock" : null,
"createBy" : null,
@@ -1,10 +1,10 @@
{
"properties" : { },
"id" : "f0e1cfcf4f254e17b75d7647f4f09f25",
"id" : "c999de118aa04594bc14c0e3f5ade568",
"script" : null,
"groupId" : "152b9ad78aaf49a7a8945b5de088c1da",
"groupId" : "7bdcc43555b9419caba2ee722e1aa2d3",
"name" : "详情",
"createTime" : 1648486052778,
"createTime" : 1648655132931,
"updateTime" : null,
"lock" : null,
"createBy" : null,
@@ -5,7 +5,7 @@
"groupId" : "f2538e0f370a4cabab0ae920f5e77ae7",
"name" : "执行生成",
"createTime" : null,
"updateTime" : 1648486047810,
"updateTime" : 1648651494341,
"lock" : null,
"createBy" : null,
"updateBy" : null,
@@ -214,43 +214,66 @@
}
}
================================
import org.ssssssss.magicapi.core.model.Option
import org.ssssssss.magicapi.component.model.ComponentInfo
import org.ssssssss.magicapi.core.model.ApiInfo
import org.ssssssss.magicapi.core.model.Group
import org.ssssssss.magicapi.core.service.MagicResourceService
import log
info = info::json
var moduleGroup = MagicResourceService.tree('api').children.filter(it => {
return it.node.path == info.modulePath || it.node.path == info.modulePath.substring(1, info.modulePath.length())
})
if(moduleGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.moduleName);
group.setPath(info.modulePath);
group.setParentId("0");
group.setType('api')
MagicResourceService.saveGroup(group);
moduleGroup = group;
}else{
moduleGroup = moduleGroup[0].node
var getGroup = (type) => {
var moduleGroup = MagicResourceService.tree(type).children.filter(it => {
return it.node.path == info.modulePath || it.node.path == info.modulePath.substring(1, info.modulePath.length())
})
if(moduleGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.moduleName);
group.setPath(info.modulePath);
group.setParentId("0");
group.setType(type)
MagicResourceService.saveGroup(group);
moduleGroup = group;
}else{
moduleGroup = moduleGroup[0].node
}
var businessGroup = MagicResourceService.tree(type).children.filter(it => it.node.id == moduleGroup.id)[0].children.filter(it => {
return it.node.path == info.businessPath || it.node.path == info.businessPath.substring(1, info.businessPath.length())
})
if(businessGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.businessName);
group.setPath(info.businessPath);
group.setParentId(moduleGroup.getId());
group.setType(type)
MagicResourceService.saveGroup(group);
businessGroup = group;
}else{
businessGroup = businessGroup[0].node
}
return {
moduleGroup,
businessGroup
}
}
var businessGroup = MagicResourceService.tree('api').children.filter(it => it.node.id == moduleGroup.id)[0].children.filter(it => {
return it.node.path == info.businessPath || it.node.path == info.businessPath.substring(1, info.businessPath.length())
})
if(businessGroup.length == 0){
Group group = new Group();
group.setId(UUID.randomUUID().toString().replace('-', ''));
group.setName(info.businessName);
group.setPath(info.businessPath);
group.setParentId(moduleGroup.getId());
group.setType('api')
MagicResourceService.saveGroup(group);
businessGroup = group;
}else{
businessGroup = businessGroup[0].node
var deleteFiles = (groupId, paths) => {
var listFiles = MagicResourceService.listFiles(groupId)
listFiles.forEach(it => {
if(paths.indexOf(it.path) != -1){
MagicResourceService.delete(it.id)
}
})
}
var businessGroup = getGroup('api').businessGroup
deleteFiles(businessGroup.getId(),['/list', '/save', '/get', '/delete'])
columns = columns::json
var listFields = columns.filter(it => it.list).map(it => it.columnName.replace(/([A-Z])/g,"_$1").toLowerCase()).join(',')
var wheres = '';
@@ -266,7 +289,6 @@ columns.forEach(it => {
}
}
})
wheres = wheres.substring(0,wheres.length() - 1)
var commonField = db.select("""
SELECT
@@ -280,6 +302,13 @@ 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 primaryLowerCamelCase = primary.replace(/([A-Z])/g,"_$1").toLowerCase()
var logic = ''
if(commonField.contains('is_del')){
logic = '.logic()'
wheres += ` and is_del = 0\n`
}
wheres = wheres.substring(0,wheres.length() - 1)
ApiInfo listApi = new ApiInfo()
listApi.setName("列表")
listApi.setPath("/list")
@@ -302,14 +331,9 @@ saveApi.setPath("/save")
saveApi.setMethod("POST")
saveApi.setGroupId(businessGroup.getId())
saveApi.setScript(`return db.table('${tableName}').primary('${primary}').${saveMethod}`)
saveApi.setOption([{ name: 'wrap_request_parameter', value: 'data' }])
saveApi.setOption([new Option('wrap_request_parameter', 'data')])
MagicResourceService.saveFile(saveApi)
var logic = ''
if(commonField.contains('is_del')){
logic = '.logic()'
}
ApiInfo deleteApi = new ApiInfo()
deleteApi.setName("删除")
deleteApi.setPath("/delete")
@@ -330,4 +354,16 @@ getApi.setScript(`return db.selectOne("""
""")`)
MagicResourceService.saveFile(getApi)
return commonField
var componentBusinessGroup = getGroup('component').businessGroup
deleteFiles(componentBusinessGroup.getId(),['/list'])
ComponentInfo componentInfo = new ComponentInfo()
componentInfo.setGroupId(componentBusinessGroup.getId())
componentInfo.setName("列表")
componentInfo.setPath("/list")
componentInfo.setScript(componentScript)
MagicResourceService.saveFile(componentInfo)
return 1
@@ -5,7 +5,7 @@
"groupId" : "1952f25c81084e24b55b11385767dc38",
"name" : "登录",
"createTime" : null,
"updateTime" : 1648478302933,
"updateTime" : 1648567495848,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@@ -64,7 +64,7 @@
"requestBody" : "{\r\n \"username\": \"admin\",\r\n \"password\": \"123456\"\r\n}",
"headers" : [ ],
"paths" : [ ],
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"cb63a01c-63d7-4722-a2c4-48fffa4b3502\",\n \"timestamp\": 1647395770056,\n \"executeTime\": 20\n}",
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"319e2efb-9e42-4b86-9658-a60d3585a7fe\",\n \"timestamp\": 1648565675784,\n \"executeTime\": 12\n}",
"description" : null,
"requestBodyDefinition" : {
"name" : "",
@@ -140,7 +140,7 @@
"children" : [ ]
}, {
"name" : "data",
"value" : "cb63a01c-63d7-4722-a2c4-48fffa4b3502",
"value" : "319e2efb-9e42-4b86-9658-a60d3585a7fe",
"description" : "",
"required" : false,
"dataType" : "Object",
@@ -152,7 +152,7 @@
"children" : [ ]
}, {
"name" : "timestamp",
"value" : "1647395770056",
"value" : "1648565675784",
"description" : "",
"required" : false,
"dataType" : "Long",
@@ -164,7 +164,7 @@
"children" : [ ]
}, {
"name" : "executeTime",
"value" : "20",
"value" : "12",
"description" : "",
"required" : false,
"dataType" : "Integer",
@@ -5,7 +5,7 @@
"groupId" : "42d241c0bb18476f8dabf92c2e4e2324",
"name" : "列表",
"createTime" : null,
"updateTime" : 1646552460608,
"updateTime" : 1648647148457,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@
"groupId" : "6f106ebdee21489db34b956f7770ff03",
"name" : "选择组件",
"createTime" : null,
"updateTime" : 1648025271406,
"updateTime" : 1648647253717,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@@ -230,7 +230,7 @@ import org.ssssssss.magicapi.utils.PathUtils
import org.ssssssss.magicapi.core.service.MagicResourceService
var getFiles = (groupId) => {
return MagicResourceService.listFiles(groupId).map(file => {
id: PathUtils.replaceSlash(String.format("%s-%s", MagicResourceService.getGroupPath(file.groupId), file.path)).replace('/', '-'),
id: PathUtils.replaceSlash(String.format("%s/%s", MagicResourceService.getGroupPath(file.groupId), file.path)).replace(/^\//,'').replace(/\/\//, '/').replace('/', '-'),
label: `${file.name}(${file.path})`
})
}
@@ -5,7 +5,7 @@
"groupId" : "67b2ce258e24491194b74992958c74aa",
"name" : "保存",
"createTime" : null,
"updateTime" : 1646576146705,
"updateTime" : 1648647102120,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@@ -59,7 +59,7 @@
}
================================
import org.ssssssss.magicapi.modules.db.cache.SqlCache;
import '@get:/menu/cache/delete' as cacheDelete;
import '@get:/system/menu/cache/delete' as cacheDelete;
if(data.url){
var urlCount = db.selectInt("select count(1) from sys_menu where is_del = 0 and url = #{data.url} ?{data.id, and id != #{data.id}}")
@@ -5,7 +5,7 @@
"groupId" : "67b2ce258e24491194b74992958c74aa",
"name" : "删除",
"createTime" : null,
"updateTime" : 1646553101301,
"updateTime" : 1648647114911,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@@ -130,7 +130,7 @@
}
}
================================
import '@get:/menu/cache/delete' as cacheDelete;
import '@get:/system/menu/cache/delete' as cacheDelete;
var menuId = id
cacheDelete();
@@ -4,8 +4,8 @@
"script" : null,
"groupId" : "89130d496f6f467c88b22ae4a7f688eb",
"name" : "保存",
"createTime" : 1646490239526,
"updateTime" : 1644121680268,
"createTime" : null,
"updateTime" : 1648647133039,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@@ -30,11 +30,23 @@
"paths" : [ ],
"responseBody" : null,
"description" : null,
"requestBodyDefinition" : null,
"requestBodyDefinition" : {
"name" : "",
"value" : "",
"description" : "",
"required" : false,
"dataType" : "Object",
"type" : null,
"defaultValue" : null,
"validateType" : "",
"error" : "",
"expression" : "",
"children" : [ ]
},
"responseBodyDefinition" : null
}
================================
import '@get:/role/cache/delete' as cacheDelete
import '@get:/system/role/cache/delete' as cacheDelete
var codeCount = db.selectInt("select count(1) from sys_role where is_del = 0 and code = #{code} ?{id, and id != #{id}}")
if(codeCount > 0){
@@ -5,7 +5,7 @@
"groupId" : "89130d496f6f467c88b22ae4a7f688eb",
"name" : "删除",
"createTime" : null,
"updateTime" : 1647615829916,
"updateTime" : 1648647124177,
"lock" : "0",
"createBy" : null,
"updateBy" : null,
@@ -46,7 +46,7 @@
"responseBodyDefinition" : null
}
================================
import '@get:/role/cache/delete' as cacheDelete
import '@get:/system/role/cache/delete' as cacheDelete
var userCount = db.selectInt("select count(1) from sys_user_role where role_id = #{id}")
if(userCount > 0){