| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | 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.system.domain.SysRoleMenu; |
| | | import com.ruoyi.system.domain.vo.MetaVo; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Service |
| | | public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService { |
| | | public class SysMenuServiceImpl extends ServicePlusImpl<SysMenuMapper, SysMenu, SysMenu> implements ISysMenuService { |
| | | public static final String PREMISSION_STRING = "perms[\"{0}\"]"; |
| | | |
| | | @Autowired |
| | |
| | | // 管理员显示所有菜单信息 |
| | | if (SysUser.isAdmin(userId)) { |
| | | menuList = list(new LambdaQueryWrapper<SysMenu>() |
| | | .like(StrUtil.isNotBlank(menu.getMenuName()),SysMenu::getMenuName,menu.getMenuName()) |
| | | .eq(StrUtil.isNotBlank(menu.getVisible()),SysMenu::getVisible,menu.getVisible()) |
| | | .eq(StrUtil.isNotBlank(menu.getStatus()),SysMenu::getStatus,menu.getStatus()) |
| | | .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 { |
| | |
| | | List<String> perms = baseMapper.selectMenuPermsByUserId(userId); |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) { |
| | | if (Validator.isNotEmpty(perm)) { |
| | | if (StringUtils.isNotEmpty(perm)) { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | } |
| | | } |
| | |
| | | router.setName(getRouteName(menu)); |
| | | router.setPath(getRouterPath(menu)); |
| | | router.setComponent(getComponent(menu)); |
| | | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()))); |
| | | 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() && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { |
| | | router.setAlwaysShow(true); |
| | |
| | | RouterVo children = new RouterVo(); |
| | | children.setPath(menu.getPath()); |
| | | children.setComponent(menu.getComponent()); |
| | | children.setName(StrUtil.upperFirst(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StrUtil.equals("1", menu.getIsCache()))); |
| | | children.setName(StringUtils.capitalize(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | 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"); |
| | | List<RouterVo> childrenList = new ArrayList<RouterVo>(); |
| | | RouterVo children = new RouterVo(); |
| | | String routerPath = StringUtils.replaceEach(menu.getPath(), new String[] { Constants.HTTP, Constants.HTTPS }, new String[] { "", "" }); |
| | | 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); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean hasChildByMenuId(Long menuId) { |
| | | int result = count(new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getParentId,menuId)); |
| | | long result = count(new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getParentId,menuId)); |
| | | return result > 0; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public boolean checkMenuExistRole(Long menuId) { |
| | | int result = roleMenuMapper.selectCount(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getMenuId,menuId)); |
| | | long result = roleMenuMapper.selectCount(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getMenuId,menuId)); |
| | | return result > 0; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public String checkMenuNameUnique(SysMenu menu) { |
| | | Long menuId = Validator.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); |
| | | 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 (Validator.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) { |
| | | if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | |
| | | * @return 路由名称 |
| | | */ |
| | | public String getRouteName(SysMenu menu) { |
| | | String routerName = StrUtil.upperFirst(menu.getPath()); |
| | | String routerName = StringUtils.capitalize(menu.getPath()); |
| | | // 非外链并且是一级目录(类型为目录) |
| | | if (isMenuFrame(menu)) { |
| | | routerName = StrUtil.EMPTY; |
| | | routerName = StringUtils.EMPTY; |
| | | } |
| | | return routerName; |
| | | } |
| | |
| | | */ |
| | | public String getRouterPath(SysMenu menu) { |
| | | String routerPath = menu.getPath(); |
| | | // 内链打开外网方式 |
| | | if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) { |
| | | routerPath = StringUtils.replaceEach(routerPath, new String[] { Constants.HTTP, Constants.HTTPS }, new String[] { "", "" }); |
| | | } |
| | | // 非外链并且是一级目录(类型为目录) |
| | | if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) |
| | | && UserConstants.NO_FRAME.equals(menu.getIsFrame())) { |
| | |
| | | */ |
| | | public String getComponent(SysMenu menu) { |
| | | String component = UserConstants.LAYOUT; |
| | | if (StrUtil.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { |
| | | if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) { |
| | | component = menu.getComponent(); |
| | | } else if (StrUtil.isEmpty(menu.getComponent()) && isParentView(menu)) { |
| | | } 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 isInnerLink(SysMenu menu) { |
| | | return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); |
| | | } |
| | | |
| | | /** |
| | | * 是否为parent_view组件 |
| | | * |
| | | * @param menu 菜单信息 |
| | |
| | | /** |
| | | * 根据父节点的ID获取所有子节点 |
| | | * |
| | | * @param list 分类表 |
| | | * @param list 分类表 |
| | | * @param parentId 传入的父节点ID |
| | | * @return String |
| | | */ |