| | |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | 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.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.helper.LoginHelper; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.TreeBuildUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.system.domain.SysMenu; |
| | | import com.ruoyi.system.domain.SysRole; |
| | | import com.ruoyi.common.satoken.utils.LoginHelper; |
| | | import com.ruoyi.common.core.utils.StreamUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.TreeBuildUtils; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | | import com.ruoyi.system.domain.vo.MetaVo; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | |
| | | public List<SysMenu> selectMenuList(SysMenu menu, Long userId) { |
| | | List<SysMenu> menuList = null; |
| | | // 管理员显示所有菜单信息 |
| | | if (SysUser.isAdmin(userId)) { |
| | | if (LoginHelper.isAdmin(userId)) { |
| | | menuList = baseMapper.selectList(new LambdaQueryWrapper<SysMenu>() |
| | | .like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible()) |
| | |
| | | .orderByAsc(SysMenu::getParentId) |
| | | .orderByAsc(SysMenu::getOrderNum)); |
| | | } else { |
| | | menu.getParams().put("userId", userId); |
| | | menuList = baseMapper.selectMenuListByUserId(menu); |
| | | QueryWrapper<SysMenu> wrapper = Wrappers.query(); |
| | | wrapper.eq("sur.user_id", userId) |
| | | .like(StringUtils.isNotBlank(menu.getMenuName()), "m.menu_name", menu.getMenuName()) |
| | | .eq(StringUtils.isNotBlank(menu.getVisible()), "m.visible", menu.getVisible()) |
| | | .eq(StringUtils.isNotBlank(menu.getStatus()), "m.status", menu.getStatus()) |
| | | .orderByAsc("m.parent_id") |
| | | .orderByAsc("m.order_num"); |
| | | menuList = baseMapper.selectMenuListByUserId(wrapper); |
| | | } |
| | | return menuList; |
| | | } |
| | |
| | | @Override |
| | | public Set<String> selectMenuPermsByUserId(Long userId) { |
| | | List<String> perms = baseMapper.selectMenuPermsByUserId(userId); |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) { |
| | | if (StringUtils.isNotEmpty(perm)) { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | } |
| | | } |
| | | return permsSet; |
| | | } |
| | | |
| | | /** |
| | | * 根据角色ID查询权限 |
| | | * |
| | | * @param roleId 角色ID |
| | | * @return 权限列表 |
| | | */ |
| | | @Override |
| | | public Set<String> selectMenuPermsByRoleId(Long roleId) { |
| | | List<String> perms = baseMapper.selectMenuPermsByRoleId(roleId); |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) { |
| | | if (StringUtils.isNotEmpty(perm)) { |
| | |
| | | @Override |
| | | public List<Long> selectMenuListByRoleId(Long roleId) { |
| | | SysRole role = roleMapper.selectById(roleId); |
| | | return baseMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); |
| | | return baseMapper.selectMenuListByRoleId(roleId, role.getMenuCheckStrictly()); |
| | | } |
| | | |
| | | /** |
| | |
| | | router.setName(getRouteName(menu)); |
| | | router.setPath(getRouterPath(menu)); |
| | | router.setComponent(getComponent(menu)); |
| | | router.setQuery(menu.getQuery()); |
| | | router.setQuery(menu.getQueryParam()); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | List<SysMenu> cMenus = (List<SysMenu>) menu.getChildren(); |
| | | List<SysMenu> cMenus = menu.getChildren(); |
| | | if (!cMenus.isEmpty() && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { |
| | | router.setAlwaysShow(true); |
| | | router.setRedirect("noRedirect"); |
| | |
| | | children.setComponent(menu.getComponent()); |
| | | children.setName(StringUtils.capitalize(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | children.setQuery(menu.getQuery()); |
| | | children.setQuery(menu.getQueryParam()); |
| | | childrenList.add(children); |
| | | router.setChildren(childrenList); |
| | | } else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) { |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); |
| | | router.setPath("/inner"); |
| | | router.setPath("/"); |
| | | List<RouterVo> childrenList = new ArrayList<RouterVo>(); |
| | | RouterVo children = new RouterVo(); |
| | | String routerPath = innerLinkReplaceEach(menu.getPath()); |
| | |
| | | * 得到子节点列表 |
| | | */ |
| | | private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) { |
| | | List<SysMenu> tlist = new ArrayList<SysMenu>(); |
| | | for (SysMenu n : list) { |
| | | if (n.getParentId().longValue() == t.getMenuId().longValue()) { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | return StreamUtils.filter(list, n -> n.getParentId().equals(t.getMenuId())); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 内链域名特殊字符替换 |
| | | * |
| | | * @return |
| | | */ |
| | | public String innerLinkReplaceEach(String path) { |
| | | return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS}, |
| | | new String[]{"", ""}); |
| | | return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."}, |
| | | new String[]{"", "", "", "/"}); |
| | | } |
| | | } |