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
c8f1e60b
Commit
c8f1e60b
authored
Jun 13, 2022
by
hongguangwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据权限-缓存保存111
parent
ff8c24dc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
10 deletions
+96
-10
CacheConstants.java
...oud.plus.v1/yifu/common/core/constant/CacheConstants.java
+9
-0
CommonConstants.java
...ud.plus.v1/yifu/common/core/constant/CommonConstants.java
+6
-0
DataAuthController.java
...oud.plus.v1/yifu/admin/controller/DataAuthController.java
+1
-0
SysDataAuthService.java
....cloud.plus.v1/yifu/admin/service/SysDataAuthService.java
+1
-0
SysDataAuthServiceImpl.java
...us.v1/yifu/admin/service/impl/SysDataAuthServiceImpl.java
+77
-10
SysDataAuthMapper.xml
...-upms-biz/src/main/resources/mapper/SysDataAuthMapper.xml
+2
-0
No files found.
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/constant/CacheConstants.java
View file @
c8f1e60b
...
...
@@ -64,4 +64,13 @@ public interface CacheConstants {
*/
String
PARAMS_DETAILS
=
"params_details"
;
/**
* 数据权限信息缓存
* data_auth_details0:用户组
* data_auth_details1:用户
* hgw
* 2022-6-9 17:29:49
*/
String
DATA_AUTH_DETAILS
=
"data_auth_details"
;
}
yifu-common/yifu-common-core/src/main/java/com/yifu.cloud.plus.v1/yifu/common/core/constant/CommonConstants.java
View file @
c8f1e60b
...
...
@@ -123,4 +123,10 @@ public interface CommonConstants {
*/
String
THREE_String
=
"3"
;
/**
* 下划线
* hgw 2022-6-9 17:36:35
*/
String
DOWN_LINE
=
"_"
;
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/controller/DataAuthController.java
View file @
c8f1e60b
...
...
@@ -29,6 +29,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.concurrent.TimeoutException
;
/**
* @Description: 数据权限控制器
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/SysDataAuthService.java
View file @
c8f1e60b
...
...
@@ -24,6 +24,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDataAuthVO;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
java.util.List
;
import
java.util.concurrent.TimeoutException
;
/**
* @Description: 数据权限配置接口
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/impl/SysDataAuthServiceImpl.java
View file @
c8f1e60b
...
...
@@ -23,14 +23,19 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.entity.*;
import
com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDataAuthVO
;
import
com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDataAuthMapper
;
import
com.yifu.cloud.plus.v1.yifu.admin.service.*
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.Common
;
import
com.yifu.cloud.plus.v1.yifu.common.core.util.R
;
import
com.yifu.cloud.plus.v1.yifu.common.security.service.YifuUser
;
import
com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -54,6 +59,9 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 自定义sql-菜单
private
final
SysDiySqlMenuRelService
diySqlMenuRelService
;
// 缓存信息
private
final
CacheManager
cacheManager
;
/**
* @Description: 分页查询
* @Author: hgw
...
...
@@ -99,18 +107,26 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
}
else
{
List
<
SysDataAuthMenuRel
>
saveMenuDeptList
=
new
ArrayList
<>();
// 更新缓存
Cache
cache
=
cacheManager
.
getCache
(
CacheConstants
.
DATA_AUTH_DETAILS
+
sysDataAuth
.
getLinkType
());
if
(
cache
==
null
)
{
return
R
.
failed
(
"获取Redis缓存失败!"
);
}
// 编辑
String
mainId
=
sysDataAuth
.
getId
();
R
<
String
>
failed
=
null
;
R
<
String
>
failed
;
if
(
mainId
==
null
)
{
// 新增
sysDataAuth
.
setCreateBy
(
user
.
getId
());
sysDataAuth
.
setCreateName
(
user
.
getNickname
());
sysDataAuth
.
setCreateTime
(
LocalDateTime
.
now
());
this
.
save
(
sysDataAuth
);
mainId
=
sysDataAuth
.
getId
();
}
else
{
// 删除之前的关系
this
.
deleteSubInfoByMainId
(
mainId
);
}
failed
=
doCore
(
sysDataAuth
,
saveMenuDeptList
,
sysDataAuthVO
,
mainId
);
failed
=
this
.
doCore
(
sysDataAuth
,
saveMenuDeptList
,
sysDataAuthVO
,
mainId
,
cache
);
if
(
failed
!=
null
)
{
return
failed
;
}
...
...
@@ -119,6 +135,7 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
if
(!
saveMenuDeptList
.
isEmpty
())
{
authMenuRelService
.
saveOrUpdateBatch
(
saveMenuDeptList
);
}
return
R
.
ok
(
"保存成功"
);
}
}
else
{
...
...
@@ -133,7 +150,8 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String>
**/
private
R
<
String
>
doCore
(
SysDataAuth
sysDataAuth
,
List
<
SysDataAuthMenuRel
>
saveMenuDeptList
,
SysDataAuthVO
sysDataAuthVO
,
String
mainId
)
{
,
SysDataAuthVO
sysDataAuthVO
,
String
mainId
,
Cache
cache
)
{
List
<
SysDataAuthDeptRel
>
authDeptList
=
sysDataAuthVO
.
getAuthDeptList
();
List
<
SysDataAuthDiySql
>
authSqlList
=
sysDataAuthVO
.
getAuthSqlList
();
...
...
@@ -141,28 +159,49 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
List
<
SysDataAuthMenuRel
>
menuCreateList
=
sysDataAuthVO
.
getMenuCreateList
();
List
<
SysDataAuthMenuRel
>
menuSettleList
=
sysDataAuthVO
.
getMenuSettleList
();
List
<
SysDataAuthMenuRel
>
menuDeptList
=
sysDataAuthVO
.
getMenuDeptList
();
// 存储sql的map,用作缓存 键:linkId + CommonConstants.DOWN_LINE + menu.getMenuId()
Map
<
String
,
String
>
authSqlMap
=
new
HashMap
<>();
StringBuilder
sql
=
new
StringBuilder
();
String
mapSql
;
StringBuilder
nowMapSql
;
// Map里的Key
String
linkId
=
sysDataAuth
.
getLinkId
();
// 处理权限部门
if
(
sysDataAuth
.
getIsDeptAuth
()
==
1
||
sysDataAuth
.
getIsDeptAuth
()
==
2
)
{
if
(
menuDeptList
==
null
||
menuDeptList
.
isEmpty
())
{
return
R
.
failed
(
"请选择部门关联的菜单!"
);
}
else
if
(
sysDataAuth
.
getIsDeptAuth
()
==
2
)
{
sql
.
append
(
" or dept.dept_id in ('0' "
);
for
(
SysDataAuthDeptRel
dept
:
authDeptList
)
{
sql
.
append
(
", '"
).
append
(
dept
.
getDeptId
()).
append
(
"'"
);
dept
.
setSysDataAuthId
(
mainId
);
}
sql
.
append
(
")"
);
authDeptRelService
.
saveOrUpdateBatch
(
authDeptList
);
}
else
{
sql
.
append
(
" or dept.dept_id = #deptId "
);
}
for
(
SysDataAuthMenuRel
menu
:
menuDeptList
)
{
authSqlMap
.
put
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menu
.
getMenuId
(),
sql
.
toString
());
menu
.
setSysDataAuthId
(
mainId
);
menu
.
setType
(
3
);
}
saveMenuDeptList
.
addAll
(
menuSettleList
);
}
String
nowSql
;
// 处理创建人
if
(
menuCreateList
!=
null
&&
!
menuCreateList
.
isEmpty
())
{
nowSql
=
" or a.create_by = #create_by "
;
sysDataAuth
.
setIsCreateAuth
(
1
);
for
(
SysDataAuthMenuRel
menu
:
menuCreateList
)
{
mapSql
=
authSqlMap
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menu
.
getMenuId
());
if
(!
Common
.
isEmpty
(
mapSql
))
{
nowMapSql
=
new
StringBuilder
(
nowSql
).
append
(
mapSql
);
}
else
{
nowMapSql
=
new
StringBuilder
(
nowSql
);
}
authSqlMap
.
put
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menu
.
getMenuId
(),
nowMapSql
.
toString
());
menu
.
setType
(
1
);
menu
.
setSysDataAuthId
(
mainId
);
}
...
...
@@ -171,8 +210,16 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
// 处理结算主体
if
(
menuSettleList
!=
null
&&
!
menuSettleList
.
isEmpty
())
{
nowSql
=
" or a.settleDomainId in ('0'#settleDomainId) "
;
sysDataAuth
.
setIsSettleAuth
(
1
);
for
(
SysDataAuthMenuRel
menu
:
menuSettleList
)
{
mapSql
=
authSqlMap
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menu
.
getMenuId
());
if
(!
Common
.
isEmpty
(
mapSql
))
{
nowMapSql
=
new
StringBuilder
(
nowSql
).
append
(
mapSql
);
}
else
{
nowMapSql
=
new
StringBuilder
(
nowSql
);
}
authSqlMap
.
put
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menu
.
getMenuId
(),
nowMapSql
.
toString
());
menu
.
setType
(
2
);
menu
.
setSysDataAuthId
(
mainId
);
}
...
...
@@ -183,14 +230,22 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
if
(
authSqlList
!=
null
&&
!
authSqlList
.
isEmpty
())
{
sysDataAuth
.
setIsDiySql
(
1
);
List
<
SysDiySqlMenuRel
>
menuSqlList
;
for
(
SysDataAuthDiySql
sql
:
authSqlList
)
{
menuSqlList
=
sql
.
getSqlMenuList
();
for
(
SysDataAuthDiySql
sqls
:
authSqlList
)
{
nowSql
=
sqls
.
getDiySql
();
menuSqlList
=
sqls
.
getSqlMenuList
();
if
(
menuSqlList
!=
null
&&
!
menuSqlList
.
isEmpty
())
{
sql
.
setSysDataAuthId
(
mainId
);
diySqlService
.
save
(
sql
);
sql
s
.
setSysDataAuthId
(
mainId
);
diySqlService
.
save
(
sql
s
);
for
(
SysDiySqlMenuRel
menuSql
:
menuSqlList
)
{
mapSql
=
authSqlMap
.
get
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menuSql
.
getMenuId
());
if
(!
Common
.
isEmpty
(
mapSql
))
{
nowMapSql
=
new
StringBuilder
(
nowSql
).
append
(
mapSql
);
}
else
{
nowMapSql
=
new
StringBuilder
(
nowSql
);
}
authSqlMap
.
put
(
linkId
+
CommonConstants
.
DOWN_LINE
+
menuSql
.
getMenuId
(),
nowMapSql
.
toString
());
menuSql
.
setSysDataAuthId
(
mainId
);
menuSql
.
setSysDiySqlId
(
sql
.
getId
());
menuSql
.
setSysDiySqlId
(
sql
s
.
getId
());
}
diySqlMenuRelService
.
saveBatch
(
menuSqlList
);
}
else
{
...
...
@@ -198,6 +253,18 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
}
}
}
// 更新缓存
// 缓存里放入 id_菜单id, sql
if
(!
authSqlMap
.
isEmpty
())
{
// 前缀
String
prefix
=
" and (1=1 "
;
// 后缀
String
suffix
=
" ) "
;
for
(
Map
.
Entry
<
String
,
String
>
authSql
:
authSqlMap
.
entrySet
())
{
cache
.
put
(
authSql
.
getKey
(),
prefix
+
authSql
.
getValue
()
+
suffix
);
}
}
return
null
;
}
...
...
yifu-upms/yifu-upms-biz/src/main/resources/mapper/SysDataAuthMapper.xml
View file @
c8f1e60b
...
...
@@ -28,6 +28,7 @@
<result
property=
"isSettleAuth"
column=
"is_settle_auth"
/>
<result
property=
"isDiySql"
column=
"is_diy_sql"
/>
<result
property=
"createBy"
column=
"create_by"
/>
<result
property=
"createName"
column=
"create_name"
/>
<result
property=
"createTime"
column=
"create_time"
/>
<result
property=
"updateBy"
column=
"update_by"
/>
<result
property=
"updateTime"
column=
"update_time"
/>
...
...
@@ -43,6 +44,7 @@
a.is_settle_auth,
a.is_diy_sql,
a.create_by,
a.create_name,
a.create_time,
a.update_by,
a.update_time
...
...
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