Commit cbbee0fa by guojuxing

权限菜单刷本地缓存

parent 9ebfee33
package com.gic.operation.web.controller; package com.gic.operation.web.controller;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import java.util.Map;
import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService; import com.ctrip.framework.apollo.ConfigService;
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;
...@@ -58,6 +58,8 @@ public class LoginController { ...@@ -58,6 +58,8 @@ public class LoginController {
@Autowired @Autowired
private MarketUserApiService marketUserApiService; private MarketUserApiService marketUserApiService;
private static final String MENU_LOCAL_CACHE_KEY = "auth:menu:list:all";
/** /**
* 商户绑定服务市场 * 商户绑定服务市场
...@@ -153,35 +155,15 @@ public class LoginController { ...@@ -153,35 +155,15 @@ public class LoginController {
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.setMenuUrlMap(map); userDetail.setMenuIdSet(menuIdSet);
userDetail.setModuleUrlMap(moduleMap); //塞本地缓存
setAllMenuToLocaleCache();
} }
} }
//塞缓存 //塞缓存
...@@ -194,4 +176,17 @@ public class LoginController { ...@@ -194,4 +176,17 @@ public class LoginController {
} }
return RestResponse.success(); return RestResponse.success();
} }
/**
* 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);
}
}
} }
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