mirror of https://gitee.com/stylefeng/roses
【8.0】【sys】【menu】菜单编码获取增加缓存
parent
c30732b3ba
commit
286ca0329d
|
@ -0,0 +1,21 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.cache;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 监听菜单的清空
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/15 0:08
|
||||
*/
|
||||
@Service
|
||||
public class MenuClearListener {
|
||||
|
||||
@Resource(name = "menuCodeCache")
|
||||
private CacheOperatorApi<String> menuCodeCache;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.cache.menucode;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.constants.MenuConstants;
|
||||
|
||||
/**
|
||||
* 菜单编码的缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/15 0:08
|
||||
*/
|
||||
public class MenuCodeMemoryCache extends AbstractMemoryCacheOperator<String> {
|
||||
|
||||
public MenuCodeMemoryCache(TimedCache<String, String> timedCache) {
|
||||
super(timedCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return MenuConstants.MENU_CODE_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.cache.menucode;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.constants.MenuConstants;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* 菜单编码的缓存
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/15 0:11
|
||||
*/
|
||||
public class MenuCodeRedisCache extends AbstractRedisCacheOperator<String> {
|
||||
|
||||
public MenuCodeRedisCache(RedisTemplate<String, String> redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return MenuConstants.MENU_CODE_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.menu.constants;
|
||||
|
||||
/**
|
||||
* 菜单的常量
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/15 0:09
|
||||
*/
|
||||
public interface MenuConstants {
|
||||
|
||||
/**
|
||||
* 菜单编码的前缀
|
||||
*/
|
||||
String MENU_CODE_CACHE_PREFIX = "MENU:CODE:";
|
||||
|
||||
}
|
|
@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
import cn.stylefeng.roses.kernel.rule.tree.buildpids.PidStructureBuildUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.callback.RemoveMenuCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.SysConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.menu.UserAppMenuInfo;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.app.service.SysAppService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.menu.entity.SysMenu;
|
||||
|
@ -45,6 +47,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Resource
|
||||
private DbOperatorApi dbOperatorApi;
|
||||
|
||||
@Resource(name = "menuCodeCache")
|
||||
private CacheOperatorApi<String> menuCodeCache;
|
||||
|
||||
@Override
|
||||
public void add(SysMenuRequest sysMenuRequest) {
|
||||
|
||||
|
@ -197,16 +202,43 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Override
|
||||
public List<String> getMenuCodeList(List<Long> menuIdList) {
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
if (ObjectUtil.isEmpty(menuIdList)) {
|
||||
return new ArrayList<>();
|
||||
return result;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<SysMenu> sysMenuLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysMenuLambdaQueryWrapper.in(SysMenu::getMenuId, menuIdList);
|
||||
sysMenuLambdaQueryWrapper.select(SysMenu::getMenuCode);
|
||||
List<SysMenu> sysMenuList = this.list(sysMenuLambdaQueryWrapper);
|
||||
for (Long menuId : menuIdList) {
|
||||
|
||||
return sysMenuList.stream().map(SysMenu::getMenuCode).collect(Collectors.toList());
|
||||
String menuIdKey = menuId.toString();
|
||||
|
||||
// 先从缓存查询,是否有菜单编码
|
||||
String menuCode = menuCodeCache.get(menuIdKey);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(menuCode)) {
|
||||
result.add(menuCode);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 查询库中的菜单编码
|
||||
LambdaQueryWrapper<SysMenu> sysMenuLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysMenuLambdaQueryWrapper.eq(SysMenu::getMenuId, menuIdList);
|
||||
sysMenuLambdaQueryWrapper.select(SysMenu::getMenuCode);
|
||||
SysMenu sysMenu = this.getOne(sysMenuLambdaQueryWrapper, false);
|
||||
|
||||
if (sysMenu != null) {
|
||||
String menuCodeQueryResult = sysMenu.getMenuCode();
|
||||
if (ObjectUtil.isNotEmpty(menuCodeQueryResult)) {
|
||||
|
||||
result.add(menuCodeQueryResult);
|
||||
|
||||
// 添加到缓存一份
|
||||
menuCodeCache.put(menuIdKey, menuCodeQueryResult, SysConstants.DEFAULT_SYS_CACHE_TIMEOUT_SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue