Commit a0a12839 authored by ZhengJie's avatar ZhengJie
Browse files

[代码完善](v2.5): update menu、dept cache

close https://github.com/elunez/eladmin/issues/468
parent c680ec4e
......@@ -96,7 +96,6 @@ public class DeptServiceImpl implements DeptService {
}
@Override
@Cacheable(key = "'pid:' + #p0")
public List<Dept> 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<DeptDto> 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<User> 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
......@@ -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<Menu> 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<MenuDto> getMenus(Long pid) {
List<Menu> 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<User> 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<Role> roles = roleService.findInMenuId(new ArrayList<Long>(){{
add(id);
add(newPid == null ? 0 : newPid);
}});
redisUtils.delByKeys("role::id:",roles.stream().map(Role::getId).collect(Collectors.toSet()));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment