解决由于mybatis-plus无法过滤软删除导致角色去掉菜单缓存未刷新的问题
parent
bbea33e72e
commit
49f25a8870
|
@ -4,6 +4,7 @@ import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
|||
import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleMenuDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
@ -33,7 +34,7 @@ public interface SysRoleMenuMapper extends BaseMapperX<SysRoleMenuDO> {
|
|||
.in("menu_id", menuIds));
|
||||
}
|
||||
|
||||
@Select("select id from sys_role_menu where update_time > #{maxUpdateTime} limit 1")
|
||||
List<Long> selectExistsByUpdateTimeAfter(Date maxUpdateTime);
|
||||
@Select("SELECT id FROM sys_role_menu WHERE update_time > #{maxUpdateTime} LIMIT 1")
|
||||
Long selectExistsByUpdateTimeAfter(Date maxUpdateTime);
|
||||
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
|||
@Override
|
||||
@PostConstruct
|
||||
public void initLocalCache() {
|
||||
Date now = new Date();
|
||||
// 获取角色与菜单的关联列表,如果有更新
|
||||
List<SysRoleMenuDO> roleMenuList = this.loadRoleMenuIfUpdate(maxUpdateTime);
|
||||
if (CollUtil.isEmpty(roleMenuList)) {
|
||||
|
@ -102,7 +103,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
|||
roleMenuCache = roleMenuCacheBuilder.build();
|
||||
menuRoleCache = menuRoleCacheBuilder.build();
|
||||
assert roleMenuList.size() > 0; // 断言,避免告警
|
||||
maxUpdateTime = roleMenuList.stream().max(Comparator.comparing(BaseDO::getUpdateTime)).get().getUpdateTime();
|
||||
maxUpdateTime = now;
|
||||
log.info("[initLocalCache][初始化角色与菜单的关联数量为 {}]", roleMenuList.size());
|
||||
}
|
||||
|
||||
|
@ -123,7 +124,7 @@ public class SysPermissionServiceImpl implements SysPermissionService {
|
|||
if (maxUpdateTime == null) { // 如果更新时间为空,说明 DB 一定有新数据
|
||||
log.info("[loadRoleMenuIfUpdate][首次加载全量角色与菜单的关联]");
|
||||
} else { // 判断数据库中是否有更新的角色与菜单的关联
|
||||
if (roleMenuMapper.selectExistsByUpdateTimeAfter(maxUpdateTime).size() == 0) {
|
||||
if (Objects.isNull(roleMenuMapper.selectExistsByUpdateTimeAfter(maxUpdateTime))) {
|
||||
return null;
|
||||
}
|
||||
log.info("[loadRoleMenuIfUpdate][增量加载全量角色与菜单的关联]");
|
||||
|
|
Loading…
Reference in New Issue