!16 解决由于mybatis-plus无法过滤软删除导致角色去掉菜单缓存未刷新的问题。

Merge pull request !16 from dxyx/master
This commit is contained in:
芋道源码 2021-03-17 23:06:04 +08:00 committed by Gitee
commit f5331ce6ac
2 changed files with 7 additions and 7 deletions

View File

@ -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;
@ -41,9 +42,7 @@ public interface SysRoleMenuMapper extends BaseMapperX<SysRoleMenuDO> {
delete(new QueryWrapper<SysRoleMenuDO>().eq("role_id", roleId));
}
default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) {
return selectOne(new QueryWrapper<SysRoleMenuDO>().select("id")
.gt("update_time", maxUpdateTime).last("LIMIT 1")) != null;
}
@Select("SELECT id FROM sys_role_menu WHERE update_time > #{maxUpdateTime} LIMIT 1")
Long selectExistsByUpdateTimeAfter(Date maxUpdateTime);
}

View File

@ -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)) {
if (Objects.isNull(roleMenuMapper.selectExistsByUpdateTimeAfter(maxUpdateTime))) {
return null;
}
log.info("[loadRoleMenuIfUpdate][增量加载全量角色与菜单的关联]");