| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.execption.EntityExistException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.param.MenuParam; |
| | | import com.sandu.ximon.dao.bo.MenuNode; |
| | | import com.sandu.ximon.dao.domain.AdminRoleRelation; |
| | | import com.sandu.ximon.dao.domain.Menu; |
| | | import com.sandu.ximon.dao.domain.RoleMenuRelation; |
| | | import com.sandu.ximon.dao.mapper.AdminRoleRelationMapper; |
| | | import com.sandu.ximon.dao.mapper.MenuMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | |
| | | if (CollectionUtil.isEmpty(menuIdList)) { |
| | | return null; |
| | | } |
| | | List<Menu> menus = listByIds(menuIdList); |
| | | return menus; |
| | | return listByIds(menuIdList); |
| | | } |
| | | |
| | | public boolean addMenu(MenuParam param) { |
| | | Menu menu = new Menu(); |
| | | BeanUtils.copyProperties(param,menu); |
| | | return save(menu); |
| | | } |
| | | |
| | | // public Set<Menu> listMenuByRoles(Set<Role> roles) { |
| | | // List<Long> roleIds = roles.stream().map(Role::getId).collect(Collectors.toList()); |
| | | // Set<Menu> menus = menuDao.listMenuByRoleIds(roleIds); |
| | | // return menus; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 把菜单转成树形结构 |
| | | // */ |
| | | // public List<MenuNode> buildTree(List<Menu> menuList) { |
| | | // return menuList.stream() |
| | | // .filter(menu -> menu.getPid().equals(0L)) |
| | | // .map(menu -> covertMenuNode(menu, menuList)).collect(Collectors.toList()); |
| | | // } |
| | | |
| | | private MenuNode covertMenuNode(Menu menu, List<Menu> menuList) { |
| | | MenuNode node = new MenuNode(); |
| | | BeanUtils.copyProperties(menu, node); |
| | | List<MenuNode> children = menuList.stream() |
| | | .filter(subMenu -> subMenu.getPid().equals(menu.getId())) |
| | | .map(subMenu -> covertMenuNode(subMenu, menuList)).collect(Collectors.toList()); |
| | | node.setChildren(children); |
| | | return node; |
| | | } |
| | | |
| | | public boolean updateMenu(Long menuId,MenuParam param) { |
| | | Menu one = getById(menuId); |
| | | if (one == null) { |
| | | throw new BusinessException("找不到菜单信息"); |
| | | } |
| | | |
| | | Menu menu = new Menu(); |
| | | BeanUtils.copyProperties(param,menu); |
| | | menu.setId(menuId); |
| | | return updateById(menu); |
| | | } |
| | | |
| | | public List<MenuNode> treeList() { |
| | | List<Menu> list = list(); |
| | | return list.stream() |
| | | .filter(menu -> menu.getPid().equals(0L)) |
| | | .map(menu -> covertMenuNode(menu, list)).collect(Collectors.toList()); |
| | | } |
| | | } |