Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
zhu
dataease
Commits
31ba1baa
提交
31ba1baa
authored
5月 31, 2022
作者:
wangjiahao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 缓存清理注解改为异步处理,加快接口处理时间
上级
107afad0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
105 行增加
和
83 行删除
+105
-83
DeCleanerAnnotationHandler.java
...java/io/dataease/auth/aop/DeCleanerAnnotationHandler.java
+8
-83
DeCatchProcess.java
...main/java/io/dataease/service/decatch/DeCatchProcess.java
+97
-0
没有找到文件。
backend/src/main/java/io/dataease/auth/aop/DeCleanerAnnotationHandler.java
浏览文件 @
31ba1baa
package
io
.
dataease
.
auth
.
aop
;
import
io.dataease.auth.annotation.DeCleaner
;
import
io.dataease.auth.api.dto.CurrentUserDto
;
import
io.dataease.commons.constants.AuthConstants
;
import
io.dataease.commons.constants.DePermissionType
;
import
io.dataease.commons.model.AuthURD
;
import
io.dataease.commons.utils.AopUtils
;
import
io.dataease.commons.utils.
AuthUtils
;
import
io.dataease.commons.utils.
CommonBeanFactory
;
import
io.dataease.commons.utils.LogUtil
;
import
io.dataease.listener.util.CacheUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
io.dataease.service.decatch.DeCatchProcess
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
...
...
@@ -20,9 +15,6 @@ import org.aspectj.lang.reflect.MethodSignature;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Method
;
import
java.util.List
;
import
java.util.Optional
;
@Aspect
@Component
public
class
DeCleanerAnnotationHandler
{
...
...
@@ -43,15 +35,16 @@ public class DeCleanerAnnotationHandler {
paramValue
=
AopUtils
.
getParamValue
(
arg
,
key
,
0
);
}
switch
(
type
.
name
())
{
case
"DATASOURCE"
:
cleanDataSource
(
paramValue
);
c
atchProcess
().
c
leanDataSource
(
paramValue
);
break
;
case
"DATASET"
:
cleanDataSet
(
paramValue
);
c
atchProcess
().
c
leanDataSet
(
paramValue
);
break
;
default
:
cleanPanel
(
paramValue
);
c
atchProcess
().
c
leanPanel
(
paramValue
);
break
;
}
}
catch
(
Throwable
e
)
{
...
...
@@ -60,78 +53,10 @@ public class DeCleanerAnnotationHandler {
}
}
private
void
cleanCacheParent
(
String
pid
,
String
type
)
{
if
(
StringUtils
.
isBlank
(
pid
)
||
StringUtils
.
isBlank
(
type
))
{
return
;
}
CurrentUserDto
user
=
AuthUtils
.
getUser
();
List
<
String
>
resourceIds
=
AuthUtils
.
parentResources
(
pid
.
toString
(),
type
);
if
(
CollectionUtils
.
isEmpty
(
resourceIds
))
return
;
resourceIds
.
forEach
(
resourceId
->
{
AuthURD
authURD
=
AuthUtils
.
authURDR
(
resourceId
);
Optional
.
ofNullable
(
authURD
.
getUserIds
()).
ifPresent
(
ids
->
{
ids
.
forEach
(
id
->
{
CacheUtils
.
remove
(
"user_"
+
type
,
"user"
+
id
);
});
});
Optional
.
ofNullable
(
authURD
.
getRoleIds
()).
ifPresent
(
ids
->
{
ids
.
forEach
(
id
->
{
CacheUtils
.
remove
(
"role_"
+
type
,
"role"
+
id
);
});
});
Optional
.
ofNullable
(
authURD
.
getDeptIds
()).
ifPresent
(
ids
->
{
ids
.
forEach
(
id
->
{
List
<
String
>
depts
=
AuthUtils
.
getAuthModels
(
id
.
toString
(),
"dept"
,
user
.
getUserId
(),
user
.
getIsAdmin
());
depts
.
forEach
(
deptId
->
{
CacheUtils
.
remove
(
"dept_"
+
type
,
"dept"
+
deptId
);
});
});
});
});
public
DeCatchProcess
catchProcess
()
{
return
CommonBeanFactory
.
getBean
(
DeCatchProcess
.
class
);
}
public
void
cleanPanel
(
Object
pid
)
{
CurrentUserDto
user
=
AuthUtils
.
getUser
();
CacheUtils
.
remove
(
AuthConstants
.
USER_PANEL_NAME
,
"user"
+
user
.
getUserId
());
CacheUtils
.
remove
(
AuthConstants
.
DEPT_PANEL_NAME
,
"dept"
+
user
.
getDeptId
());
user
.
getRoles
().
forEach
(
role
->
{
CacheUtils
.
remove
(
AuthConstants
.
ROLE_PANEL_NAME
,
"role"
+
role
.
getId
());
});
Optional
.
ofNullable
(
pid
).
ifPresent
(
resourceId
->
{
cleanCacheParent
(
resourceId
.
toString
(),
"panel"
);
});
}
public
void
cleanDataSet
(
Object
pid
)
{
CurrentUserDto
user
=
AuthUtils
.
getUser
();
CacheUtils
.
remove
(
AuthConstants
.
USER_DATASET_NAME
,
"user"
+
user
.
getUserId
());
CacheUtils
.
remove
(
AuthConstants
.
DEPT_DATASET_NAME
,
"dept"
+
user
.
getDeptId
());
user
.
getRoles
().
forEach
(
role
->
{
CacheUtils
.
remove
(
AuthConstants
.
ROLE_DATASET_NAME
,
"role"
+
role
.
getId
());
});
Optional
.
ofNullable
(
pid
).
ifPresent
(
resourceId
->
{
cleanCacheParent
(
resourceId
.
toString
(),
"dataset"
);
});
}
public
void
cleanDataSource
(
Object
pid
)
{
CurrentUserDto
user
=
AuthUtils
.
getUser
();
CacheUtils
.
remove
(
AuthConstants
.
USER_LINK_NAME
,
"user"
+
user
.
getUserId
());
CacheUtils
.
remove
(
AuthConstants
.
DEPT_LINK_NAME
,
"dept"
+
user
.
getDeptId
());
user
.
getRoles
().
forEach
(
role
->
{
CacheUtils
.
remove
(
AuthConstants
.
ROLE_LINK_NAME
,
"role"
+
role
.
getId
());
});
Optional
.
ofNullable
(
pid
).
ifPresent
(
resourceId
->
{
cleanCacheParent
(
resourceId
.
toString
(),
"link"
);
});
}
}
backend/src/main/java/io/dataease/service/decatch/DeCatchProcess.java
0 → 100644
浏览文件 @
31ba1baa
package
io
.
dataease
.
service
.
decatch
;
import
io.dataease.auth.api.dto.CurrentUserDto
;
import
io.dataease.commons.constants.AuthConstants
;
import
io.dataease.commons.model.AuthURD
;
import
io.dataease.commons.utils.AuthUtils
;
import
io.dataease.listener.util.CacheUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Optional
;
/**
* Author: wangjiahao
* Date: 2022/5/31
* Description:
*/
@Service
public
class
DeCatchProcess
{
@Async
(
"taskExecutor"
)
public
void
cleanPanel
(
Object
pid
)
{
CurrentUserDto
user
=
AuthUtils
.
getUser
();
CacheUtils
.
remove
(
AuthConstants
.
USER_PANEL_NAME
,
"user"
+
user
.
getUserId
());
CacheUtils
.
remove
(
AuthConstants
.
DEPT_PANEL_NAME
,
"dept"
+
user
.
getDeptId
());
user
.
getRoles
().
forEach
(
role
->
{
CacheUtils
.
remove
(
AuthConstants
.
ROLE_PANEL_NAME
,
"role"
+
role
.
getId
());
});
Optional
.
ofNullable
(
pid
).
ifPresent
(
resourceId
->
{
cleanCacheParent
(
resourceId
.
toString
(),
"panel"
);
});
}
@Async
(
"taskExecutor"
)
public
void
cleanDataSet
(
Object
pid
)
{
CurrentUserDto
user
=
AuthUtils
.
getUser
();
CacheUtils
.
remove
(
AuthConstants
.
USER_DATASET_NAME
,
"user"
+
user
.
getUserId
());
CacheUtils
.
remove
(
AuthConstants
.
DEPT_DATASET_NAME
,
"dept"
+
user
.
getDeptId
());
user
.
getRoles
().
forEach
(
role
->
{
CacheUtils
.
remove
(
AuthConstants
.
ROLE_DATASET_NAME
,
"role"
+
role
.
getId
());
});
Optional
.
ofNullable
(
pid
).
ifPresent
(
resourceId
->
{
cleanCacheParent
(
resourceId
.
toString
(),
"dataset"
);
});
}
@Async
(
"taskExecutor"
)
public
void
cleanDataSource
(
Object
pid
)
{
CurrentUserDto
user
=
AuthUtils
.
getUser
();
CacheUtils
.
remove
(
AuthConstants
.
USER_LINK_NAME
,
"user"
+
user
.
getUserId
());
CacheUtils
.
remove
(
AuthConstants
.
DEPT_LINK_NAME
,
"dept"
+
user
.
getDeptId
());
user
.
getRoles
().
forEach
(
role
->
{
CacheUtils
.
remove
(
AuthConstants
.
ROLE_LINK_NAME
,
"role"
+
role
.
getId
());
});
Optional
.
ofNullable
(
pid
).
ifPresent
(
resourceId
->
{
cleanCacheParent
(
resourceId
.
toString
(),
"link"
);
});
}
private
void
cleanCacheParent
(
String
pid
,
String
type
)
{
if
(
StringUtils
.
isBlank
(
pid
)
||
StringUtils
.
isBlank
(
type
))
{
return
;
}
CurrentUserDto
user
=
AuthUtils
.
getUser
();
List
<
String
>
resourceIds
=
AuthUtils
.
parentResources
(
pid
.
toString
(),
type
);
if
(
CollectionUtils
.
isEmpty
(
resourceIds
))
return
;
resourceIds
.
forEach
(
resourceId
->
{
AuthURD
authURD
=
AuthUtils
.
authURDR
(
resourceId
);
Optional
.
ofNullable
(
authURD
.
getUserIds
()).
ifPresent
(
ids
->
{
ids
.
forEach
(
id
->
{
CacheUtils
.
remove
(
"user_"
+
type
,
"user"
+
id
);
});
});
Optional
.
ofNullable
(
authURD
.
getRoleIds
()).
ifPresent
(
ids
->
{
ids
.
forEach
(
id
->
{
CacheUtils
.
remove
(
"role_"
+
type
,
"role"
+
id
);
});
});
Optional
.
ofNullable
(
authURD
.
getDeptIds
()).
ifPresent
(
ids
->
{
ids
.
forEach
(
id
->
{
List
<
String
>
depts
=
AuthUtils
.
getAuthModels
(
id
.
toString
(),
"dept"
,
user
.
getUserId
(),
user
.
getIsAdmin
());
depts
.
forEach
(
deptId
->
{
CacheUtils
.
remove
(
"dept_"
+
type
,
"dept"
+
deptId
);
});
});
});
});
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论