修复角色菜单临时接口
This commit is contained in:
@@ -0,0 +1,118 @@
|
|||||||
|
package com.cool.store.vo.menu;
|
||||||
|
|
||||||
|
import com.cool.store.entity.SysMenuDO;
|
||||||
|
import com.cool.store.enums.MenuTypeEnum;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.collections4.ListUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* describe:
|
||||||
|
*
|
||||||
|
* @author zhouyiping
|
||||||
|
* @date 2020/09/22
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MenuAuthTreeVO {
|
||||||
|
|
||||||
|
@ApiModelProperty("请求地址(前端路由)")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
@ApiModelProperty("菜单编号")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@ApiModelProperty("菜单名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("菜单id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty("父级菜单")
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
@ApiModelProperty("是否新开页面")
|
||||||
|
private String target;
|
||||||
|
|
||||||
|
@ApiModelProperty("组件")
|
||||||
|
private String component;
|
||||||
|
|
||||||
|
@ApiModelProperty("图标'")
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
@ApiModelProperty("常用功能图标")
|
||||||
|
private String commonFunctionsIcon;
|
||||||
|
|
||||||
|
@ApiModelProperty("菜单类型 1菜单 2权限")
|
||||||
|
private Integer menuType;
|
||||||
|
|
||||||
|
@ApiModelProperty("权限列表")
|
||||||
|
private List<MenuAuthTreeVO> authorityList;
|
||||||
|
|
||||||
|
@ApiModelProperty("子菜单")
|
||||||
|
private List<MenuAuthTreeVO> children;
|
||||||
|
|
||||||
|
public static List<MenuAuthTreeVO> dealMenuTree(Long rootId, List<SysMenuDO> menuList) {
|
||||||
|
if(CollectionUtils.isEmpty(menuList)){
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
|
Map<Long, List<SysMenuDO>> parentGroup = ListUtils.emptyIfNull(menuList).stream().collect(Collectors.groupingBy(SysMenuDO::getParentId));
|
||||||
|
List<SysMenuDO> menuDOList = parentGroup.get(rootId);
|
||||||
|
if (CollectionUtils.isEmpty(menuDOList)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<MenuAuthTreeVO> voList = convertVO(menuDOList);
|
||||||
|
List<MenuAuthTreeVO> treeVOList = new LinkedList<>(voList);
|
||||||
|
for (MenuAuthTreeVO data : treeVOList) {
|
||||||
|
getChild(data, parentGroup);
|
||||||
|
}
|
||||||
|
return treeVOList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<MenuAuthTreeVO> convertVO(List<SysMenuDO> menuList) {
|
||||||
|
menuList = menuList.stream().sorted(Comparator.comparing(SysMenuDO::getSort)).collect(Collectors.toList());
|
||||||
|
List<MenuAuthTreeVO> resultList = new ArrayList<>();
|
||||||
|
for (SysMenuDO menu : menuList) {
|
||||||
|
MenuAuthTreeVO vo = new MenuAuthTreeVO();
|
||||||
|
vo.setId(menu.getId());
|
||||||
|
vo.setParentId(menu.getParentId());
|
||||||
|
vo.setName(menu.getName());
|
||||||
|
vo.setCode(menu.getType());
|
||||||
|
vo.setPath(menu.getPath());
|
||||||
|
vo.setComponent(menu.getComponent());
|
||||||
|
vo.setTarget(menu.getTarget());
|
||||||
|
vo.setIcon(menu.getIcon());
|
||||||
|
vo.setMenuType(menu.getMenuType());
|
||||||
|
vo.setCommonFunctionsIcon(menu.getCommonFunctionsIcon());
|
||||||
|
resultList.add(vo);
|
||||||
|
}
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getChild(MenuAuthTreeVO data, Map<Long, List<SysMenuDO>> parentGroup) {
|
||||||
|
List<SysMenuDO> sysMenuDOList = parentGroup.get(data.getId());
|
||||||
|
List<SysMenuDO> parentMenuList = ListUtils.emptyIfNull(sysMenuDOList).stream().filter(menu -> MenuTypeEnum.MENU.getCode().equals(menu.getMenuType())).collect(Collectors.toList());
|
||||||
|
List<SysMenuDO> parentAuthList = ListUtils.emptyIfNull(sysMenuDOList).stream().filter(menu -> MenuTypeEnum.AUTH.getCode().equals(menu.getMenuType())).collect(Collectors.toList());
|
||||||
|
//属于菜单下时候
|
||||||
|
if (CollectionUtils.isNotEmpty(parentMenuList)) {
|
||||||
|
List<MenuAuthTreeVO> voList = convertVO(parentMenuList);
|
||||||
|
List<MenuAuthTreeVO> authorityList = convertVO(parentMenuList);
|
||||||
|
data.setAuthorityList(authorityList);
|
||||||
|
List<MenuAuthTreeVO> menuList = voList.stream().filter(vo -> MenuTypeEnum.MENU.getCode().equals(vo.getMenuType())).collect(Collectors.toList());
|
||||||
|
data.setChildren(menuList);
|
||||||
|
voList.forEach(child -> {
|
||||||
|
getChild(child, parentGroup);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//数据是权限的的时候
|
||||||
|
if (CollectionUtils.isNotEmpty(parentAuthList)) {
|
||||||
|
List<MenuAuthTreeVO> authorityList = convertVO(parentAuthList);
|
||||||
|
data.setAuthorityList(authorityList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.cool.store.service;
|
|||||||
|
|
||||||
import com.cool.store.dto.menu.AddMenuDTO;
|
import com.cool.store.dto.menu.AddMenuDTO;
|
||||||
import com.cool.store.enums.MenuTypeEnum;
|
import com.cool.store.enums.MenuTypeEnum;
|
||||||
|
import com.cool.store.vo.menu.MenuAuthTreeVO;
|
||||||
import com.cool.store.vo.menu.MenuTreeVO;
|
import com.cool.store.vo.menu.MenuTreeVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,7 +27,7 @@ public interface MenuService {
|
|||||||
* 获取所有的菜单
|
* 获取所有的菜单
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<MenuTreeVO> getAllMenus();
|
List<MenuAuthTreeVO> getAllMenus();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增菜单
|
* 新增菜单
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.cool.store.entity.SysRoleMenuDO;
|
|||||||
import com.cool.store.enums.MenuTypeEnum;
|
import com.cool.store.enums.MenuTypeEnum;
|
||||||
import com.cool.store.enums.PlatFormTypeEnum;
|
import com.cool.store.enums.PlatFormTypeEnum;
|
||||||
import com.cool.store.service.MenuService;
|
import com.cool.store.service.MenuService;
|
||||||
|
import com.cool.store.vo.menu.MenuAuthTreeVO;
|
||||||
import com.cool.store.vo.menu.MenuTreeVO;
|
import com.cool.store.vo.menu.MenuTreeVO;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -53,9 +54,9 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MenuTreeVO> getAllMenus() {
|
public List<MenuAuthTreeVO> getAllMenus() {
|
||||||
List<SysMenuDO> menuList= sysMenuDAO.selectMenuAll(null, PlatFormTypeEnum.PC.getCode());
|
List<SysMenuDO> menuList= sysMenuDAO.selectMenuAll(null, PlatFormTypeEnum.PC.getCode());
|
||||||
return MenuTreeVO.dealMenuTree(CommonConstants.ZERO_LONG, menuList);
|
return MenuAuthTreeVO.dealMenuTree(CommonConstants.ZERO_LONG, menuList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user