From a0a1283970a280fb45f6d7946655c4c5c51b7015 Mon Sep 17 00:00:00 2001 From: ZhengJie <201507802@qq.com> Date: Sun, 6 Sep 2020 17:19:57 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84](v2.5):?= =?UTF-8?q?=20update=20menu=E3=80=81dept=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close https://github.com/elunez/eladmin/issues/468 --- .../system/service/impl/DeptServiceImpl.java | 12 +++--------- .../system/service/impl/MenuServiceImpl.java | 13 +++---------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java index ec2338f7..ac2bcbe2 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java @@ -96,7 +96,6 @@ public class DeptServiceImpl implements DeptService { } @Override - @Cacheable(key = "'pid:' + #p0") public List findByPid(long pid) { return deptRepository.findByPid(pid); } @@ -113,7 +112,6 @@ public class DeptServiceImpl implements DeptService { // 计算子节点数目 resources.setSubCount(0); // 清理缓存 - redisUtils.del("dept::pid:" + (resources.getPid() == null ? 0 : resources.getPid())); updateSubCnt(resources.getPid()); } @@ -134,7 +132,7 @@ public class DeptServiceImpl implements DeptService { updateSubCnt(oldPid); updateSubCnt(newPid); // 清理缓存 - delCaches(resources.getId(), oldPid, newPid); + delCaches(resources.getId()); } @Override @@ -142,7 +140,7 @@ public class DeptServiceImpl implements DeptService { public void delete(Set deptDtos) { for (DeptDto deptDto : deptDtos) { // 清理缓存 - delCaches(deptDto.getId(), deptDto.getPid(), null); + delCaches(deptDto.getId()); deptRepository.deleteById(deptDto.getId()); updateSubCnt(deptDto.getPid()); } @@ -273,15 +271,11 @@ public class DeptServiceImpl implements DeptService { /** * 清理缓存 * @param id / - * @param oldPid / - * @param newPid / */ - public void delCaches(Long id, Long oldPid, Long newPid){ + public void delCaches(Long id){ List users = userRepository.findByDeptRoleId(id); // 删除数据权限 redisUtils.delByKeys("data::user:",users.stream().map(User::getId).collect(Collectors.toSet())); redisUtils.del("dept::id:" + id); - redisUtils.del("dept::pid:" + (oldPid == null ? 0 : oldPid)); - redisUtils.del("dept::pid:" + (newPid == null ? 0 : newPid)); } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java index 386d06c3..f0ce9f71 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java @@ -128,7 +128,6 @@ public class MenuServiceImpl implements MenuService { resources.setSubCount(0); // 更新父节点菜单数目 updateSubCnt(resources.getPid()); - redisUtils.del("menu::pid:" + (resources.getPid() == null ? 0 : resources.getPid())); } @Override @@ -183,7 +182,7 @@ public class MenuServiceImpl implements MenuService { updateSubCnt(oldPid); updateSubCnt(newPid); // 清理缓存 - delCaches(resources.getId(), oldPid, newPid); + delCaches(resources.getId()); } @Override @@ -204,7 +203,7 @@ public class MenuServiceImpl implements MenuService { public void delete(Set menuSet) { for (Menu menu : menuSet) { // 清理缓存 - delCaches(menu.getId(), menu.getPid(), null); + delCaches(menu.getId()); roleService.untiedMenu(menu.getId()); menuRepository.deleteById(menu.getId()); updateSubCnt(menu.getPid()); @@ -212,7 +211,6 @@ public class MenuServiceImpl implements MenuService { } @Override - @Cacheable(key = "'pid:' + #p0") public List getMenus(Long pid) { List menus; if(pid != null && !pid.equals(0L)){ @@ -341,19 +339,14 @@ public class MenuServiceImpl implements MenuService { /** * 清理缓存 * @param id 菜单ID - * @param oldPid 旧的菜单父级ID - * @param newPid 新的菜单父级ID */ - public void delCaches(Long id, Long oldPid, Long newPid){ + public void delCaches(Long id){ List users = userRepository.findByMenuId(id); redisUtils.del("menu::id:" +id); redisUtils.delByKeys("menu::user:",users.stream().map(User::getId).collect(Collectors.toSet())); - redisUtils.del("menu::pid:" + (oldPid == null ? 0 : oldPid)); - redisUtils.del("menu::pid:" + (newPid == null ? 0 : newPid)); // 清除 Role 缓存 List roles = roleService.findInMenuId(new ArrayList(){{ add(id); - add(newPid == null ? 0 : newPid); }}); redisUtils.delByKeys("role::id:",roles.stream().map(Role::getId).collect(Collectors.toSet())); }