|
@@ -18,10 +18,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -167,6 +164,41 @@ public class SysMenuServiceImpl extends ServiceImpl<ISysMenuMapper, SysMenu> imp
|
|
|
|
|
|
@Override
|
|
|
public List<Long> getMenuIdsByRoleId(Long roleId) {
|
|
|
- return roleMenuService.getButtonIdsByRoleId(roleId);
|
|
|
+ List<SysRoleMenu> roleMenus = roleMenuService.getByRoleId(roleId);
|
|
|
+ if(roleMenus.size() <=0){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ Set<Long> menuIds = roleMenus.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toSet());
|
|
|
+ HashMap<Long, SysMenu> menuMap = this.getByIds(new ArrayList<>(menuIds));
|
|
|
+
|
|
|
+ Set<Long> setParentIds = new HashSet<>();
|
|
|
+ List<Long> returnMenuIds = new ArrayList<>();
|
|
|
+ List<Long> delMenuIds = new ArrayList<>();
|
|
|
+ //如果父菜单不包含全部子菜单,将父菜单移除,不返回前端
|
|
|
+ for (Long menuId : menuMap.keySet()) {
|
|
|
+ Long parentId = menuMap.get(menuId).getParentId();
|
|
|
+ if(parentId != null && menuMap.containsKey(parentId) && !setParentIds.contains(parentId)){
|
|
|
+ setParentIds.add(parentId);
|
|
|
+ List<SysMenu> menuList = this.getBySonById(parentId);
|
|
|
+ for (SysMenu sysMenu : menuList) {
|
|
|
+ if(!menuMap.containsKey(sysMenu.getId()) ){
|
|
|
+ delMenuIds.add(parentId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Long menuId : menuIds) {
|
|
|
+ if(!delMenuIds.contains(menuId)){
|
|
|
+ returnMenuIds.add(menuId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return returnMenuIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SysMenu> getBySonById(Long parentId) {
|
|
|
+ LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SysMenu::getParentId,parentId);
|
|
|
+ return this.list(wrapper);
|
|
|
}
|
|
|
}
|