| | |
| | |
|
| | | @Autowired
|
| | | private SysMenuMapper menuMapper;
|
| | | |
| | |
|
| | | @Autowired
|
| | | private SysRoleMapper roleMapper;
|
| | |
|
| | |
| | | public Set<String> selectMenuPermsByUserId(Long userId)
|
| | | {
|
| | | List<String> perms = menuMapper.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 = menuMapper.selectMenuPermsByRoleId(roleId);
|
| | | Set<String> permsSet = new HashSet<>();
|
| | | for (String perm : perms)
|
| | | {
|
| | |
| | | router.setQuery(menu.getQuery());
|
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
| | | List<SysMenu> cMenus = menu.getChildren();
|
| | | if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
|
| | | if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
|
| | | {
|
| | | router.setAlwaysShow(true);
|
| | | router.setRedirect("noRedirect");
|
| | |
| | | RouterVo children = new RouterVo();
|
| | | children.setPath(menu.getPath());
|
| | | children.setComponent(menu.getComponent());
|
| | | children.setName(StringUtils.capitalize(menu.getPath()));
|
| | | children.setName(getRouteName(menu.getRouteName(), menu.getPath()));
|
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
| | | children.setQuery(menu.getQuery());
|
| | | childrenList.add(children);
|
| | |
| | | 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());
|
| | | children.setPath(routerPath);
|
| | | children.setComponent(UserConstants.INNER_LINK);
|
| | | children.setName(StringUtils.capitalize(routerPath));
|
| | | children.setName(getRouteName(menu.getRouteName(), routerPath));
|
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
|
| | | childrenList.add(children);
|
| | | router.setChildren(childrenList);
|
| | |
| | | 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());
|
| | | }
|
| | | List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
|
| | | for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();)
|
| | | {
|
| | | SysMenu menu = (SysMenu) iterator.next();
|
| | |
| | | public boolean hasChildByMenuId(Long menuId)
|
| | | {
|
| | | int result = menuMapper.hasChildByMenuId(menuId);
|
| | | return result > 0 ? true : false;
|
| | | return result > 0;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public boolean checkMenuExistRole(Long menuId)
|
| | | {
|
| | | int result = roleMenuMapper.checkMenuExistRole(menuId);
|
| | | return result > 0 ? true : false;
|
| | | return result > 0;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | public String checkMenuNameUnique(SysMenu menu)
|
| | | public boolean checkMenuNameUnique(SysMenu menu)
|
| | | {
|
| | | Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId();
|
| | | SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
|
| | |
| | | */
|
| | | public String getRouteName(SysMenu menu)
|
| | | {
|
| | | String routerName = StringUtils.capitalize(menu.getPath());
|
| | | // 非外链并且是一级目录(类型为目录)
|
| | | if (isMenuFrame(menu))
|
| | | {
|
| | | routerName = StringUtils.EMPTY;
|
| | | return StringUtils.EMPTY;
|
| | | }
|
| | | return routerName;
|
| | | return getRouteName(menu.getRouteName(), menu.getPath());
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取路由名称,如没有配置路由名称则取路由地址
|
| | | * |
| | | * @param name 路由名称
|
| | | * @param path 路由地址
|
| | | * @return 路由名称(驼峰格式)
|
| | | */
|
| | | public String getRouteName(String name, String path)
|
| | | {
|
| | | String routerName = StringUtils.isNotEmpty(name) ? name : path;
|
| | | return StringUtils.capitalize(routerName);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
|
| | | && menu.getIsFrame().equals(UserConstants.NO_FRAME);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 是否为parent_view组件
|
| | | *
|
| | |
| | | /**
|
| | | * 递归列表
|
| | | *
|
| | | * @param list
|
| | | * @param t
|
| | | * @param list 分类表
|
| | | * @param t 子节点
|
| | | */
|
| | | private void recursionFn(List<SysMenu> list, SysMenu t)
|
| | | {
|
| | |
| | | */
|
| | | private boolean hasChild(List<SysMenu> list, SysMenu t)
|
| | | {
|
| | | return getChildList(list, t).size() > 0 ? true : false;
|
| | | return getChildList(list, t).size() > 0;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 内链域名特殊字符替换
|
| | | *
|
| | | * @return
|
| | | * @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[] { "", "", "", "/", "/" });
|
| | | }
|
| | | }
|