Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
0ca247b8
Commit
0ca247b8
authored
Mar 26, 2024
by
chenzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改拦截器 兼容分页插件
parent
9685838f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
9 deletions
+59
-9
UserEmpowerInterceptor.java
...s/boot/module/hygf/api/config/UserEmpowerInterceptor.java
+59
-9
No files found.
amos-boot-system-jxiop/amos-boot-module-hygf-api/src/main/java/com/yeejoin/amos/boot/module/hygf/api/config/UserEmpowerInterceptor.java
View file @
0ca247b8
...
...
@@ -46,15 +46,30 @@ public class UserEmpowerInterceptor implements Interceptor {
try
{
if
(
null
==
redisUtils
){
return
invocation
.
proceed
();
}
StdUserEmpower
orgCode
=(
StdUserEmpower
)
redisUtils
.
get
(
"Emp_"
+
RedisKey
.
buildReginKey
(
RequestContext
.
getExeUserId
(),
RequestContext
.
getToken
()));
if
(
orgCode
!=
null
&&
orgCode
.
isFlag
()&&!
orgCode
.
isFarmer
()){
StatementHandler
statementHandler
=
PluginUtils
.
realTarget
(
invocation
.
getTarget
());
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statementHandler
);
MappedStatement
mappedStatement
=
(
MappedStatement
)
metaObject
.
getValue
(
"delegate.mappedStatement"
);
//获取方法注解
Method
method
=
getTargetDataAuthMethod
(
mappedStatement
);
UserEmpower
userEmpower
=
getTargetDataAuthAnnotation
(
mappedStatement
);
// Method method = getTargetDataAuthMethod(mappedStatement);
UserEmpower
userEmpower
;
if
(
mappedStatement
.
getId
().
contains
(
"_COUNT"
)){
String
id
=
mappedStatement
.
getId
().
replace
(
"_COUNT"
,
""
);
userEmpower
=
getTargetDataAuthAnnotationCount
(
id
);
if
(
userEmpower
==
null
)
{
return
invocation
.
proceed
();
}
}
else
{
userEmpower
=
getTargetDataAuthAnnotation
(
mappedStatement
);
}
if
(
userEmpower
==
null
){
return
invocation
.
proceed
();
}
...
...
@@ -125,11 +140,22 @@ public class UserEmpowerInterceptor implements Interceptor {
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statementHandler
);
MappedStatement
mappedStatement
=
(
MappedStatement
)
metaObject
.
getValue
(
"delegate.mappedStatement"
);
//获取方法注解
Method
method
=
getTargetDataAuthMethod
(
mappedStatement
);
UserEmpower
userEmpower
=
getTargetDataAuthAnnotation
(
mappedStatement
);
if
(
userEmpower
==
null
)
{
return
invocation
.
proceed
();
BoundSql
boundSql
=
(
BoundSql
)
metaObject
.
getValue
(
"delegate.boundSql"
);
String
sql
=
boundSql
.
getSql
();
UserEmpower
userEmpower
;
if
(
mappedStatement
.
getId
().
contains
(
"_COUNT"
)){
String
id
=
mappedStatement
.
getId
().
replace
(
"_COUNT"
,
""
);
userEmpower
=
getTargetDataAuthAnnotationCount
(
id
);
if
(
userEmpower
==
null
)
{
return
invocation
.
proceed
();
}
}
else
{
userEmpower
=
getTargetDataAuthAnnotation
(
mappedStatement
);
if
(
userEmpower
==
null
)
{
return
invocation
.
proceed
();
}
}
//获取字段
String
[]
filed
=
userEmpower
.
dealerField
();
//获取字段条件表达式
...
...
@@ -141,10 +167,11 @@ public class UserEmpowerInterceptor implements Interceptor {
List
<
String
>
list
=
new
ArrayList
<>(
Arrays
.
asList
(
data
));
list
.
removeAll
(
Collections
.
singleton
(
null
));
BoundSql
boundSql
=
(
BoundSql
)
metaObject
.
getValue
(
"delegate.boundSql"
);
List
<
String
>
sq
;
//获取sql
String
sql
=
boundSql
.
getSql
();
List
<
String
>
fileds
=
Arrays
.
asList
(
filed
);
if
(!
ValidationUtil
.
isEmpty
(
dataAuthRule
.
getAdminRegionalCompaniesCode
()))
{
sq
=
selectSqlJXS
(
new
String
[]{
fileds
.
get
(
0
),
fileds
.
get
(
1
)},
fileCondition
,
list
);
...
...
@@ -508,6 +535,20 @@ public class UserEmpowerInterceptor implements Interceptor {
return
null
;
}
private
Method
getTargetDataAuthMethodCount
(
String
id
)
throws
ClassNotFoundException
{
String
className
=
id
.
substring
(
0
,
id
.
lastIndexOf
(
"."
));
String
methodName
=
id
.
substring
(
id
.
lastIndexOf
(
"."
)
+
1
);
final
Class
<?>
cls
=
Class
.
forName
(
className
);
final
Method
[]
methods
=
cls
.
getMethods
();
for
(
Method
method
:
methods
)
{
// TODO 后续重载方法需要优化
if
(
method
.
getName
().
equals
(
methodName
)
&&
method
.
isAnnotationPresent
(
UserEmpower
.
class
))
{
return
method
;
}
}
return
null
;
}
/**
* 获取当前执行语句对应mapper方法的DataAuth注解
*
...
...
@@ -535,6 +576,10 @@ public class UserEmpowerInterceptor implements Interceptor {
return
sql
;
}
private
UserEmpower
getTargetDataAuthAnnotationCount
(
String
id
)
throws
ClassNotFoundException
{
return
getTargetDataAuthMethodCount
(
id
).
getAnnotation
(
UserEmpower
.
class
);
}
...
...
@@ -557,7 +602,11 @@ public class UserEmpowerInterceptor implements Interceptor {
return
sql
;
}
private
boolean
isCountQuery
(
String
sql
)
{
// 判断 SQL 是否为 COUNT 查询
boolean
flag
=
sql
.
startsWith
(
"SELECT count("
);
return
flag
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment