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
112c566a
Commit
112c566a
authored
Mar 21, 2024
by
tangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改权限注解
parent
a2423790
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
60 deletions
+79
-60
UserEmpower.java
...yeejoin/amos/boot/module/hygf/api/config/UserEmpower.java
+4
-0
UserEmpowerInterceptor.java
...s/boot/module/hygf/api/config/UserEmpowerInterceptor.java
+75
-60
No files found.
amos-boot-system-jxiop/amos-boot-module-hygf-api/src/main/java/com/yeejoin/amos/boot/module/hygf/api/config/UserEmpower.java
View file @
112c566a
...
@@ -23,6 +23,10 @@ public @interface UserEmpower {
...
@@ -23,6 +23,10 @@ public @interface UserEmpower {
*/
*/
String
[]
field
();
String
[]
field
();
/**
/**
* @param 经销商字段(Field1,Field2)
*/
String
[]
dealerField
();
/**
* @param 每个字段运算符( in,like,likeLeft,likeRight,eq)
* @param 每个字段运算符( in,like,likeLeft,likeRight,eq)
*/
*/
String
[]
fieldConditions
()
;
String
[]
fieldConditions
()
;
...
...
amos-boot-system-jxiop/amos-boot-module-hygf-api/src/main/java/com/yeejoin/amos/boot/module/hygf/api/config/UserEmpowerInterceptor.java
View file @
112c566a
...
@@ -45,80 +45,95 @@ public class UserEmpowerInterceptor implements Interceptor {
...
@@ -45,80 +45,95 @@ public class UserEmpowerInterceptor implements Interceptor {
@Override
@Override
public
Object
intercept
(
Invocation
invocation
)
throws
Throwable
{
public
Object
intercept
(
Invocation
invocation
)
throws
Throwable
{
try
{
StdUserEmpower
orgCode
=(
StdUserEmpower
)
redisUtils
.
get
(
"Emp_"
+
RedisKey
.
buildReginKey
(
RequestContext
.
getExeUserId
(),
RequestContext
.
getToken
()));
if
(
orgCode
.
isFlag
()){
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
);
if
(
userEmpower
==
null
){
return
invocation
.
proceed
();
}
//StdUserEmpower orgCode = UserEmpowerThreadLocal.getDataAuthRule();
if
(
orgCode
!=
null
&&
orgCode
.
isFlag
()){
//获取字段
String
[]
filed
=
userEmpower
.
field
();
//获取字段条件表达式
String
[]
fileCondition
=
userEmpower
.
fieldConditions
();
//获取 参数之间关系
String
[]
fileBetweenCondition
=
userEmpower
.
relationship
();
//获取 是否特殊
Boolean
specific
=
userEmpower
.
specific
();
BoundSql
boundSql
=
(
BoundSql
)
metaObject
.
getValue
(
"delegate.boundSql"
);
//获取sql
String
sql
=
boundSql
.
getSql
();
//拼接参数
List
<
String
>
sq
=
selectSql
(
filed
,
fileCondition
,
orgCode
,
specific
);
String
sqldata
=
" "
;
if
(
sq
!=
null
&&
sq
.
size
()>
0
){
if
(
fileCondition
.
length
==
1
){
sqldata
=
sqldata
+
sq
.
get
(
0
);
}
else
{
if
(
fileBetweenCondition
!=
null
&&
fileBetweenCondition
.
length
>
0
){
for
(
int
i
=
0
;
i
<
sq
.
size
();
i
++)
{
if
(
i
==
sq
.
size
()-
1
){
sqldata
=
sqldata
+
sq
.
get
(
i
);
}
else
{
sqldata
=
sqldata
+
sq
.
get
(
i
)+
" "
+
fileBetweenCondition
[
i
]+
" "
;
}
}
}
else
{
sqldata
=
" "
;
}
}
}
try
{
Select
select
=
(
Select
)
CCJSqlParserUtil
.
parse
(
sql
);
StatementHandler
statementHandler
=
PluginUtils
.
realTarget
(
invocation
.
getTarget
());
PlainSelect
selectBody
=
(
PlainSelect
)
select
.
getSelectBody
();
MetaObject
metaObject
=
SystemMetaObject
.
forObject
(
statementHandler
);
if
(!
ValidationUtil
.
isEmpty
(
sqldata
.
trim
()))
{
MappedStatement
mappedStatement
=
(
MappedStatement
)
metaObject
.
getValue
(
"delegate.mappedStatement"
);
//获取方法注解
Method
method
=
getTargetDataAuthMethod
(
mappedStatement
);
UserEmpower
userEmpower
=
getTargetDataAuthAnnotation
(
mappedStatement
);
if
(
userEmpower
==
null
){
return
invocation
.
proceed
();
}
//StdUserEmpower orgCode = UserEmpowerThreadLocal.getDataAuthRule();
StdUserEmpower
orgCode
=(
StdUserEmpower
)
redisUtils
.
get
(
"Emp_"
+
RedisKey
.
buildReginKey
(
RequestContext
.
getExeUserId
(),
RequestContext
.
getToken
()));
}
else
{
sqldata
=
" 1= 2 "
;
}
if
(
orgCode
!=
null
&&
orgCode
.
isFlag
()){
if
(
ValidationUtil
.
isEmpty
(
selectBody
.
getWhere
()))
{
//获取字段
selectBody
.
setWhere
(
CCJSqlParserUtil
.
parseCondExpression
(
sqldata
));
String
[]
filed
=
userEmpower
.
field
();
}
else
{
//获取字段条件表达式
AndExpression
andExpr
=
new
AndExpression
(
selectBody
.
getWhere
(),
CCJSqlParserUtil
.
parseCondExpression
(
sqldata
));
String
[]
fileCondition
=
userEmpower
.
fieldConditions
();
selectBody
.
setWhere
(
andExpr
);
//获取 参数之间关系
}
String
[]
fileBetweenCondition
=
userEmpower
.
relationship
();
System
.
out
.
println
(
selectBody
.
toString
());
//获取 是否特殊
metaObject
.
setValue
(
"delegate.boundSql.sql"
,
selectBody
.
toString
());
Boolean
specific
=
userEmpower
.
specific
();
}
else
{
return
invocation
.
proceed
();
}
}
else
{
//经销商
BoundSql
boundSql
=
(
BoundSql
)
metaObject
.
getValue
(
"delegate.boundSql"
);
//获取sql
String
sql
=
boundSql
.
getSql
();
//拼接参数
List
<
String
>
sq
=
selectSql
(
filed
,
fileCondition
,
orgCode
,
specific
);
String
sqldata
=
" "
;
if
(
sq
!=
null
&&
sq
.
size
()>
0
){
if
(
fileCondition
.
length
==
1
){
sqldata
=
sqldata
+
sq
.
get
(
0
);
}
else
{
if
(
fileBetweenCondition
!=
null
&&
fileBetweenCondition
.
length
>
0
){
for
(
int
i
=
0
;
i
<
sq
.
size
();
i
++)
{
if
(
i
==
sq
.
size
()-
1
){
sqldata
=
sqldata
+
sq
.
get
(
i
);
}
else
{
sqldata
=
sqldata
+
sq
.
get
(
i
)+
" "
+
fileBetweenCondition
[
i
]+
" "
;
}
}
}
else
{
sqldata
=
" "
;
}
}
}
}
Select
select
=
(
Select
)
CCJSqlParserUtil
.
parse
(
sql
);
PlainSelect
selectBody
=
(
PlainSelect
)
select
.
getSelectBody
();
if
(!
ValidationUtil
.
isEmpty
(
sqldata
.
trim
()))
{
}
else
{
sqldata
=
" 1= 2 "
;
}
if
(
ValidationUtil
.
isEmpty
(
selectBody
.
getWhere
()))
{
selectBody
.
setWhere
(
CCJSqlParserUtil
.
parseCondExpression
(
sqldata
));
}
else
{
AndExpression
andExpr
=
new
AndExpression
(
selectBody
.
getWhere
(),
CCJSqlParserUtil
.
parseCondExpression
(
sqldata
));
selectBody
.
setWhere
(
andExpr
);
}
System
.
out
.
println
(
selectBody
.
toString
());
metaObject
.
setValue
(
"delegate.boundSql.sql"
,
selectBody
.
toString
());
}
else
{
return
invocation
.
proceed
();
}
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
BadRequest
(
"权限认证失败!"
);
throw
new
BadRequest
(
"权限认证失败!"
);
...
...
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