|  |  |  | 
|---|
|  |  |  | package com.ruoyi.system.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.ruoyi.account.mapper.SysMenuMapper; | 
|---|
|  |  |  | import com.ruoyi.system.api.model.SysMenu; | 
|---|
|  |  |  | import com.ruoyi.account.service.SysMenuService; | 
|---|
|  |  |  | import com.ruoyi.common.core.constant.Constants; | 
|---|
|  |  |  | import com.ruoyi.common.core.constant.UserConstants; | 
|---|
|  |  |  | import com.ruoyi.common.core.utils.StringUtils; | 
|---|
|  |  |  | import com.ruoyi.common.security.service.TokenService; | 
|---|
|  |  |  | import com.ruoyi.common.security.utils.SecurityUtils; | 
|---|
|  |  |  | import com.ruoyi.system.api.domain.SysRole; | 
|---|
|  |  |  | import com.ruoyi.system.domain.SysMenu; | 
|---|
|  |  |  | import com.ruoyi.system.domain.SysMenus; | 
|---|
|  |  |  | import com.ruoyi.system.domain.SysUserRole; | 
|---|
|  |  |  | import com.ruoyi.system.domain.vo.MetaVo; | 
|---|
|  |  |  | import com.ruoyi.system.domain.vo.RouterVo; | 
|---|
|  |  |  | import com.ruoyi.system.domain.vo.TreeSelect; | 
|---|
|  |  |  | import com.ruoyi.system.mapper.*; | 
|---|
|  |  |  | import com.ruoyi.system.service.ISysMenuService; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | *  服务实现类 | 
|---|
|  |  |  | * </p> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author luodangjia | 
|---|
|  |  |  | * @since 2024-11-21 | 
|---|
|  |  |  | * 菜单 业务层处理 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @author ruoyi | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService { | 
|---|
|  |  |  | public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService | 
|---|
|  |  |  | { | 
|---|
|  |  |  | public static final String PREMISSION_STRING = "perms[\"{0}\"]"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysMenuMapper menuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysRoleMapper roleMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysRoleMenuMapper roleMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TokenService tokenService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysUserRoleMapper sysUserRoleMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private SysUserMapper sysUserMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据用户查询系统菜单列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param userId 用户ID | 
|---|
|  |  |  | * @return 菜单列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SysMenu> selectMenuList(Long userId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return selectMenuList(new SysMenu(), userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询系统菜单列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 菜单列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SysMenu> selectMenuList(SysMenu menu, Long userId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<SysMenu> menuList = null; | 
|---|
|  |  |  | // 管理员显示所有菜单信息 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | menu.getParams().put("userId", userId); | 
|---|
|  |  |  | menuList = menuMapper.selectMenuListByUserId(menu); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return menuList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据用户ID查询权限 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param userId 用户ID | 
|---|
|  |  |  | * @return 权限列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 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.add(perm); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(perm)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | permsSet.add(perm); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return permsSet; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据用户ID查询菜单 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param userId 用户名称 | 
|---|
|  |  |  | * @return 菜单列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SysMenu> selectMenuTreeByUserId(Long userId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<SysMenu> menus = null; | 
|---|
|  |  |  | if (SecurityUtils.isAdmin(userId)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | menus = menuMapper.selectMenuTreeAll(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | menus = menuMapper.selectMenuTreeByUserId(userId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return getChildPerms(menus, 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据角色ID查询菜单树信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param roleId 角色ID | 
|---|
|  |  |  | * @return 选中菜单列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Long> selectMenuListByRoleId(Long roleId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SysRole role = roleMapper.selectRoleById(roleId); | 
|---|
|  |  |  | return menuMapper.selectMenuListByRoleId(roleId, false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 构建前端路由所需要的菜单 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menus 菜单列表 | 
|---|
|  |  |  | * @return 路由列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<RouterVo> buildMenus(List<SysMenu> menus) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<RouterVo> routers = new LinkedList<RouterVo>(); | 
|---|
|  |  |  | for (SysMenu menu : menus) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | RouterVo router = new RouterVo(); | 
|---|
|  |  |  | router.setHidden("1".equals(menu.getVisible())); | 
|---|
|  |  |  | router.setName(getRouteName(menu)); | 
|---|
|  |  |  | router.setPath(getRouterPath(menu)); | 
|---|
|  |  |  | router.setComponent(getComponent(menu)); | 
|---|
|  |  |  | 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())) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | router.setAlwaysShow(true); | 
|---|
|  |  |  | router.setRedirect("noRedirect"); | 
|---|
|  |  |  | router.setChildren(buildMenus(cMenus)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (isMenuFrame(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | router.setMeta(null); | 
|---|
|  |  |  | List<RouterVo> childrenList = new ArrayList<RouterVo>(); | 
|---|
|  |  |  | RouterVo children = new RouterVo(); | 
|---|
|  |  |  | children.setPath(menu.getPath()); | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | childrenList.add(children); | 
|---|
|  |  |  | router.setChildren(childrenList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); | 
|---|
|  |  |  | 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.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath())); | 
|---|
|  |  |  | childrenList.add(children); | 
|---|
|  |  |  | router.setChildren(childrenList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | routers.add(router); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return routers; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 构建前端所需要树结构 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menus 菜单列表 | 
|---|
|  |  |  | * @return 树结构列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SysMenu> buildMenuTree(List<SysMenu> menus) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<SysMenu> returnList = new ArrayList<SysMenu>(); | 
|---|
|  |  |  | List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); | 
|---|
|  |  |  | for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SysMenu menu = (SysMenu) iterator.next(); | 
|---|
|  |  |  | // 如果是顶级节点, 遍历该父节点的所有子节点 | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据菜单ID查询信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menuId 菜单ID | 
|---|
|  |  |  | * @return 菜单信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public SysMenu selectMenuById(Long menuId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menuMapper.selectMenuById(menuId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否存在菜单子节点 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menuId 菜单ID | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean hasChildByMenuId(Long menuId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | int result = menuMapper.hasChildByMenuId(menuId); | 
|---|
|  |  |  | return result > 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询菜单使用数量 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menuId 菜单ID | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean checkMenuExistRole(Long menuId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | int result = roleMenuMapper.checkMenuExistRole(menuId); | 
|---|
|  |  |  | return result > 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 新增保存菜单信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int insertMenu(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menuMapper.insertMenu(menu); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改保存菜单信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int updateMenu(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menuMapper.updateMenu(menu); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 删除菜单管理信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menuId 菜单ID | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int deleteMenuById(Long menuId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menuMapper.deleteMenuById(menuId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 校验菜单名称是否唯一 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean checkMenuNameUnique(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); | 
|---|
|  |  |  | SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); | 
|---|
|  |  |  | if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return UserConstants.NOT_UNIQUE; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return UserConstants.UNIQUE; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SysMenus> getAllMenu() { | 
|---|
|  |  |  | Long userid = tokenService.getLoginUser().getUserid(); | 
|---|
|  |  |  | SysUserRole sysUserRole = sysUserRoleMapper.selectSysUserRoleByUserId(userid); | 
|---|
|  |  |  | Long roleId = sysUserRole.getRoleId(); | 
|---|
|  |  |  | List<SysMenus> list=null; | 
|---|
|  |  |  | if(roleId!=1){ | 
|---|
|  |  |  | list = menuMapper.getAllOne(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | list = menuMapper.getAll(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取所有 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 第三级 | 
|---|
|  |  |  | List<SysMenus> s3 = list.stream().filter(e -> e.getMenuType().equals("F")).collect(Collectors.toList()); | 
|---|
|  |  |  | // 第二级 | 
|---|
|  |  |  | List<SysMenus> s2 = list.stream().filter(e -> e.getMenuType().equals("C") | 
|---|
|  |  |  | && e.getMenuId() != 1196 | 
|---|
|  |  |  | && e.getMenuId() != 1197 | 
|---|
|  |  |  | && e.getMenuId() != 1198 | 
|---|
|  |  |  | && e.getMenuId() != 1199 | 
|---|
|  |  |  | && e.getMenuId() != 1201 | 
|---|
|  |  |  | && e.getMenuId() != 1205).collect(Collectors.toList()); | 
|---|
|  |  |  | // 第一级 | 
|---|
|  |  |  | List<SysMenus> s1 = list.stream().filter(e -> e.getMenuType().equals("M")).collect(Collectors.toList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (SysMenus menus : s2) { | 
|---|
|  |  |  | List<SysMenus> collect = s3.stream().filter(e -> e.getParentId().equals(menus.getMenuId())).collect(Collectors.toList()); | 
|---|
|  |  |  | menus.setChildren(collect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (SysMenus menus : s1) { | 
|---|
|  |  |  | List<SysMenus> collect = s2.stream().filter(e -> e.getParentId().equals(menus.getMenuId())).collect(Collectors.toList()); | 
|---|
|  |  |  | menus.setChildren(collect); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return s1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取路由名称 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 路由名称 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String getRouteName(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | String routerName = StringUtils.capitalize(menu.getPath()); | 
|---|
|  |  |  | // 非外链并且是一级目录(类型为目录) | 
|---|
|  |  |  | if (isMenuFrame(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | routerName = StringUtils.EMPTY; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return routerName; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取路由地址 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 路由地址 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String getRouterPath(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | String routerPath = menu.getPath(); | 
|---|
|  |  |  | // 内链打开外网方式 | 
|---|
|  |  |  | if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | routerPath = innerLinkReplaceEach(routerPath); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 非外链并且是一级目录(类型为目录) | 
|---|
|  |  |  | if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) | 
|---|
|  |  |  | && UserConstants.NO_FRAME.equals(menu.getIsFrame())) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | routerPath = "/" + menu.getPath(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 非外链并且是一级目录(类型为菜单) | 
|---|
|  |  |  | else if (isMenuFrame(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | routerPath = "/"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return routerPath; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取组件信息 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 组件信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String getComponent(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | String component = UserConstants.LAYOUT; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | component = menu.getComponent(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | component = UserConstants.INNER_LINK; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | component = UserConstants.PARENT_VIEW; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return component; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否为菜单内部跳转 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean isMenuFrame(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) | 
|---|
|  |  |  | && menu.getIsFrame().equals(UserConstants.NO_FRAME); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否为内链组件 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean isInnerLink(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 是否为parent_view组件 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param menu 菜单信息 | 
|---|
|  |  |  | * @return 结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean isParentView(SysMenu menu) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据父节点的ID获取所有子节点 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param list 分类表 | 
|---|
|  |  |  | * @param parentId 传入的父节点ID | 
|---|
|  |  |  | * @return String | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<SysMenu> returnList = new ArrayList<SysMenu>(); | 
|---|
|  |  |  | for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext();) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SysMenu t = (SysMenu) iterator.next(); | 
|---|
|  |  |  | // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 | 
|---|
|  |  |  | if (t.getParentId() == parentId) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | recursionFn(list, t); | 
|---|
|  |  |  | returnList.add(t); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return returnList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 递归列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param list | 
|---|
|  |  |  | * @param t | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void recursionFn(List<SysMenu> list, SysMenu t) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // 得到子节点列表 | 
|---|
|  |  |  | List<SysMenu> childList = getChildList(list, t); | 
|---|
|  |  |  | t.setChildren(childList); | 
|---|
|  |  |  | for (SysMenu tChild : childList) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (hasChild(list, tChild)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | recursionFn(list, tChild); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到子节点列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<SysMenu> tlist = new ArrayList<SysMenu>(); | 
|---|
|  |  |  | Iterator<SysMenu> it = list.iterator(); | 
|---|
|  |  |  | while (it.hasNext()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SysMenu n = (SysMenu) it.next(); | 
|---|
|  |  |  | if (n.getParentId().longValue() == t.getMenuId().longValue()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | tlist.add(n); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return tlist; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 判断是否有子节点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private boolean hasChild(List<SysMenu> list, SysMenu t) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return getChildList(list, t).size() > 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 内链域名特殊字符替换 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String innerLinkReplaceEach(String path) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS, Constants.WWW, "." }, | 
|---|
|  |  |  | new String[] { "", "", "", "/" }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|