Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-platform-auth
Overview
Overview
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
base_platform_enterprise
gic-platform-auth
Commits
e080d85d
Commit
e080d85d
authored
Sep 27, 2020
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
权限菜单刷本地缓存
parent
d8ce25f6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
117 deletions
+109
-117
MenuApiService.java
...pi/src/main/java/com/gic/auth/service/MenuApiService.java
+10
-1
MenuApiServiceImpl.java
...a/com/gic/auth/service/outer/impl/MenuApiServiceImpl.java
+71
-85
LoginController.java
...ain/java/com/gic/auth/web/controller/LoginController.java
+28
-31
No files found.
gic-platform-auth-api/src/main/java/com/gic/auth/service/MenuApiService.java
View file @
e080d85d
...
...
@@ -55,7 +55,7 @@ public interface MenuApiService {
ServiceResponse
<
Set
<
String
>>
getAppIdSetByUserId
(
Integer
userId
);
/**
* 查询用户
拥有的所有菜单路由权限
,用于登录用户session用
* 查询用户
没有权限的操作项(接口)
,用于登录用户session用
* @Title: listUserMenu
* @Description:
* @author guojuxing
...
...
@@ -194,6 +194,15 @@ public interface MenuApiService {
ServiceResponse
<
List
<
MenuDTO
>>
getAllMenuNotTree
(
String
versionCode
);
/**
* 查询gic平台所有的菜单数据,menu_type = 0 gic平台的菜单数据塞本地缓存
* @Title: setAllMenuToLocaleCache
* @Description:
* @author guojuxing
* @return com.gic.api.base.commons.ServiceResponse<java.util.List<com.gic.auth.dto.MenuDTO>>
*/
ServiceResponse
<
List
<
MenuDTO
>>
getAllMenu
();
/**
* 运维处使用
* @param enterpriseId
* @return
...
...
gic-platform-auth-service/src/main/java/com/gic/auth/service/outer/impl/MenuApiServiceImpl.java
View file @
e080d85d
...
...
@@ -29,6 +29,7 @@ import com.gic.open.api.dto.*;
import
com.gic.open.api.service.AppTokenApiService
;
import
com.gic.open.api.service.ApplicationApiService
;
import
com.gic.open.api.service.ServeApiService
;
import
com.gic.redis.data.util.RedisUtil
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -123,42 +124,17 @@ public class MenuApiServiceImpl implements MenuApiService {
if
(
tabSysUser
==
null
)
{
return
ServiceResponse
.
failure
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
"用户不存在"
);
}
if
(
StringUtils
.
isBlank
(
versionCode
))
{
return
ServiceResponse
.
success
(
new
ArrayList
<>());
}
//是否是运维用户
boolean
isOperationUser
=
tabSysUser
.
getLoginType
().
intValue
()
!=
0
;
List
<
MenuDTO
>
result
;
if
(
tabSysUser
.
getSuperAdmin
().
intValue
()
==
1
)
{
List
<
TabSysMenu
>
temp
=
new
ArrayList
<>();
//超级管理员
MenuListQO
params
=
new
MenuListQO
();
if
(!
isOperationUser
)
{
params
.
setAuthTypeList
(
Arrays
.
stream
(
new
Integer
[]{
1
,
2
}).
collect
(
Collectors
.
toList
()));
}
//查询gic的菜单
params
.
setIsGIC
(
MenuProjectConstants
.
DEFAULT_PROJECT_CODE
);
params
.
setVersionCode
(
versionCode
);
params
.
setMenuType
(
MenuTypeEnum
.
PAGE
.
getCode
());
temp
.
addAll
(
this
.
menuService
.
listMenu
(
params
));
//查询应用的菜单
params
.
setVersionCode
(
""
);
params
.
setIsGIC
(
MenuProjectConstants
.
APP_PROJECT_CODE
);
params
.
setMenuType
(
MenuTypeEnum
.
PAGE
.
getCode
());
temp
.
addAll
(
this
.
menuService
.
listMenu
(
params
));
result
=
EntityUtil
.
changeEntityListNew
(
MenuDTO
.
class
,
filterOperationUserDepartAuth
(
temp
,
tabSysUser
));
//没有权限的操作项数据
ServiceResponse
<
List
<
MenuDTO
>>
tempResult
=
getNoAuthOperationItem
(
userId
,
MenuProjectConstants
.
ALL_CODE
,
versionCode
);
return
ServiceResponse
.
success
(
tempResult
.
getResult
());
}
else
{
List
<
TabSysMenu
>
menuList
=
getUserMenuList
(
userId
);
result
=
EntityUtil
.
changeEntityListNew
(
MenuDTO
.
class
,
menuList
);
//没有权限的操作项数据
ServiceResponse
<
List
<
MenuDTO
>>
tempResult
=
getNoAuthOperationItem
(
userId
,
MenuProjectConstants
.
ALL_CODE
,
versionCode
);
re
sult
.
addAll
(
tempResult
.
getResult
());
re
turn
ServiceResponse
.
success
(
tempResult
.
getResult
());
}
return
ServiceResponse
.
success
(
result
);
}
@Override
...
...
@@ -259,6 +235,16 @@ public class MenuApiServiceImpl implements MenuApiService {
}
@Override
public
ServiceResponse
<
List
<
MenuDTO
>>
getAllMenu
()
{
//超级管理员
MenuListQO
params
=
new
MenuListQO
();
//查询gic的菜单
params
.
setMenuType
(
MenuTypeEnum
.
PAGE
.
getCode
());
List
<
MenuDTO
>
result
=
EntityUtil
.
changeEntityListNew
(
MenuDTO
.
class
,
this
.
menuService
.
listMenu
(
params
));
return
ServiceResponse
.
success
(
result
);
}
@Override
public
ServiceResponse
<
List
<
MenuDTO
>>
getSuperAdminMenuNotTree
(
Integer
enterpriseId
)
{
ServiceResponse
<
EnterpriseDTO
>
result
=
enterpriseApiService
.
getEnterpriseById
(
enterpriseId
);
if
(
result
.
isSuccess
())
{
...
...
@@ -1298,31 +1284,8 @@ public class MenuApiServiceImpl implements MenuApiService {
*/
private
List
<
TabSysMenu
>
filterOperationUserDepartAuth
(
List
<
TabSysMenu
>
resultList
,
TabSysUser
tabSysUser
)
{
if
(
tabSysUser
!=
null
&&
tabSysUser
.
getLoginType
().
intValue
()
!=
0
)
{
//运营人员的部门职位;根据手机号查询运维人员的部门职位信息
GicUserDTO
gicUserDTO
=
gicUserService
.
getUserByMobile
(
tabSysUser
.
getPhoneNumber
());
LOGGER
.
info
(
"运维人员的部门职位数据:{}"
,
JSON
.
toJSONString
(
gicUserDTO
));
//如果是运营人员
Set
<
String
>
departPosition
=
new
HashSet
<>(
2
);
String
departmentCode
=
gicUserDTO
.
getDepartmentCode
();
if
(
StringUtils
.
isNotBlank
(
departmentCode
))
{
if
(
StringUtils
.
isBlank
(
gicUserDTO
.
getPositionCode
()))
{
//如果职位code是空,则取下面全部的职位code
List
<
GicDepartmentDTO
>
gicDepartmentDTOList
=
gicDepartmentService
.
listAllGicDepartment
();
if
(
CollectionUtils
.
isNotEmpty
(
gicDepartmentDTOList
))
{
Map
<
String
,
List
<
GicPositionDTO
>>
departMap
=
gicDepartmentDTOList
.
stream
()
.
collect
(
Collectors
.
toMap
(
e
->
e
.
getDepartmentCode
(),
e
->
e
.
getPositionList
()));
List
<
GicPositionDTO
>
positionList
=
departMap
.
get
(
departmentCode
);
if
(
CollectionUtils
.
isNotEmpty
(
positionList
))
{
positionList
.
forEach
(
e
->
{
departPosition
.
add
(
departmentCode
+
"-"
+
e
.
getPositionCode
());
});
}
}
}
else
{
departPosition
.
add
(
departmentCode
+
"-"
+
gicUserDTO
.
getPositionCode
());
}
}
Set
<
String
>
departPosition
=
getLoginOperationDepartPosition
(
tabSysUser
.
getPhoneNumber
());
//过滤运营人员的部门职位权限
Map
<
String
,
List
<
TabSysMenuAuthDepart
>>
departMap
=
getAuthDepartMap
(
null
);
return
resultList
.
stream
().
filter
(
e
->
{
...
...
@@ -1352,6 +1315,40 @@ public class MenuApiServiceImpl implements MenuApiService {
}
/**
* 获取运维人员的部门职位数据
* @param phoneNumber
* @return
*/
private
Set
<
String
>
getLoginOperationDepartPosition
(
String
phoneNumber
)
{
//如果是运营人员
Set
<
String
>
departPosition
=
new
HashSet
<>(
16
);
//运营人员的部门职位;根据手机号查询运维人员的部门职位信息
GicUserDTO
gicUserDTO
=
gicUserService
.
getUserByMobile
(
phoneNumber
);
LOGGER
.
info
(
"运维人员的部门职位数据:{}"
,
JSON
.
toJSONString
(
gicUserDTO
));
String
departmentCode
=
gicUserDTO
.
getDepartmentCode
();
if
(
StringUtils
.
isNotBlank
(
departmentCode
))
{
if
(
StringUtils
.
isBlank
(
gicUserDTO
.
getPositionCode
()))
{
//如果职位code是空,则取下面全部的职位code
List
<
GicDepartmentDTO
>
gicDepartmentDTOList
=
gicDepartmentService
.
listAllGicDepartment
();
if
(
CollectionUtils
.
isNotEmpty
(
gicDepartmentDTOList
))
{
Map
<
String
,
List
<
GicPositionDTO
>>
departMap
=
gicDepartmentDTOList
.
stream
()
.
collect
(
Collectors
.
toMap
(
e
->
e
.
getDepartmentCode
(),
e
->
e
.
getPositionList
()));
List
<
GicPositionDTO
>
positionList
=
departMap
.
get
(
departmentCode
);
if
(
CollectionUtils
.
isNotEmpty
(
positionList
))
{
positionList
.
forEach
(
e
->
{
departPosition
.
add
(
departmentCode
+
DELIMITER
+
e
.
getPositionCode
());
});
}
}
}
else
{
departPosition
.
add
(
departmentCode
+
DELIMITER
+
gicUserDTO
.
getPositionCode
());
}
}
return
departPosition
;
}
/**
* 查询出所有的部门职位,用于过滤运营人员权限
* @param menuCodeList
* @return
...
...
@@ -1428,45 +1425,34 @@ public class MenuApiServiceImpl implements MenuApiService {
* @return com.gic.api.base.commons.ServiceResponse<java.util.List<com.gic.auth.dto.MenuDTO>>
*/
private
ServiceResponse
<
List
<
MenuDTO
>>
getNoAuthOperationItem
(
Integer
userId
,
int
projectCode
,
String
versionCode
)
{
//没有基础服务数据,则返回空
if
(
StringUtils
.
isBlank
(
versionCode
))
{
List
<
MenuDTO
>
noAuthList
=
new
ArrayList
<>(
1
);
MenuDTO
temp
=
new
MenuDTO
();
temp
.
setMenuId
(-
1
);
noAuthList
.
add
(
temp
);
return
ServiceResponse
.
success
(
noAuthList
);
}
TabSysUser
tabSysUser
=
userService
.
getUserById
(
userId
);
if
(
tabSysUser
==
null
)
{
return
ServiceResponse
.
failure
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
"用户不存在"
);
}
boolean
isSuperAdmin
=
tabSysUser
.
getSuperAdmin
().
intValue
()
==
1
;
//添加逻辑:如果是超级管理员,过滤部门权限,给出没有权限的操作项
if
(
tabSysUser
.
getSuperAdmin
().
intValue
()
==
1
)
{
if
(
isSuperAdmin
)
{
//
MenuListQO
params
=
new
MenuListQO
();
//操作项
params
.
setMenuType
(
2
);
params
.
setMenuType
(
MenuTypeEnum
.
OPERATION
.
getCode
()
);
List
<
TabSysMenu
>
allOper
=
menuService
.
listMenu
(
params
);
if
(
tabSysUser
!=
null
&&
tabSysUser
.
getLoginType
().
intValue
()
!=
0
)
{
//运营人员的部门职位;根据手机号查询运维人员的部门职位信息
GicUserDTO
gicUserDTO
=
gicUserService
.
getUserByMobile
(
tabSysUser
.
getPhoneNumber
());
LOGGER
.
info
(
"运维人员的部门职位数据:{}"
,
JSON
.
toJSONString
(
gicUserDTO
));
//如果是运营人员
Set
<
String
>
departPosition
=
new
HashSet
<>(
2
);
String
departmentCode
=
gicUserDTO
.
getDepartmentCode
();
if
(
StringUtils
.
isNotBlank
(
departmentCode
))
{
if
(
StringUtils
.
isBlank
(
gicUserDTO
.
getPositionCode
()))
{
//如果职位code是空,则取下面全部的职位code
List
<
GicDepartmentDTO
>
gicDepartmentDTOList
=
gicDepartmentService
.
listAllGicDepartment
();
if
(
CollectionUtils
.
isNotEmpty
(
gicDepartmentDTOList
))
{
Map
<
String
,
List
<
GicPositionDTO
>>
departMap
=
gicDepartmentDTOList
.
stream
()
.
collect
(
Collectors
.
toMap
(
e
->
e
.
getDepartmentCode
(),
e
->
e
.
getPositionList
()));
List
<
GicPositionDTO
>
positionList
=
departMap
.
get
(
departmentCode
);
if
(
CollectionUtils
.
isNotEmpty
(
positionList
))
{
positionList
.
forEach
(
e
->
{
departPosition
.
add
(
departmentCode
+
DELIMITER
+
e
.
getPositionCode
());
});
}
}
}
else
{
departPosition
.
add
(
departmentCode
+
DELIMITER
+
gicUserDTO
.
getPositionCode
());
}
}
boolean
isOperationUser
=
tabSysUser
.
getLoginType
().
intValue
()
!=
0
;
if
(
isOperationUser
)
{
//运营人员的部门职位
Set
<
String
>
departPosition
=
getLoginOperationDepartPosition
(
tabSysUser
.
getPhoneNumber
());
//过滤运营人员的部门职位权限
Map
<
String
,
List
<
TabSysMenuAuthDepart
>>
departMap
=
getAuthDepartMap
(
null
);
return
ServiceResponse
.
success
(
EntityUtil
.
changeEntityListNew
(
MenuDTO
.
class
,
allOper
.
stream
().
filter
(
e
->
{
...
...
@@ -1485,8 +1471,8 @@ public class MenuApiServiceImpl implements MenuApiService {
}
return
true
;
}).
collect
(
Collectors
.
toList
())));
}
else
if
(
tabSysUser
!=
null
&&
tabSysUser
.
getSuperAdmin
().
intValue
()
==
1
)
{
//超级管理员
}
else
{
//
gic
超级管理员
return
ServiceResponse
.
success
(
EntityUtil
.
changeEntityListNew
(
MenuDTO
.
class
,
allOper
.
stream
().
filter
(
e
->
e
.
getAuthType
().
intValue
()
==
3
).
collect
(
Collectors
.
toList
())));
}
}
...
...
gic-platform-auth-web/src/main/java/com/gic/auth/web/controller/LoginController.java
View file @
e080d85d
...
...
@@ -29,6 +29,7 @@ import com.gic.enterprise.utils.UserDetailUtils;
import
com.gic.member.config.api.service.AppletsConfigApiService
;
import
com.gic.member.config.api.service.MemberCardApiService
;
import
com.gic.member.config.api.service.ServiceConfigApiService
;
import
com.gic.redis.data.util.RedisUtil
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -41,6 +42,8 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
*
* @ClassName: LoginController
...
...
@@ -73,6 +76,8 @@ public class LoginController {
@Autowired
private
ServiceConfigApiService
serviceConfigApiService
;
private
static
final
String
MENU_LOCAL_CACHE_KEY
=
"auth:menu:list:all"
;
@RequestMapping
(
"list-enterprise-by-phone"
)
public
RestResponse
listUserEnterprise
(
String
phoneNumber
,
String
nationCode
)
{
if
(
StringUtils
.
isBlank
(
phoneNumber
))
{
...
...
@@ -150,43 +155,22 @@ public class LoginController {
}
if
(
enterpriseDTO
!=
null
)
{
userDetail
.
setEnterpriseInfo
(
EntityUtil
.
changeEntityNew
(
EnterpriseInfo
.
class
,
enterpriseDTO
));
//登录用户所拥有的权限菜单和操作项(接口)
ServiceResponse
<
List
<
MenuDTO
>>
menuResult
=
menuApiService
.
listUserMenu
(
userDetail
.
getUserId
(),
enterpriseDTO
.
getVersionCode
());
if
(
menuResult
.
isSuccess
())
{
List
<
MenuDTO
>
menuList
=
menuResult
.
getResult
();
List
<
MenuInfo
>
menuInfoList
=
EntityUtil
.
changeEntityListNew
(
MenuInfo
.
class
,
menuList
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
16
);
if
(
CollectionUtils
.
isNotEmpty
(
menuInfoList
))
{
for
(
MenuInfo
menuDTO
:
menuInfoList
)
{
if
(
StringUtils
.
isBlank
(
menuDTO
.
getMenuUrl
()))
{
continue
;
}
map
.
put
(
menuDTO
.
getMenuUrl
(),
menuDTO
);
}
}
//查询全部的操作模块
Map
<
String
,
MenuInfo
>
moduleMap
=
new
HashMap
<>(
16
);
ServiceResponse
<
List
<
MenuDTO
>>
allGicMenu
=
menuApiService
.
getAllMenuNotTree
(
enterpriseDTO
.
getVersionCode
());
if
(
allGicMenu
.
isSuccess
())
{
List
<
MenuDTO
>
temp
=
allGicMenu
.
getResult
();
List
<
MenuInfo
>
tempMenuInfoList
=
EntityUtil
.
changeEntityListNew
(
MenuInfo
.
class
,
temp
);
if
(
CollectionUtils
.
isNotEmpty
(
tempMenuInfoList
))
{
for
(
MenuInfo
menuDTO
:
tempMenuInfoList
)
{
if
(
StringUtils
.
isBlank
(
menuDTO
.
getMenuUrl
()))
{
continue
;
}
moduleMap
.
put
(
menuDTO
.
getProjectUrlForWeb
()
+
menuDTO
.
getMenuUrl
(),
menuDTO
);
}
}
userDetail
.
setMenuInfoList
(
tempMenuInfoList
);
}
Set
<
Integer
>
menuIdSet
=
new
HashSet
<>(
2
);
if
(
CollectionUtils
.
isNotEmpty
(
menuList
))
{
menuIdSet
=
menuList
.
stream
().
filter
(
e
->
StringUtils
.
isNotBlank
(
e
.
getMenuUrl
()))
.
map
(
e
->
e
.
getMenuId
()).
collect
(
Collectors
.
toSet
());
}
//塞用户权限菜单值
userDetail
.
setMenuIdSet
(
menuIdSet
);
//塞本地缓存
setAllMenuToLocaleCache
();
//设置用户资源组
this
.
setUserResource
(
userDetail
,
userDetail
.
getUserId
());
//塞值
userDetail
.
setMenuUrlMap
(
map
);
userDetail
.
setModuleUrlMap
(
moduleMap
);
}
//塞缓存
UserDetailUtils
.
setUserDetail
(
userDetail
);
...
...
@@ -234,6 +218,19 @@ public class LoginController {
return
RestResponse
.
failure
(
ErrorCode
.
PARAMETER_ERROR
.
getCode
(),
"token错误"
);
}
/**
* gic平台的菜单数据塞本地缓存
*/
private
void
setAllMenuToLocaleCache
()
{
ServiceResponse
<
List
<
MenuDTO
>>
response
=
menuApiService
.
getAllMenu
();
if
(
response
.
isSuccess
())
{
List
<
MenuDTO
>
list
=
response
.
getResult
();
//gic平台的菜单数据塞本地缓存
RedisUtil
.
delLocalCache
(
MENU_LOCAL_CACHE_KEY
);
RedisUtil
.
setLocalCache
(
MENU_LOCAL_CACHE_KEY
,
EntityUtil
.
changeEntityListNew
(
MenuInfo
.
class
,
list
),
null
);
}
}
private
void
setUserResource
(
UserDetail
detail
,
Integer
userId
)
{
ServiceResponse
<
UserResourceDTO
>
resource
=
this
.
userResourceApiService
.
getResourceByUserId
(
userId
);
detail
.
setUserResourceInfo
(
new
UserResourceInfo
());
...
...
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