From bbb1c5ccc7e5cd96c88457d13a515940da66eee2 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, 4 Jan 2022 14:56:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90code=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/magic-api/api/后台/安全/登录.ms | 24 +- .../api/后台/安全/获取当前用户权限code.ms | 16 +- data/magic-api/api/后台/用户管理/保存.ms | 9 +- data/magic-api/api/后台/用户管理/删除.ms | 5 +- data/magic-api/api/后台/菜单管理/保存.ms | 12 +- data/magic-api/api/后台/菜单管理/删除.ms | 101 ++++- .../api/后台/菜单管理/当前用户菜单.ms | 385 +++++++++++++++++- .../api/后台/菜单管理/根据菜单id清除缓存.ms | 32 ++ data/magic-api/api/后台/角色管理/保存.ms | 6 +- data/magic-api/api/后台/角色管理/删除.ms | 11 +- .../api/后台/角色管理/根据角色id删除缓存.ms | 30 ++ magic-boot/pom.xml | 2 +- .../interceptor/PermissionInterceptor.java | 2 +- 13 files changed, 580 insertions(+), 55 deletions(-) create mode 100644 data/magic-api/api/后台/菜单管理/根据菜单id清除缓存.ms create mode 100644 data/magic-api/api/后台/角色管理/根据角色id删除缓存.ms diff --git a/data/magic-api/api/后台/安全/登录.ms b/data/magic-api/api/后台/安全/登录.ms index ca94fd3..0ccce94 100644 --- a/data/magic-api/api/后台/安全/登录.ms +++ b/data/magic-api/api/后台/安全/登录.ms @@ -5,19 +5,19 @@ "groupId" : "1952f25c81084e24b55b11385767dc38", "name" : "登录", "createTime" : null, - "updateTime" : 1641016807364, + "updateTime" : 1641276726183, "lock" : "0", "method" : "POST", "path" : "/login", "parameters" : [ ], "option" : "[{\"name\":\"require_login\",\"value\":\"false\",\"description\":\"该接口需要登录才允许访问\"}]", - "requestBody" : "{\r\n \"username\": \"admin\",\r\n \"password\": \"1\"\r\n}", + "requestBody" : "{\r\n \"username\": \"test\",\r\n \"password\": \"1\"\r\n}", "headers" : [ ], "paths" : [ ], - "responseBody" : "{\n \"code\": 500,\n \"message\": \"系统内部出现错误\",\n \"data\": null,\n \"timestamp\": 1634225636093,\n \"executeTime\": 9174\n}", + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": \"565504aa-ecfa-4c0d-a22f-d35732672708\",\n \"timestamp\": 1641276642379,\n \"executeTime\": 13\n}", "description" : null, "requestBodyDefinition" : { - "name" : "root", + "name" : "", "value" : "", "description" : "", "required" : false, @@ -29,9 +29,9 @@ "expression" : "", "children" : [ { "name" : "username", - "value" : "admin", + "value" : "test", "description" : "", - "required" : true, + "required" : false, "dataType" : "String", "type" : null, "defaultValue" : null, @@ -43,7 +43,7 @@ "name" : "password", "value" : "1", "description" : "", - "required" : true, + "required" : false, "dataType" : "String", "type" : null, "defaultValue" : null, @@ -66,7 +66,7 @@ "expression" : "", "children" : [ { "name" : "code", - "value" : "500", + "value" : "200", "description" : "", "required" : false, "dataType" : "Integer", @@ -78,7 +78,7 @@ "children" : [ ] }, { "name" : "message", - "value" : "系统内部出现错误", + "value" : "success", "description" : "", "required" : false, "dataType" : "String", @@ -90,7 +90,7 @@ "children" : [ ] }, { "name" : "data", - "value" : "null", + "value" : "565504aa-ecfa-4c0d-a22f-d35732672708", "description" : "", "required" : false, "dataType" : "Object", @@ -102,7 +102,7 @@ "children" : [ ] }, { "name" : "timestamp", - "value" : "1634225636093", + "value" : "1641276642379", "description" : "", "required" : false, "dataType" : "Long", @@ -114,7 +114,7 @@ "children" : [ ] }, { "name" : "executeTime", - "value" : "9174", + "value" : "13", "description" : "", "required" : false, "dataType" : "Integer", diff --git a/data/magic-api/api/后台/安全/获取当前用户权限code.ms b/data/magic-api/api/后台/安全/获取当前用户权限code.ms index f1b1b80..4db1a26 100644 --- a/data/magic-api/api/后台/安全/获取当前用户权限code.ms +++ b/data/magic-api/api/后台/安全/获取当前用户权限code.ms @@ -4,8 +4,8 @@ "script" : null, "groupId" : "1952f25c81084e24b55b11385767dc38", "name" : "获取当前用户权限code", - "createTime" : 1634724871163, - "updateTime" : 1634724871163, + "createTime" : null, + "updateTime" : 1641276424757, "lock" : "0", "method" : "POST", "path" : "/permissions", @@ -14,7 +14,7 @@ "requestBody" : "{\r\n\t\r\n}", "headers" : [ ], "paths" : [ ], - "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [\n \"role:view\",\n \"role:save\",\n \"role:delete\",\n \"menu:delete\",\n \"office:office:list\",\n \"office:office:save\",\n \"office:office:delete\",\n \"dict:items:delete\",\n \"sys:test:aaa\",\n \"dict:delete\",\n \"dict:items\",\n \"dict:save\",\n \"user:save\",\n \"dict:view\",\n \"user:delete\",\n \"menu:save\",\n \"dict:items:save\"\n ],\n \"timestamp\": 1634092982336,\n \"executeTime\": 25\n}", + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [\"sys:test:aaa\", \"menu:save\", \"menu:delete\", \"office:office:list\", \"office:office:save\", \"office:office:delete\", \"role:view\", \"role:save\", \"role:delete\", \"user:save\", \"user:delete\", \"dict:view\", \"dict:save\", \"dict:delete\", \"dict:items\", \"dict:items:save\", \"dict:items:delete\"],\n \"timestamp\": 1641199273283,\n \"executeTime\": 1\n}", "description" : null, "requestBodyDefinition" : null, "responseBodyDefinition" : { @@ -65,7 +65,7 @@ "expression" : "", "children" : [ { "name" : "", - "value" : "role:view", + "value" : "sys:test:aaa", "description" : "", "required" : false, "dataType" : "String", @@ -78,7 +78,7 @@ } ] }, { "name" : "timestamp", - "value" : "1634092982336", + "value" : "1641199273283", "description" : "", "required" : false, "dataType" : "Long", @@ -90,10 +90,10 @@ "children" : [ ] }, { "name" : "executeTime", - "value" : "25", + "value" : "1", "description" : "", "required" : false, - "dataType" : "Integer", + "dataType" : "Object", "type" : null, "defaultValue" : null, "validateType" : "", @@ -110,7 +110,7 @@ import 'cn.dev33.satoken.stp.StpUtil'; var userId = StpUtil.getLoginId() -return db.select(""" +return db.cache(`permissions:${userId}`).select(""" SELECT DISTINCT sm.permission FROM diff --git a/data/magic-api/api/后台/用户管理/保存.ms b/data/magic-api/api/后台/用户管理/保存.ms index 7ed88e3..b7c75e3 100644 --- a/data/magic-api/api/后台/用户管理/保存.ms +++ b/data/magic-api/api/后台/用户管理/保存.ms @@ -5,7 +5,7 @@ "groupId" : "4f0230049d7e4f39b1e0897cc0f46f9a", "name" : "保存", "createTime" : null, - "updateTime" : 1634730816739, + "updateTime" : 1641261914841, "lock" : "0", "method" : "POST", "path" : "/save", @@ -22,21 +22,24 @@ } ================================ import 'cn.dev33.satoken.secure.SaSecureUtil'; +import org.ssssssss.magicapi.cache.SqlCache +password = password ? SaSecureUtil.sha256(password) : '' var user = { id, name, username, - password: SaSecureUtil.sha256(password), + password: password, phone, isLogin } if(id){ + SqlCache.delete(`permissions:${id}`) db.update(""" delete from sys_user_role where user_id = #{id} """) } id = db.table("sys_user").primary("id").saveOrUpdate(user) for(roleId in roles.split(',')){ - db.table("sys_user_role").column('userId', id).column("roleId", roleId).insert() + db.table("sys_user_role").column('user_id', id).column("role_id", roleId).insert() } \ No newline at end of file diff --git a/data/magic-api/api/后台/用户管理/删除.ms b/data/magic-api/api/后台/用户管理/删除.ms index 2909ad2..decdc07 100644 --- a/data/magic-api/api/后台/用户管理/删除.ms +++ b/data/magic-api/api/后台/用户管理/删除.ms @@ -5,7 +5,7 @@ "groupId" : "4f0230049d7e4f39b1e0897cc0f46f9a", "name" : "删除", "createTime" : null, - "updateTime" : 1634731401903, + "updateTime" : 1641218486141, "lock" : "0", "method" : "POST", "path" : "/delete", @@ -21,7 +21,10 @@ "optionMap" : { } } ================================ +import org.ssssssss.magicapi.cache.SqlCache + for(userId in id.split(',')){ + SqlCache.delete(`permissions:${userId}`) db.table("sys_user").logic().where().eq("id",userId).delete(); } return true \ No newline at end of file diff --git a/data/magic-api/api/后台/菜单管理/保存.ms b/data/magic-api/api/后台/菜单管理/保存.ms index 046beff..8791149 100644 --- a/data/magic-api/api/后台/菜单管理/保存.ms +++ b/data/magic-api/api/后台/菜单管理/保存.ms @@ -4,8 +4,8 @@ "script" : null, "groupId" : "67b2ce258e24491194b74992958c74aa", "name" : "保存", - "createTime" : 1634724871170, - "updateTime" : 1634724871170, + "createTime" : null, + "updateTime" : 1641219427227, "lock" : "0", "method" : "POST", "path" : "/save", @@ -23,4 +23,12 @@ } } ================================ +import org.ssssssss.magicapi.cache.SqlCache; +import '@get:/menu/cache/delete' as cacheDelete; + +SqlCache.delete('permissions:1') +if(data.id){ + var menuId = data.id + cacheDelete(); +} return db.table("sys_menu").primary("id").saveOrUpdate(data); \ No newline at end of file diff --git a/data/magic-api/api/后台/菜单管理/删除.ms b/data/magic-api/api/后台/菜单管理/删除.ms index 31c4852..606447a 100644 --- a/data/magic-api/api/后台/菜单管理/删除.ms +++ b/data/magic-api/api/后台/菜单管理/删除.ms @@ -4,21 +4,110 @@ "script" : null, "groupId" : "67b2ce258e24491194b74992958c74aa", "name" : "删除", - "createTime" : 1634724871164, - "updateTime" : 1634724871164, + "createTime" : null, + "updateTime" : 1641276678116, "lock" : "0", "method" : "POST", "path" : "/delete", - "parameters" : [ ], + "parameters" : [ { + "name" : "id", + "value" : "b1851d1b13594e71840103c11a37a669", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : null, + "error" : null, + "expression" : null, + "children" : null + } ], "option" : "[]", - "requestBody" : "", + "requestBody" : "{\r\n\t\r\n}", "headers" : [ ], "paths" : [ ], - "responseBody" : null, + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": null,\n \"timestamp\": 1641201245421,\n \"executeTime\": 7\n}", "description" : null, "requestBodyDefinition" : null, - "responseBodyDefinition" : 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" : "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" : [ ] + } ] + }, "optionMap" : { } } ================================ +import '@get:/menu/cache/delete' as cacheDelete; +var menuId = id +cacheDelete(); + +db.table('sys_role_menu').where().eq("menu_id",id).delete(); return db.table("sys_menu").logic().where().eq("id",id).delete(); \ No newline at end of file diff --git a/data/magic-api/api/后台/菜单管理/当前用户菜单.ms b/data/magic-api/api/后台/菜单管理/当前用户菜单.ms index c7fee56..2e0dc77 100644 --- a/data/magic-api/api/后台/菜单管理/当前用户菜单.ms +++ b/data/magic-api/api/后台/菜单管理/当前用户菜单.ms @@ -5,16 +5,16 @@ "groupId" : "67b2ce258e24491194b74992958c74aa", "name" : "当前用户菜单", "createTime" : null, - "updateTime" : 1641016811595, + "updateTime" : 1641279378685, "lock" : "0", "method" : "POST", "path" : "/current/menus", "parameters" : [ ], "option" : "[]", - "requestBody" : "", + "requestBody" : "{\n\n}", "headers" : [ ], "paths" : [ ], - "responseBody" : "{\n \"code\": 402,\n \"message\": \"凭证已过期\",\n \"data\": null,\n \"timestamp\": 1641016803295,\n \"executeTime\": null\n}", + "responseBody" : "{\n \"code\": 200,\n \"message\": \"success\",\n \"data\": [{\n \"id\": \"b1851d1b13594e71840103c11a37a669\",\n \"name\": \"系统设置\",\n \"pid\": \"0\",\n \"isShow\": 1,\n \"url\": \"/system\",\n \"sort\": 10,\n \"icon\": \"settings\",\n \"component\": \"Layout\",\n \"path\": \"/system\",\n \"meta\": {\n \"title\": \"系统设置\",\n \"icon\": \"settings\"\n },\n \"redirect\": \"noRedirect\",\n \"alwaysShow\": true,\n \"children\": [{\n \"id\": \"39be13ef6f0745568c80bf35202ddb2b\",\n \"name\": \"菜单管理\",\n \"pid\": \"b1851d1b13594e71840103c11a37a669\",\n \"isShow\": 1,\n \"url\": \"/system/menu/menu-list\",\n \"sort\": 10,\n \"icon\": \"menu\",\n \"component\": \"/system/menu/menu-list\",\n \"path\": \"/system/menu/menu-list\",\n \"meta\": {\n \"title\": \"菜单管理\",\n \"icon\": \"menu\"\n }\n }, {\n \"id\": \"8e9455740091486c914495cfb0c7faa5\",\n \"name\": \"角色管理\",\n \"pid\": \"b1851d1b13594e71840103c11a37a669\",\n \"isShow\": 1,\n \"url\": \"/system/role/role-list\",\n \"sort\": 40,\n \"icon\": \"role\",\n \"component\": \"/system/role/role-list\",\n \"path\": \"/system/role/role-list\",\n \"meta\": {\n \"title\": \"角色管理\",\n \"icon\": \"role\"\n }\n }, {\n \"id\": \"06b8a427e4cd4c1ba11752070f565f20\",\n \"name\": \"用户管理\",\n \"pid\": \"b1851d1b13594e71840103c11a37a669\",\n \"isShow\": 1,\n \"url\": \"/system/user/user-list\",\n \"sort\": 50,\n \"icon\": \"user\",\n \"component\": \"/system/user/user-list\",\n \"path\": \"/system/user/user-list\",\n \"meta\": {\n \"title\": \"用户管理\",\n \"icon\": \"user\"\n }\n }, {\n \"id\": \"c5f407478c4e4c9cbcdbee6389d2c909\",\n \"name\": \"数据字典\",\n \"pid\": \"b1851d1b13594e71840103c11a37a669\",\n \"isShow\": 1,\n \"url\": \"/system/dict/dict-list\",\n \"sort\": 60,\n \"icon\": \"dict\",\n \"component\": \"/system/dict/dict-list\",\n \"path\": \"/system/dict/dict-list\",\n \"meta\": {\n \"title\": \"数据字典\",\n \"icon\": \"dict\"\n }\n }]\n }, {\n \"id\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"name\": \"一些例子\",\n \"pid\": \"0\",\n \"isShow\": 1,\n \"url\": \"/examples\",\n \"sort\": 20,\n \"icon\": \"examples\",\n \"component\": \"Layout\",\n \"path\": \"/examples\",\n \"meta\": {\n \"title\": \"一些例子\",\n \"icon\": \"examples\"\n },\n \"redirect\": \"noRedirect\",\n \"alwaysShow\": true,\n \"children\": [{\n \"id\": \"dc332875-831e-4937-86ff-0c7420915ce9\",\n \"name\": \"三级联动\",\n \"pid\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"isShow\": 1,\n \"url\": \"/examples/three-linkage\",\n \"sort\": 10,\n \"icon\": \"\",\n \"component\": \"/examples/three-linkage\",\n \"path\": \"/examples/three-linkage\",\n \"meta\": {\n \"title\": \"三级联动\",\n \"icon\": \"\"\n }\n }, {\n \"id\": \"f09410d5-5043-4164-9f68-8d135de71b29\",\n \"name\": \"上传文件\",\n \"pid\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"isShow\": 1,\n \"url\": \"/examples/upload-file\",\n \"sort\": 20,\n \"icon\": \"\",\n \"component\": \"/examples/upload-file\",\n \"path\": \"/examples/upload-file\",\n \"meta\": {\n \"title\": \"上传文件\",\n \"icon\": \"\"\n }\n }, {\n \"id\": \"74c852ea-be4b-4533-b146-cfbd776045d5\",\n \"name\": \"富文本\",\n \"pid\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"isShow\": 1,\n \"url\": \"/examples/ueditor-example\",\n \"sort\": 30,\n \"icon\": \"\",\n \"component\": \"/examples/ueditor-example\",\n \"path\": \"/examples/ueditor-example\",\n \"meta\": {\n \"title\": \"富文本\",\n \"icon\": \"\"\n }\n }, {\n \"id\": \"91bdb7d742a64a8c8a8fdc6d3bb61581\",\n \"name\": \"可编辑表格\",\n \"pid\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"isShow\": 1,\n \"url\": \"/examples/editor-table\",\n \"sort\": 40,\n \"icon\": \"\",\n \"component\": \"/examples/editor-table\",\n \"path\": \"/examples/editor-table\",\n \"meta\": {\n \"title\": \"可编辑表格\",\n \"icon\": \"\"\n }\n }, {\n \"id\": \"0ca23f378d794b23b935d6045bb54915\",\n \"name\": \"页面设计\",\n \"pid\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"isShow\": 1,\n \"url\": \"/examples/page-design\",\n \"sort\": 50,\n \"icon\": \"\",\n \"component\": \"/examples/page-design\",\n \"path\": \"/examples/page-design\",\n \"meta\": {\n \"title\": \"页面设计\",\n \"icon\": \"\"\n }\n }, {\n \"id\": \"2664b76cb2904227bce5b0f7d1dd6e7b\",\n \"name\": \"下拉框\",\n \"pid\": \"641253af-8ea1-4b5d-8bc3-a7165ef60ff2\",\n \"isShow\": 1,\n \"url\": \"/examples/select-example\",\n \"sort\": 60,\n \"icon\": \"\",\n \"component\": \"/examples/select-example\",\n \"path\": \"/examples/select-example\",\n \"meta\": {\n \"title\": \"下拉框\",\n \"icon\": \"\"\n }\n }]\n }, {\n \"id\": \"f481f745ef8f40deae861b57390f9130\",\n \"name\": \"测试\",\n \"pid\": \"0\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 30,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"测试\",\n \"icon\": null\n },\n \"redirect\": \"noRedirect\",\n \"alwaysShow\": true,\n \"children\": [{\n \"id\": \"2c0dfae696b84994981461231dd82599\",\n \"name\": \"1\",\n \"pid\": \"f481f745ef8f40deae861b57390f9130\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 40,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"1\",\n \"icon\": null\n },\n \"redirect\": \"noRedirect\",\n \"alwaysShow\": true,\n \"children\": [{\n \"id\": \"def5a6402307471498447e17e48daf32\",\n \"name\": \"1-1\",\n \"pid\": \"2c0dfae696b84994981461231dd82599\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 10,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"1-1\",\n \"icon\": null\n },\n \"redirect\": \"noRedirect\",\n \"alwaysShow\": true,\n \"children\": [{\n \"id\": \"dc2fc72b7b584cb4a1027a9abcce4269\",\n \"name\": \"1-1-1\",\n \"pid\": \"def5a6402307471498447e17e48daf32\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 10,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"1-1-1\",\n \"icon\": null\n },\n \"redirect\": \"noRedirect\",\n \"alwaysShow\": true,\n \"children\": [{\n \"id\": \"740eb175bb004427a91deecfe6551c78\",\n \"name\": \"1-1-1-1\",\n \"pid\": \"dc2fc72b7b584cb4a1027a9abcce4269\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 10,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"1-1-1-1\",\n \"icon\": null\n }\n }]\n }, {\n \"id\": \"4bf506637f094a38903345c906ca13f9\",\n \"name\": \"1-1-2\",\n \"pid\": \"def5a6402307471498447e17e48daf32\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 20,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"1-1-2\",\n \"icon\": null\n }\n }]\n }, {\n \"id\": \"3922bbc556b64e08b2caf77ee5690f1a\",\n \"name\": \"1-2\",\n \"pid\": \"2c0dfae696b84994981461231dd82599\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 30,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"1-2\",\n \"icon\": null\n }\n }]\n }, {\n \"id\": \"eb2f8b86ad994986862a705168da875b\",\n \"name\": \"测试2\",\n \"pid\": \"f481f745ef8f40deae861b57390f9130\",\n \"isShow\": 1,\n \"url\": null,\n \"sort\": 40,\n \"icon\": null,\n \"component\": \"Layout\",\n \"path\": \"/\",\n \"meta\": {\n \"title\": \"测试2\",\n \"icon\": null\n }\n }]\n }],\n \"timestamp\": 1641276761756,\n \"executeTime\": 7\n}", "description" : null, "requestBodyDefinition" : null, "responseBodyDefinition" : { @@ -30,7 +30,7 @@ "expression" : "", "children" : [ { "name" : "code", - "value" : "402", + "value" : "200", "description" : "", "required" : false, "dataType" : "Integer", @@ -42,7 +42,7 @@ "children" : [ ] }, { "name" : "message", - "value" : "凭证已过期", + "value" : "success", "description" : "", "required" : false, "dataType" : "String", @@ -54,19 +54,367 @@ "children" : [ ] }, { "name" : "data", - "value" : "null", + "value" : "", "description" : "", "required" : false, - "dataType" : "Object", + "dataType" : "Array", "type" : null, "defaultValue" : null, "validateType" : "", "error" : "", "expression" : "", - "children" : [ ] + "children" : [ { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "id", + "value" : "b1851d1b13594e71840103c11a37a669", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "name", + "value" : "系统设置", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "pid", + "value" : "0", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "isShow", + "value" : "1", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "url", + "value" : "/system", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "sort", + "value" : "10", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "icon", + "value" : "settings", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "component", + "value" : "Layout", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "path", + "value" : "/system", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "meta", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "title", + "value" : "系统设置", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "icon", + "value" : "settings", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + }, { + "name" : "redirect", + "value" : "noRedirect", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "alwaysShow", + "value" : "true", + "description" : "", + "required" : false, + "dataType" : "Boolean", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "children", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Array", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "id", + "value" : "39be13ef6f0745568c80bf35202ddb2b", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "name", + "value" : "菜单管理", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "pid", + "value" : "b1851d1b13594e71840103c11a37a669", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "isShow", + "value" : "1", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "url", + "value" : "/system/menu/menu-list", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "sort", + "value" : "10", + "description" : "", + "required" : false, + "dataType" : "Integer", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "icon", + "value" : "menu", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "component", + "value" : "/system/menu/menu-list", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "path", + "value" : "/system/menu/menu-list", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "meta", + "value" : "", + "description" : "", + "required" : false, + "dataType" : "Object", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ { + "name" : "title", + "value" : "菜单管理", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + }, { + "name" : "icon", + "value" : "menu", + "description" : "", + "required" : false, + "dataType" : "String", + "type" : null, + "defaultValue" : null, + "validateType" : "", + "error" : "", + "expression" : "", + "children" : [ ] + } ] + } ] + } ] + } ] + } ] }, { "name" : "timestamp", - "value" : "1641016803295", + "value" : "1641276761756", "description" : "", "required" : false, "dataType" : "Long", @@ -78,7 +426,7 @@ "children" : [ ] }, { "name" : "executeTime", - "value" : "null", + "value" : "7", "description" : "", "required" : false, "dataType" : "Object", @@ -96,8 +444,9 @@ import 'cn.dev33.satoken.stp.StpUtil'; var userId = StpUtil.getLoginId() + var menus = db.select(""" - SELECT DISTINCT + select sm.id, sm.name, sm.pid, @@ -105,12 +454,14 @@ var menus = db.select(""" sm.url, sm.sort, sm.icon - FROM - sys_menu sm - left JOIN sys_role_menu srm ON sm.id = srm.menu_id - left JOIN sys_user_role sur ON sur.role_id = srm.role_id - left JOIN sys_user su ON su.id = sur.user_id - ?{userId != '1', AND su.id = #{userId}} and su.is_del = 0 where sm.is_del = 0 and sm.is_show = 1 order by sort + from sys_menu sm where 1=1 + ?{userId != '1', + and sm.id in ( + select menu_id from sys_role_menu where role_id in ( + select role_id from sys_user_role where user_id = #{userId} + ) + ) + } and sm.is_del = '0' and sm.is_show = 1 order by sm.sort """) for(menu in menus){ diff --git a/data/magic-api/api/后台/菜单管理/根据菜单id清除缓存.ms b/data/magic-api/api/后台/菜单管理/根据菜单id清除缓存.ms new file mode 100644 index 0000000..17405ff --- /dev/null +++ b/data/magic-api/api/后台/菜单管理/根据菜单id清除缓存.ms @@ -0,0 +1,32 @@ +{ + "properties" : { }, + "id" : "96336e6177d143c1a2259685f71cd615", + "script" : null, + "groupId" : "67b2ce258e24491194b74992958c74aa", + "name" : "根据菜单id清除缓存", + "createTime" : null, + "updateTime" : 1641218495832, + "lock" : "0", + "method" : "GET", + "path" : "/cache/delete", + "parameters" : [ ], + "option" : "[]", + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : null, + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : null, + "optionMap" : { } +} +================================ +import org.ssssssss.magicapi.cache.SqlCache +var userIds = db.select(""" + select user_id from sys_user_role where role_id in ( + select role_id from sys_role_menu where menu_id = #{menuId} + ) and user_id is not null +""") +for(item in userIds){ + SqlCache.delete(`permissions:${item.userId}`) +} \ No newline at end of file diff --git a/data/magic-api/api/后台/角色管理/保存.ms b/data/magic-api/api/后台/角色管理/保存.ms index e2193fc..1696f53 100644 --- a/data/magic-api/api/后台/角色管理/保存.ms +++ b/data/magic-api/api/后台/角色管理/保存.ms @@ -5,7 +5,7 @@ "groupId" : "89130d496f6f467c88b22ae4a7f688eb", "name" : "保存", "createTime" : null, - "updateTime" : 1634730841303, + "updateTime" : 1641215973180, "lock" : "0", "method" : "POST", "path" : "/save", @@ -23,6 +23,8 @@ } } ================================ +import '@get:/role/cache/delete' as cacheDelete + var role = { type, name, @@ -30,6 +32,8 @@ var role = { id } if(id){ + var roleId = id + cacheDelete() db.table("sys_role_menu").where().eq("role_id",id).delete() } id = db.table("sys_role").primary("id").saveOrUpdate(role); diff --git a/data/magic-api/api/后台/角色管理/删除.ms b/data/magic-api/api/后台/角色管理/删除.ms index 9169819..c3f2537 100644 --- a/data/magic-api/api/后台/角色管理/删除.ms +++ b/data/magic-api/api/后台/角色管理/删除.ms @@ -4,14 +4,14 @@ "script" : null, "groupId" : "89130d496f6f467c88b22ae4a7f688eb", "name" : "删除", - "createTime" : 1634724871175, - "updateTime" : 1634724871175, + "createTime" : null, + "updateTime" : 1641276685001, "lock" : "0", "method" : "POST", "path" : "/delete", "parameters" : [ ], "option" : "[]", - "requestBody" : "", + "requestBody" : "{\r\n\t\r\n}", "headers" : [ ], "paths" : [ ], "responseBody" : null, @@ -21,4 +21,9 @@ "optionMap" : { } } ================================ +import '@get:/role/cache/delete' as cacheDelete +var roleId = id +cacheDelete() + +db.table("sys_role_menu").where().eq("role_id",id).delete() return db.table("sys_role").logic().where().eq("id",id).delete(); \ No newline at end of file diff --git a/data/magic-api/api/后台/角色管理/根据角色id删除缓存.ms b/data/magic-api/api/后台/角色管理/根据角色id删除缓存.ms new file mode 100644 index 0000000..b6c0ae3 --- /dev/null +++ b/data/magic-api/api/后台/角色管理/根据角色id删除缓存.ms @@ -0,0 +1,30 @@ +{ + "properties" : { }, + "id" : "598efb2903ec4e0491fa99e8df0222f9", + "script" : null, + "groupId" : "89130d496f6f467c88b22ae4a7f688eb", + "name" : "根据角色id删除缓存", + "createTime" : null, + "updateTime" : 1641218346505, + "lock" : "0", + "method" : "GET", + "path" : "/cache/delete", + "parameters" : [ ], + "option" : "[]", + "requestBody" : "", + "headers" : [ ], + "paths" : [ ], + "responseBody" : null, + "description" : null, + "requestBodyDefinition" : null, + "responseBodyDefinition" : null, + "optionMap" : { } +} +================================ +import org.ssssssss.magicapi.cache.SqlCache +var userIds = db.select(""" + select user_id from sys_user_role where role_id = #{roleId} and user_id is not null +""") +for(item in userIds){ + SqlCache.delete(`permissions:${item.userId}`) +} \ No newline at end of file diff --git a/magic-boot/pom.xml b/magic-boot/pom.xml index 2662ea1..99474c9 100644 --- a/magic-boot/pom.xml +++ b/magic-boot/pom.xml @@ -14,7 +14,7 @@ magic-boot 1.8 - 1.7.2 + 1.7.4 1.2.1 5.7.13 1.26.0 diff --git a/magic-boot/src/main/java/org/ssssssss/magicboot/interceptor/PermissionInterceptor.java b/magic-boot/src/main/java/org/ssssssss/magicboot/interceptor/PermissionInterceptor.java index 9f1c083..7917fc1 100644 --- a/magic-boot/src/main/java/org/ssssssss/magicboot/interceptor/PermissionInterceptor.java +++ b/magic-boot/src/main/java/org/ssssssss/magicboot/interceptor/PermissionInterceptor.java @@ -46,4 +46,4 @@ public class PermissionInterceptor implements RequestInterceptor { return null; } -} \ No newline at end of file +}