From 49f25a88704b79a6713bbd4835a0359d5b629921 Mon Sep 17 00:00:00 2001 From: asas6559 <302811456@qq.com> Date: Wed, 17 Mar 2021 21:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=94=B1=E4=BA=8Emybatis-plu?= =?UTF-8?q?s=E6=97=A0=E6=B3=95=E8=BF=87=E6=BB=A4=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AF=BC=E8=87=B4=E8=A7=92=E8=89=B2=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=BC=93=E5=AD=98=E6=9C=AA=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/dal/mysql/permission/SysRoleMenuMapper.java | 5 +++-- .../service/permission/impl/SysPermissionServiceImpl.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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][增量加载全量角色与菜单的关联]");