Commit e080d85d by guojuxing

权限菜单刷本地缓存

parent d8ce25f6
...@@ -55,7 +55,7 @@ public interface MenuApiService { ...@@ -55,7 +55,7 @@ public interface MenuApiService {
ServiceResponse<Set<String>> getAppIdSetByUserId(Integer userId); ServiceResponse<Set<String>> getAppIdSetByUserId(Integer userId);
/** /**
* 查询用户拥有的所有菜单路由权限,用于登录用户session用 * 查询用户没有权限的操作项(接口),用于登录用户session用
* @Title: listUserMenu
 * @Title: listUserMenu

* @Description: * @Description:

 * @author guojuxing 
 * @author guojuxing
...@@ -194,6 +194,15 @@ public interface MenuApiService { ...@@ -194,6 +194,15 @@ public interface MenuApiService {
ServiceResponse<List<MenuDTO>> getAllMenuNotTree(String versionCode); 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 * @param enterpriseId
* @return * @return
......
...@@ -29,6 +29,7 @@ import com.gic.enterprise.utils.UserDetailUtils; ...@@ -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.AppletsConfigApiService;
import com.gic.member.config.api.service.MemberCardApiService; import com.gic.member.config.api.service.MemberCardApiService;
import com.gic.member.config.api.service.ServiceConfigApiService; 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.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
...@@ -41,6 +42,8 @@ import javax.servlet.http.HttpServletRequest; ...@@ -41,6 +42,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* *
* @ClassName: LoginController * @ClassName: LoginController
...@@ -73,6 +76,8 @@ public class LoginController { ...@@ -73,6 +76,8 @@ public class LoginController {
@Autowired @Autowired
private ServiceConfigApiService serviceConfigApiService; private ServiceConfigApiService serviceConfigApiService;
private static final String MENU_LOCAL_CACHE_KEY = "auth:menu:list:all";
@RequestMapping("list-enterprise-by-phone") @RequestMapping("list-enterprise-by-phone")
public RestResponse listUserEnterprise(String phoneNumber, String nationCode) { public RestResponse listUserEnterprise(String phoneNumber, String nationCode) {
if (StringUtils.isBlank(phoneNumber)) { if (StringUtils.isBlank(phoneNumber)) {
...@@ -150,43 +155,22 @@ public class LoginController { ...@@ -150,43 +155,22 @@ public class LoginController {
} }
if (enterpriseDTO != null) { if (enterpriseDTO != null) {
userDetail.setEnterpriseInfo(EntityUtil.changeEntityNew(EnterpriseInfo.class, enterpriseDTO)); userDetail.setEnterpriseInfo(EntityUtil.changeEntityNew(EnterpriseInfo.class, enterpriseDTO));
//登录用户所拥有的权限菜单和操作项(接口)
ServiceResponse<List<MenuDTO>> menuResult = menuApiService.listUserMenu(userDetail.getUserId(), ServiceResponse<List<MenuDTO>> menuResult = menuApiService.listUserMenu(userDetail.getUserId(),
enterpriseDTO.getVersionCode()); enterpriseDTO.getVersionCode());
if (menuResult.isSuccess()) { if (menuResult.isSuccess()) {
List<MenuDTO> menuList = menuResult.getResult(); List<MenuDTO> menuList = menuResult.getResult();
List<MenuInfo> menuInfoList = EntityUtil.changeEntityListNew(MenuInfo.class, menuList); Set<Integer> menuIdSet = new HashSet<>(2);
Map<String, Object> map = new HashMap<>(16); if (CollectionUtils.isNotEmpty(menuList)) {
if (CollectionUtils.isNotEmpty(menuInfoList)) { menuIdSet = menuList.stream().filter(e -> StringUtils.isNotBlank(e.getMenuUrl()))
for (MenuInfo menuDTO : menuInfoList) { .map(e -> e.getMenuId()).collect(Collectors.toSet());
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);
} }
//塞用户权限菜单值
userDetail.setMenuIdSet(menuIdSet);
//塞本地缓存
setAllMenuToLocaleCache();
//设置用户资源组 //设置用户资源组
this.setUserResource(userDetail, userDetail.getUserId()); this.setUserResource(userDetail, userDetail.getUserId());
//塞值
userDetail.setMenuUrlMap(map);
userDetail.setModuleUrlMap(moduleMap);
} }
//塞缓存 //塞缓存
UserDetailUtils.setUserDetail(userDetail); UserDetailUtils.setUserDetail(userDetail);
...@@ -234,6 +218,19 @@ public class LoginController { ...@@ -234,6 +218,19 @@ public class LoginController {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "token错误"); 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) { private void setUserResource(UserDetail detail, Integer userId) {
ServiceResponse<UserResourceDTO> resource = this.userResourceApiService.getResourceByUserId(userId); ServiceResponse<UserResourceDTO> resource = this.userResourceApiService.getResourceByUserId(userId);
detail.setUserResourceInfo(new UserResourceInfo()); detail.setUserResourceInfo(new UserResourceInfo());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment