diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/permission/SysRoleMenuMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/permission/SysRoleMenuMapper.java index e6bdc56cd..977243aa6 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/permission/SysRoleMenuMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/permission/SysRoleMenuMapper.java @@ -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 { .in("menu_id", menuIds)); } - @Select("select id from sys_role_menu where update_time > #{maxUpdateTime} limit 1") - List selectExistsByUpdateTimeAfter(Date maxUpdateTime); + @Select("SELECT id FROM sys_role_menu WHERE update_time > #{maxUpdateTime} LIMIT 1") + Long selectExistsByUpdateTimeAfter(Date maxUpdateTime); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java index 835fb8961..fc66f5c32 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java @@ -86,6 +86,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { @Override @PostConstruct public void initLocalCache() { + Date now = new Date(); // 获取角色与菜单的关联列表,如果有更新 List 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][增量加载全量角色与菜单的关联]");