| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.TreeSelect; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.TreeBuildUtils; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | | import com.ruoyi.system.domain.vo.MetaVo; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 菜单 业务层处理 |
| | |
| | | // 管理员显示所有菜单信息 |
| | | if (SysUser.isAdmin(userId)) { |
| | | menuList = list(new LambdaQueryWrapper<SysMenu>() |
| | | .like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible()) |
| | | .eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus()) |
| | | .orderByAsc(SysMenu::getParentId) |
| | | .orderByAsc(SysMenu::getOrderNum)); |
| | | .like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible()) |
| | | .eq(StringUtils.isNotBlank(menu.getStatus()), SysMenu::getStatus, menu.getStatus()) |
| | | .orderByAsc(SysMenu::getParentId) |
| | | .orderByAsc(SysMenu::getOrderNum)); |
| | | } else { |
| | | menu.getParams().put("userId", userId); |
| | | menuList = baseMapper.selectMenuListByUserId(menu); |
| | |
| | | * @return 选中菜单列表 |
| | | */ |
| | | @Override |
| | | public List<Integer> selectMenuListByRoleId(Long roleId) { |
| | | public List<Long> selectMenuListByRoleId(Long roleId) { |
| | | SysRole role = roleMapper.selectById(roleId); |
| | | return baseMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 构建前端所需要树结构 |
| | | * |
| | | * @param menus 菜单列表 |
| | | * @return 树结构列表 |
| | | */ |
| | | @Override |
| | | public List<SysMenu> buildMenuTree(List<SysMenu> menus) { |
| | | List<SysMenu> returnList = new ArrayList<SysMenu>(); |
| | | List<Long> tempList = new ArrayList<Long>(); |
| | | for (SysMenu dept : menus) { |
| | | tempList.add(dept.getMenuId()); |
| | | } |
| | | for (SysMenu menu : menus) { |
| | | // 如果是顶级节点, 遍历该父节点的所有子节点 |
| | | if (!tempList.contains(menu.getParentId())) { |
| | | recursionFn(menus, menu); |
| | | returnList.add(menu); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) { |
| | | returnList = menus; |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | /** |
| | | * 构建前端所需要下拉树结构 |
| | | * |
| | | * @param menus 菜单列表 |
| | | * @return 下拉树结构列表 |
| | | */ |
| | | @Override |
| | | public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) { |
| | | List<SysMenu> menuTrees = buildMenuTree(menus); |
| | | return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); |
| | | public List<Tree<Long>> buildMenuTreeSelect(List<SysMenu> menus) { |
| | | return TreeBuildUtils.build(menus, (menu, tree) -> |
| | | tree.setId(menu.getMenuId()) |
| | | .setParentId(menu.getParentId()) |
| | | .setName(menu.getMenuName()) |
| | | .setWeight(menu.getOrderNum())); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public String checkMenuNameUnique(SysMenu menu) { |
| | | Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); |
| | | SysMenu info = getOne(new LambdaQueryWrapper<SysMenu>() |
| | | .eq(SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(SysMenu::getParentId, menu.getParentId()) |
| | | .last("limit 1")); |
| | | if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) { |
| | | long count = count(new LambdaQueryWrapper<SysMenu>() |
| | | .eq(SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(SysMenu::getParentId, menu.getParentId()) |
| | | .ne(SysMenu::getMenuId, menuId)); |
| | | if (count > 0) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | |
| | | } |
| | | // 非外链并且是一级目录(类型为目录) |
| | | if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) |
| | | && UserConstants.NO_FRAME.equals(menu.getIsFrame())) { |
| | | && UserConstants.NO_FRAME.equals(menu.getIsFrame())) { |
| | | routerPath = "/" + menu.getPath(); |
| | | } |
| | | // 非外链并且是一级目录(类型为菜单) |
| | |
| | | */ |
| | | public boolean isMenuFrame(SysMenu menu) { |
| | | return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) |
| | | && menu.getIsFrame().equals(UserConstants.NO_FRAME); |
| | | && menu.getIsFrame().equals(UserConstants.NO_FRAME); |
| | | } |
| | | |
| | | /** |