权限code缓存

This commit is contained in:
吕金泽 2022-01-04 14:56:52 +08:00
parent 17d09d1d7f
commit bbb1c5ccc7
13 changed files with 580 additions and 55 deletions

View File

@ -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",

View File

@ -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

View File

@ -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()
}

View File

@ -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

View File

@ -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);

View File

@ -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();

File diff suppressed because one or more lines are too long

View File

@ -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}`)
}

View File

@ -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);

View File

@ -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();

View File

@ -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}`)
}

View File

@ -14,7 +14,7 @@
<description>magic-boot</description>
<properties>
<java.version>1.8</java.version>
<magic-api.version>1.7.2</magic-api.version>
<magic-api.version>1.7.4</magic-api.version>
<druid.version>1.2.1</druid.version>
<hutool-all.version>5.7.13</hutool-all.version>
<sa-token.version>1.26.0</sa-token.version>

View File

@ -46,4 +46,4 @@ public class PermissionInterceptor implements RequestInterceptor {
return null;
}
}
}