Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
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
fangxinjiang
yifu-mvp
Commits
8371a0d0
Commit
8371a0d0
authored
Aug 08, 2025
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MVP1.7.14-优化采用用户组控制数据权限的菜单,账号若无用户组,不允许看数据。
parent
65707b1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
74 deletions
+91
-74
MenuUtil.java
...om/yifu/cloud/plus/v1/yifu/common/dapr/util/MenuUtil.java
+91
-74
No files found.
yifu-common/yifu-common-dapr/src/main/java/com/yifu/cloud/plus/v1/yifu/common/dapr/util/MenuUtil.java
View file @
8371a0d0
...
...
@@ -36,96 +36,113 @@ public class MenuUtil {
private
static
final
String
START_STR
=
"start"
;
public
void
setAuthSql
(
YifuUser
user
,
BaseEntity
entity
)
{
// 是否无权限,默认否
boolean
noAuth
=
false
;
// 普通用户:
if
(
user
!=
null
&&
Common
.
isNotNull
(
user
.
getId
())
&&
CommonConstants
.
ONE_STRING
.
equals
(
user
.
getSystemFlag
()))
{
// 菜单id
String
menuId
=
entity
.
getMId
();
if
(
Common
.
isEmpty
(
menuId
))
{
menuId
=
entity
.
getMenuInfo
();
}
if
(
Common
.
isNotNull
(
menuId
))
{
String
linkId
=
user
.
getId
();
int
linkType
=
1
;
// 用户
SysDataAuth
sysDataAuth
=
new
SysDataAuth
();
sysDataAuth
.
setLinkId
(
linkId
);
sysDataAuth
.
setLinkType
(
linkType
);
// 获取缓存菜单权限的步骤:
Cache
cache
=
cacheManager
.
getCache
(
CacheConstants
.
DATA_AUTH_DETAILS
+
linkType
);
Object
obj
=
null
;
if
(
cache
!=
null
)
{
obj
=
cache
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE_STRING
+
menuId
);
if
(
Common
.
isEmpty
(
obj
))
{
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
(),
daprUpmsProperties
.
getAppId
()
,
"/dataAuth/refreshAuth"
,
sysDataAuth
,
SysDataAuth
.
class
,
SecurityConstants
.
FROM_IN
);
if
(
user
!=
null
&&
Common
.
isNotNull
(
user
.
getId
()))
{
if
(
CommonConstants
.
ONE_STRING
.
equals
(
user
.
getSystemFlag
()))
{
// 菜单id
String
menuId
=
entity
.
getMId
();
if
(
Common
.
isEmpty
(
menuId
))
{
menuId
=
entity
.
getMenuInfo
();
}
if
(
Common
.
isNotNull
(
menuId
))
{
String
linkId
=
user
.
getId
();
int
linkType
=
1
;
// 用户
SysDataAuth
sysDataAuth
=
new
SysDataAuth
();
sysDataAuth
.
setLinkId
(
linkId
);
sysDataAuth
.
setLinkType
(
linkType
);
// 获取缓存菜单权限的步骤:
Cache
cache
=
cacheManager
.
getCache
(
CacheConstants
.
DATA_AUTH_DETAILS
+
linkType
);
Object
obj
=
null
;
if
(
cache
!=
null
)
{
obj
=
cache
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE_STRING
+
menuId
);
if
(
Common
.
isEmpty
(
obj
))
{
linkId
=
user
.
getUserGroup
();
linkType
=
0
;
// 用户组
cache
=
cacheManager
.
getCache
(
CacheConstants
.
DATA_AUTH_DETAILS
+
linkType
);
if
(
cache
!=
null
)
{
obj
=
cache
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE_STRING
+
menuId
);
if
(
Common
.
isEmpty
(
obj
))
{
sysDataAuth
.
setLinkId
(
linkId
);
sysDataAuth
.
setLinkType
(
linkType
);
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
(),
daprUpmsProperties
.
getAppId
()
,
"/dataAuth/refreshAuth"
,
sysDataAuth
,
SysDataAuth
.
class
,
SecurityConstants
.
FROM_IN
);
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
(),
daprUpmsProperties
.
getAppId
()
,
"/dataAuth/refreshAuth"
,
sysDataAuth
,
SysDataAuth
.
class
,
SecurityConstants
.
FROM_IN
);
obj
=
cache
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE_STRING
+
menuId
);
if
(
Common
.
isEmpty
(
obj
))
{
linkId
=
user
.
getUserGroup
();
// 无用户组,直接返回阻断sql
if
(
Common
.
isEmpty
(
linkId
))
{
entity
.
setAuthSql
(
" and 1=2 "
);
return
;
}
linkType
=
0
;
// 用户组
cache
=
cacheManager
.
getCache
(
CacheConstants
.
DATA_AUTH_DETAILS
+
linkType
);
if
(
cache
!=
null
)
{
obj
=
cache
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE_STRING
+
menuId
);
if
(
Common
.
isEmpty
(
obj
))
{
sysDataAuth
.
setLinkId
(
linkId
);
sysDataAuth
.
setLinkType
(
linkType
);
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
(),
daprUpmsProperties
.
getAppId
()
,
"/dataAuth/refreshAuth"
,
sysDataAuth
,
SysDataAuth
.
class
,
SecurityConstants
.
FROM_IN
);
obj
=
cache
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE_STRING
+
menuId
);
}
}
}
}
}
}
if
(
Common
.
isNotNull
(
obj
))
{
SimpleValueWrapper
objs
=
(
SimpleValueWrapper
)
obj
;
if
(
Common
.
isNotNull
(
objs
))
{
String
sql
=
String
.
valueOf
(
objs
.
get
());
if
(
sql
.
contains
(
"#create_by"
))
{
sql
=
sql
.
replace
(
"#create_by"
,
user
.
getId
());
}
if
(
sql
.
contains
(
"#settleDomainId"
))
{
// 获取人员项目权限
R
<
TSettleDomainListVo
>
res
=
HttpDaprUtil
.
invokeMethodPost
(
daprArchivesProperties
.
getAppUrl
()
,
daprArchivesProperties
.
getAppId
(),
"/tsettledomain/getSettleDomainIdsByUserId"
,
user
.
getId
(),
TSettleDomainListVo
.
class
,
SecurityConstants
.
FROM_IN
);
StringBuilder
deptStr
=
new
StringBuilder
();
if
(
res
!=
null
&&
CommonConstants
.
SUCCESS
==
res
.
getCode
()
&&
res
.
getData
()
!=
null
&&
res
.
getData
().
getDeptIds
()
!=
null
&&
!
res
.
getData
().
getDeptIds
().
isEmpty
())
{
for
(
String
deptId
:
res
.
getData
().
getDeptIds
())
{
deptStr
.
append
(
",'"
).
append
(
deptId
).
append
(
"'"
);
if
(
Common
.
isNotNull
(
obj
))
{
SimpleValueWrapper
objs
=
(
SimpleValueWrapper
)
obj
;
if
(
Common
.
isNotNull
(
objs
))
{
String
sql
=
String
.
valueOf
(
objs
.
get
());
if
(
sql
.
contains
(
"#create_by"
))
{
sql
=
sql
.
replace
(
"#create_by"
,
user
.
getId
());
}
if
(
sql
.
contains
(
"#settleDomainId"
))
{
// 获取人员项目权限
R
<
TSettleDomainListVo
>
res
=
HttpDaprUtil
.
invokeMethodPost
(
daprArchivesProperties
.
getAppUrl
()
,
daprArchivesProperties
.
getAppId
(),
"/tsettledomain/getSettleDomainIdsByUserId"
,
user
.
getId
(),
TSettleDomainListVo
.
class
,
SecurityConstants
.
FROM_IN
);
StringBuilder
deptStr
=
new
StringBuilder
(
);
if
(
res
!=
null
&&
CommonConstants
.
SUCCESS
==
res
.
getCode
()
&&
res
.
getData
()
!=
null
&&
res
.
getData
().
getDeptIds
()
!=
null
&&
!
res
.
getData
().
getDeptIds
().
isEmpty
())
{
for
(
String
deptId
:
res
.
getData
().
getDeptIds
())
{
deptStr
.
append
(
",'"
).
append
(
deptId
).
append
(
"'"
);
}
}
//sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "")
sql
=
sql
.
replace
(
"#settleDomainId"
,
deptStr
.
toString
());
}
//sql = sql.replace("or a.settle_domain_id in ('0'#settleDomainId) ", "")
sql
=
sql
.
replace
(
"#settleDomainId"
,
deptStr
.
toString
());
}
String
userIds
=
"0"
;
if
(
sql
.
contains
(
START_STR
))
{
String
deptIds
=
StringUtils
.
substringBetween
(
sql
,
START_STR
,
"end"
);
R
<
String
>
userIdR
=
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
()
,
daprUpmsProperties
.
getAppId
(),
"/user/inner/getUserIdByDeptIds"
,
deptIds
,
String
.
class
,
SecurityConstants
.
FROM_IN
);
if
(
userIdR
!=
null
&&
CommonConstants
.
SUCCESS
==
userIdR
.
getCode
())
{
userIds
=
userIdR
.
getData
(
);
String
userIds
=
"0"
;
if
(
sql
.
contains
(
START_STR
))
{
String
deptIds
=
StringUtils
.
substringBetween
(
sql
,
START_STR
,
"end"
);
R
<
String
>
userIdR
=
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
()
,
daprUpmsProperties
.
getAppId
(),
"/user/inner/getUserIdByDeptIds"
,
deptIds
,
String
.
class
,
SecurityConstants
.
FROM_IN
);
if
(
userIdR
!=
null
&&
CommonConstants
.
SUCCESS
==
userIdR
.
getCode
())
{
userIds
=
userIdR
.
getData
();
}
sql
=
sql
.
replace
(
START_STR
,
""
).
replace
(
"end"
,
""
)
.
replace
(
deptIds
,
userIds
);
}
sql
=
sql
.
replace
(
START_STR
,
""
).
replace
(
"end"
,
""
)
.
replace
(
deptIds
,
userIds
);
}
if
(
sql
.
contains
(
"#deptId"
))
{
R
<
String
>
userIdR
=
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
()
,
daprUpmsProperties
.
getAppId
(),
"/user/inner/getUserIdByDeptIds"
,
String
.
valueOf
(
user
.
getDeptId
()),
String
.
class
,
SecurityConstants
.
FROM_IN
);
if
(
userIdR
!=
null
&&
CommonConstants
.
SUCCESS
==
userIdR
.
getCode
())
{
userIds
=
userIdR
.
getData
();
if
(
sql
.
contains
(
"#deptId"
))
{
R
<
String
>
userIdR
=
HttpDaprUtil
.
invokeMethodPost
(
daprUpmsProperties
.
getAppUrl
()
,
daprUpmsProperties
.
getAppId
(),
"/user/inner/getUserIdByDeptIds"
,
String
.
valueOf
(
user
.
getDeptId
()),
String
.
class
,
SecurityConstants
.
FROM_IN
);
if
(
userIdR
!=
null
&&
CommonConstants
.
SUCCESS
==
userIdR
.
getCode
())
{
userIds
=
userIdR
.
getData
();
}
sql
=
sql
.
replace
(
"#deptId"
,
userIds
);
//sql = sql.replace(" or dept.dept_id = #deptId ", "")
}
if
(
Common
.
isNotNull
(
sql
))
{
entity
.
setAuthSql
(
sql
);
}
sql
=
sql
.
replace
(
"#deptId"
,
userIds
);
//sql = sql.replace(" or dept.dept_id = #deptId ", "")
}
if
(
Common
.
isNotNull
(
sql
))
{
entity
.
setAuthSql
(
sql
);
}
}
}
else
{
noAuth
=
true
;
}
}
}
else
{
noAuth
=
true
;
}
// 无权限的,默认无数据
if
(
noAuth
)
{
entity
.
setAuthSql
(
" and 1=2 "
);
}
}
}
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