mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2026-04-26 00:00:04 +08:00
代码生成、优化
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "组织机构",
|
||||
"type" : "api",
|
||||
"parentId" : "acff5ad7aae64de2acb03e1d16a58ce2",
|
||||
"path" : "/office",
|
||||
"paths" : [ ],
|
||||
"options" : [ ]
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "37aaae0a84ce4e00ad4f89d704d3cb51",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "上移",
|
||||
"createTime" : 1646490239489,
|
||||
"updateTime" : 1641732205207,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/sort/up",
|
||||
"method" : "GET",
|
||||
"parameters" : [ ],
|
||||
"options" : [ ],
|
||||
"requestBody" : "",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : null,
|
||||
"description" : null,
|
||||
"requestBodyDefinition" : null,
|
||||
"responseBodyDefinition" : null
|
||||
}
|
||||
================================
|
||||
var top = db.selectOne("""
|
||||
SELECT
|
||||
id,
|
||||
sort
|
||||
FROM
|
||||
sys_office
|
||||
WHERE
|
||||
is_del = 0
|
||||
AND pid = #{pid}
|
||||
AND sort < ( SELECT sort FROM sys_office WHERE is_del = 0 AND id = #{id} )
|
||||
ORDER BY
|
||||
sort DESC
|
||||
LIMIT 1
|
||||
""")
|
||||
if(top){
|
||||
db.update("""
|
||||
update sys_office set sort = #{top.sort} where id = #{id}
|
||||
""")
|
||||
db.update("""
|
||||
update sys_office set sort = #{sort} where id = #{top.id}
|
||||
""")
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "5f8edf5b8045475f92049270bcf0739a",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "下移",
|
||||
"createTime" : 1646490239491,
|
||||
"updateTime" : 1641737498723,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/sort/down",
|
||||
"method" : "GET",
|
||||
"parameters" : [ ],
|
||||
"options" : [ ],
|
||||
"requestBody" : "",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : null,
|
||||
"description" : null,
|
||||
"requestBodyDefinition" : null,
|
||||
"responseBodyDefinition" : null
|
||||
}
|
||||
================================
|
||||
var top = db.selectOne("""
|
||||
SELECT
|
||||
id,
|
||||
sort
|
||||
FROM
|
||||
sys_office
|
||||
WHERE
|
||||
is_del = 0
|
||||
AND pid = #{pid}
|
||||
AND sort > ( SELECT sort FROM sys_office WHERE is_del = 0 AND id = #{id} )
|
||||
ORDER BY
|
||||
sort
|
||||
LIMIT 1
|
||||
""")
|
||||
if(top){
|
||||
db.update("""
|
||||
update sys_office set sort = #{top.sort} where id = #{id}
|
||||
""")
|
||||
db.update("""
|
||||
update sys_office set sort = #{sort} where id = #{top.id}
|
||||
""")
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "03c2c9614e5b47f48f61f4f7759fe353",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "保存",
|
||||
"createTime" : null,
|
||||
"updateTime" : 1647615397163,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/save",
|
||||
"method" : "POST",
|
||||
"parameters" : [ ],
|
||||
"options" : [ {
|
||||
"name" : "wrap_request_parameter",
|
||||
"value" : "data",
|
||||
"description" : "包装请求参数到一个变量中",
|
||||
"required" : false,
|
||||
"dataType" : "String",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : null,
|
||||
"error" : null,
|
||||
"expression" : null,
|
||||
"children" : null
|
||||
}, {
|
||||
"name" : "permission",
|
||||
"value" : "office:save",
|
||||
"description" : "允许拥有该权限的访问",
|
||||
"required" : false,
|
||||
"dataType" : "String",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : null,
|
||||
"error" : null,
|
||||
"expression" : null,
|
||||
"children" : null
|
||||
} ],
|
||||
"requestBody" : "{}",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : null,
|
||||
"description" : null,
|
||||
"requestBodyDefinition" : {
|
||||
"name" : "",
|
||||
"value" : "",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
},
|
||||
"responseBodyDefinition" : null
|
||||
}
|
||||
================================
|
||||
var codeCount = db.selectInt("select count(1) from sys_office where is_del = 0 and code = #{code} ?{id, and id != #{id}}")
|
||||
if(codeCount > 0){
|
||||
exit 0,'机构编码已存在'
|
||||
}
|
||||
return db.table("sys_office").primary("id").saveOrUpdate(data);
|
||||
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "f7fa03a5d8b64dbaa39387c185a21adb",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "列表",
|
||||
"createTime" : 1646490239494,
|
||||
"updateTime" : 1645694064991,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/tree",
|
||||
"method" : "GET",
|
||||
"parameters" : [ ],
|
||||
"options" : [ {
|
||||
"name" : "permission",
|
||||
"value" : "office:view",
|
||||
"description" : "允许拥有该权限的访问",
|
||||
"required" : false,
|
||||
"dataType" : "String",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : null,
|
||||
"error" : null,
|
||||
"expression" : null,
|
||||
"children" : null
|
||||
} ],
|
||||
"requestBody" : "{\n\n}",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : "{\n \"code\": 402,\n \"message\": \"凭证已过期\",\n \"data\": null,\n \"timestamp\": 1645694060610,\n \"executeTime\": null\n}",
|
||||
"description" : null,
|
||||
"requestBodyDefinition" : null,
|
||||
"responseBodyDefinition" : {
|
||||
"name" : "",
|
||||
"value" : "",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ {
|
||||
"name" : "code",
|
||||
"value" : "402",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Integer",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "message",
|
||||
"value" : "凭证已过期",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "String",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "data",
|
||||
"value" : "null",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "timestamp",
|
||||
"value" : "1645694060610",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Long",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "executeTime",
|
||||
"value" : "null",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
} ]
|
||||
}
|
||||
}
|
||||
================================
|
||||
var toTree = (list,pid) => select t.*,toTree(list,t.id) children from list t where t.pid = pid
|
||||
var list = toTree(db.select('select id,name,pid,type,sort,code from sys_office where is_del = 0 order by sort'),'0')
|
||||
|
||||
return {
|
||||
list: list,
|
||||
total: list.getLength()
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "4f2140a0d177450da2f27e4569afb7b8",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "删除",
|
||||
"createTime" : null,
|
||||
"updateTime" : 1647615807925,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/delete",
|
||||
"method" : "DELETE",
|
||||
"parameters" : [ ],
|
||||
"options" : [ {
|
||||
"name" : "permission",
|
||||
"value" : "office:delete",
|
||||
"description" : "允许拥有该权限的访问",
|
||||
"required" : false,
|
||||
"dataType" : "String",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : null,
|
||||
"error" : null,
|
||||
"expression" : null,
|
||||
"children" : null
|
||||
} ],
|
||||
"requestBody" : "{\n\n}",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": null,\n \"timestamp\": 1641201245421,\n \"executeTime\": 7\n}",
|
||||
"description" : null,
|
||||
"requestBodyDefinition" : {
|
||||
"name" : "",
|
||||
"value" : "",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
},
|
||||
"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" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "timestamp",
|
||||
"value" : "1641201245421",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Long",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "executeTime",
|
||||
"value" : "7",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Integer",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
} ]
|
||||
}
|
||||
}
|
||||
================================
|
||||
var pCount = db.selectInt("select count(1) from sys_office where is_del = 0 and pid = #{id}")
|
||||
if(pCount > 0){
|
||||
exit 500,'存在下级机构,不允许删除'
|
||||
}
|
||||
var userCount = db.selectInt("select count(1) from sys_user where is_del = 0 and office_id = #{id}")
|
||||
if(userCount > 0){
|
||||
exit 500, '机构存在用户,不允许删除'
|
||||
}
|
||||
var root = db.selectValue("select pid from sys_office where is_del = 0 and id = #{id}")
|
||||
if(root == '0'){
|
||||
exit 500, '不能删除根节点'
|
||||
}
|
||||
// db.table('sys_user_office').where().eq("office_id",id).delete();
|
||||
return db.table("sys_office").logic().where().eq("id",id).delete();
|
||||
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "dd6fd96602cb4905b5c2d79f584ab0a0",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "根据角色获取组织机构",
|
||||
"createTime" : 1646490239498,
|
||||
"updateTime" : 1642080922495,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/by/role",
|
||||
"method" : "GET",
|
||||
"parameters" : [ ],
|
||||
"options" : [ ],
|
||||
"requestBody" : "",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [],\n \"timestamp\": 1642080916671,\n \"executeTime\": 90\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" : "",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Array",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "timestamp",
|
||||
"value" : "1642080916671",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Long",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
}, {
|
||||
"name" : "executeTime",
|
||||
"value" : "90",
|
||||
"description" : "",
|
||||
"required" : false,
|
||||
"dataType" : "Object",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : "",
|
||||
"error" : "",
|
||||
"expression" : "",
|
||||
"children" : [ ]
|
||||
} ]
|
||||
}
|
||||
}
|
||||
================================
|
||||
return db.select("""
|
||||
select office_id id from sys_role_office where role_id = #{roleId}
|
||||
""").map(it => it.id)
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"properties" : { },
|
||||
"id" : "f6e998eaff2c49be807fcb38a1a7d55b",
|
||||
"script" : null,
|
||||
"groupId" : "8295fc13678d4144bf7363c465247a50",
|
||||
"name" : "获取排序号",
|
||||
"createTime" : 1646490239501,
|
||||
"updateTime" : 1641732159522,
|
||||
"lock" : "0",
|
||||
"createBy" : null,
|
||||
"updateBy" : null,
|
||||
"path" : "/sort",
|
||||
"method" : "GET",
|
||||
"parameters" : [ {
|
||||
"name" : "pid",
|
||||
"value" : "",
|
||||
"description" : "",
|
||||
"required" : true,
|
||||
"dataType" : "String",
|
||||
"type" : null,
|
||||
"defaultValue" : null,
|
||||
"validateType" : null,
|
||||
"error" : null,
|
||||
"expression" : null,
|
||||
"children" : null
|
||||
} ],
|
||||
"options" : [ ],
|
||||
"requestBody" : "",
|
||||
"headers" : [ ],
|
||||
"paths" : [ ],
|
||||
"responseBody" : null,
|
||||
"description" : null,
|
||||
"requestBodyDefinition" : null,
|
||||
"responseBodyDefinition" : null
|
||||
}
|
||||
================================
|
||||
return db.selectInt("""
|
||||
select max(sort) + 10 from sys_office where pid = #{pid} and is_del = '0'
|
||||
""") || 10;
|
||||
Reference in New Issue
Block a user