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
a16bf1d3
Commit
a16bf1d3
authored
Jun 14, 2022
by
fangxinjiang
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/develop' into develop
parents
dfba77f2
ee735b39
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
125 additions
and
15 deletions
+125
-15
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
SysDict.java
...com/yifu.cloud.plus.v1/yifu/admin/api/entity/SysDict.java
+10
-4
DataAuthController.java
...oud.plus.v1/yifu/admin/controller/DataAuthController.java
+1
-1
SysDataAuthService.java
....cloud.plus.v1/yifu/admin/service/SysDataAuthService.java
+1
-0
SysDataAuthServiceImpl.java
...us.v1/yifu/admin/service/impl/SysDataAuthServiceImpl.java
+90
-10
SysDataAuthMapper.xml
...-upms-biz/src/main/resources/mapper/SysDataAuthMapper.xml
+8
-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 @
a16bf1d3
...
...
@@ -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 @
a16bf1d3
...
...
@@ -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-api/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/api/entity/SysDict.java
View file @
a16bf1d3
...
...
@@ -44,15 +44,15 @@ public class SysDict extends BaseEntity {
private
Long
id
;
/**
*
类型
*
字典编码
*/
@Schema
(
description
=
"字典
类型
"
)
@Schema
(
description
=
"字典
编码
"
)
private
String
type
;
/**
*
描述
*
字典名称
*/
@Schema
(
description
=
"字典
描述
"
)
@Schema
(
description
=
"字典
名称
"
)
private
String
description
;
/**
...
...
@@ -74,4 +74,10 @@ public class SysDict extends BaseEntity {
@Schema
(
description
=
"删除标记,1:已删除,0:正常"
)
private
String
delFlag
;
/**
* 备注信息
*/
@Schema
(
description
=
"联动上级类型"
)
private
String
parentItemType
;
}
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/controller/DataAuthController.java
View file @
a16bf1d3
...
...
@@ -89,7 +89,7 @@ public class DataAuthController {
@Operation
(
summary
=
"新增/编辑数据权限配置"
)
@SysLog
(
"系统管理-数据权限-新增/编辑数据权限配置"
)
@PostMapping
(
"/saveOrUpdate"
)
@PreAuthorize
(
"@pms.hasPermission('sys_data_auth_add')"
)
//
@PreAuthorize("@pms.hasPermission('sys_data_auth_add')")
public
R
<
String
>
saveOrUpdate
(
@RequestBody
SysDataAuthVO
sysDataAuthVO
)
{
return
sysDataAuthService
.
saveDataAuth
(
sysDataAuthVO
);
}
...
...
yifu-upms/yifu-upms-biz/src/main/java/com/yifu.cloud.plus.v1/yifu/admin/service/SysDataAuthService.java
View file @
a16bf1d3
...
...
@@ -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 @
a16bf1d3
...
...
@@ -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,39 @@ 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
old
=
new
SysDataAuth
();
old
.
setLinkId
(
sysDataAuth
.
getLinkId
());
old
.
setLinkType
(
sysDataAuth
.
getLinkType
());
List
<
SysDataAuth
>
oldList
=
this
.
getSysDataAuthList
(
old
);
if
(
oldList
!=
null
&&
!
oldList
.
isEmpty
())
{
return
R
.
failed
(
sysDataAuth
.
getLinkName
()
+
" 已存在,不可新增,请去编辑!"
);
}
// 新增
sysDataAuth
.
setCreateBy
(
user
.
getId
());
sysDataAuth
.
setCreateName
(
user
.
getNickname
());
sysDataAuth
.
setCreateTime
(
LocalDateTime
.
now
());
sysDataAuth
.
setIsCreateAuth
(
0
);
sysDataAuth
.
setIsDeptAuth
(
0
);
sysDataAuth
.
setIsSettleAuth
(
0
);
sysDataAuth
.
setIsDiySql
(
0
);
this
.
save
(
sysDataAuth
);
mainId
=
sysDataAuth
.
getId
();
}
else
{
sysDataAuth
.
setUpdateBy
(
user
.
getId
());
sysDataAuth
.
setUpdateTime
(
LocalDateTime
.
now
());
// 删除之前的关系
this
.
deleteSubInfoByMainId
(
mainId
);
}
failed
=
doCore
(
sysDataAuth
,
saveMenuDeptList
,
sysDataAuthVO
,
mainId
);
failed
=
this
.
doCore
(
sysDataAuth
,
saveMenuDeptList
,
sysDataAuthVO
,
mainId
,
cache
);
if
(
failed
!=
null
)
{
return
failed
;
}
...
...
@@ -119,6 +148,7 @@ public class SysDataAuthServiceImpl extends ServiceImpl<SysDataAuthMapper, SysDa
if
(!
saveMenuDeptList
.
isEmpty
())
{
authMenuRelService
.
saveOrUpdateBatch
(
saveMenuDeptList
);
}
return
R
.
ok
(
"保存成功"
);
}
}
else
{
...
...
@@ -133,7 +163,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 +172,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 +223,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 +243,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 +266,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 @
a16bf1d3
...
...
@@ -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
...
...
@@ -56,6 +58,12 @@
<if
test=
"sysDataAuth.linkName != null and sysDataAuth.linkName.trim() != ''"
>
AND a.link_name like concat('%',#{sysDataAuth.linkName},'%')
</if>
<if
test=
"sysDataAuth.linkId != null and sysDataAuth.linkId.trim() != ''"
>
AND a.link_id = #{sysDataAuth.linkId}
</if>
<if
test=
"sysDataAuth.linkType != null"
>
AND a.link_type =#{sysDataAuth.linkType}
</if>
</if>
</sql>
...
...
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