| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.utils.BeanCopyUtils; |
| | | import com.ruoyi.common.core.utils.MapstructUtils; |
| | | 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.SysMenu; |
| | | import com.ruoyi.system.domain.SysRole; |
| | | import com.ruoyi.system.domain.SysRoleMenu; |
| | | import com.ruoyi.system.domain.SysTenantPackage; |
| | | import com.ruoyi.system.domain.bo.SysMenuBo; |
| | | import com.ruoyi.system.domain.vo.MetaVo; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | |
| | | import com.ruoyi.system.mapper.SysMenuMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMapper; |
| | | import com.ruoyi.system.mapper.SysRoleMenuMapper; |
| | | import com.ruoyi.system.mapper.SysTenantPackageMapper; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final SysMenuMapper baseMapper; |
| | | private final SysRoleMapper roleMapper; |
| | | private final SysRoleMenuMapper roleMenuMapper; |
| | | private final SysTenantPackageMapper sysTenantPackageMapper; |
| | | |
| | | /** |
| | | * 根据用户查询系统菜单列表 |
| | |
| | | public List<SysMenuVo> selectMenuList(SysMenuBo menu, Long userId) { |
| | | List<SysMenuVo> menuList; |
| | | // 管理员显示所有菜单信息 |
| | | if (LoginHelper.isAdmin(userId)) { |
| | | if (LoginHelper.isSuperAdmin(userId)) { |
| | | menuList = baseMapper.selectVoList(new LambdaQueryWrapper<SysMenu>() |
| | | .like(StringUtils.isNotBlank(menu.getMenuName()), SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(StringUtils.isNotBlank(menu.getVisible()), SysMenu::getVisible, menu.getVisible()) |
| | |
| | | .orderByAsc("m.parent_id") |
| | | .orderByAsc("m.order_num"); |
| | | List<SysMenu> list = baseMapper.selectMenuListByUserId(wrapper); |
| | | menuList = BeanCopyUtils.copyList(list, SysMenuVo.class); |
| | | menuList = MapstructUtils.convert(list, SysMenuVo.class); |
| | | } |
| | | return menuList; |
| | | } |
| | |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) { |
| | | if (StringUtils.isNotEmpty(perm)) { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | permsSet.addAll(StringUtils.splitList(perm.trim())); |
| | | } |
| | | } |
| | | return permsSet; |
| | |
| | | Set<String> permsSet = new HashSet<>(); |
| | | for (String perm : perms) { |
| | | if (StringUtils.isNotEmpty(perm)) { |
| | | permsSet.addAll(Arrays.asList(perm.trim().split(","))); |
| | | permsSet.addAll(StringUtils.splitList(perm.trim())); |
| | | } |
| | | } |
| | | return permsSet; |
| | |
| | | @Override |
| | | public List<SysMenu> selectMenuTreeByUserId(Long userId) { |
| | | List<SysMenu> menus; |
| | | if (LoginHelper.isAdmin(userId)) { |
| | | if (LoginHelper.isSuperAdmin(userId)) { |
| | | menus = baseMapper.selectMenuTreeAll(); |
| | | } else { |
| | | menus = baseMapper.selectMenuTreeByUserId(userId); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据租户套餐ID查询菜单树信息 |
| | | * |
| | | * @param packageId 租户套餐ID |
| | | * @return 选中菜单列表 |
| | | */ |
| | | @Override |
| | | public List<Long> selectMenuListByPackageId(Long packageId) { |
| | | SysTenantPackage tenantPackage = sysTenantPackageMapper.selectById(packageId); |
| | | List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong); |
| | | if (CollUtil.isEmpty(menuIds)) { |
| | | return List.of(); |
| | | } |
| | | List<Long> parentIds = null; |
| | | if (tenantPackage.getMenuCheckStrictly()) { |
| | | parentIds = baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>() |
| | | .select(SysMenu::getParentId) |
| | | .in(SysMenu::getMenuId, menuIds), Convert::toLong); |
| | | } |
| | | return baseMapper.selectObjs(new LambdaQueryWrapper<SysMenu>() |
| | | .in(SysMenu::getMenuId, menuIds) |
| | | .notIn(CollUtil.isNotEmpty(parentIds), SysMenu::getMenuId, parentIds), Convert::toLong); |
| | | } |
| | | |
| | | /** |
| | | * 构建前端路由所需要的菜单 |
| | | * |
| | | * @param menus 菜单列表 |
| | |
| | | router.setHidden("1".equals(menu.getVisible())); |
| | | router.setName(menu.getRouteName()); |
| | | router.setPath(menu.getRouterPath()); |
| | | router.setComponent(menu.getComponent()); |
| | | router.setComponent(menu.getComponentInfo()); |
| | | router.setQuery(menu.getQueryParam()); |
| | | 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())) { |
| | | if (CollUtil.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) { |
| | | router.setAlwaysShow(true); |
| | | router.setRedirect("noRedirect"); |
| | | router.setChildren(buildMenus(cMenus)); |
| | |
| | | List<RouterVo> childrenList = new ArrayList<>(); |
| | | RouterVo children = new RouterVo(); |
| | | children.setPath(menu.getPath()); |
| | | children.setComponent(menu.getComponent()); |
| | | children.setComponent(menu.getComponentInfo()); |
| | | children.setName(StringUtils.capitalize(menu.getPath())); |
| | | children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); |
| | | children.setQuery(menu.getQueryParam()); |
| | |
| | | */ |
| | | @Override |
| | | public int insertMenu(SysMenuBo bo) { |
| | | SysMenu menu = BeanUtil.toBean(bo, SysMenu.class); |
| | | SysMenu menu = MapstructUtils.convert(bo, SysMenu.class); |
| | | return baseMapper.insert(menu); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public int updateMenu(SysMenuBo bo) { |
| | | SysMenu menu = BeanUtil.toBean(bo, SysMenu.class); |
| | | SysMenu menu = MapstructUtils.convert(bo, SysMenu.class); |
| | | return baseMapper.updateById(menu); |
| | | } |
| | | |
| | |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public String checkMenuNameUnique(SysMenuBo menu) { |
| | | public boolean checkMenuNameUnique(SysMenuBo menu) { |
| | | boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysMenu>() |
| | | .eq(SysMenu::getMenuName, menu.getMenuName()) |
| | | .eq(SysMenu::getParentId, menu.getParentId()) |
| | | .ne(ObjectUtil.isNotNull(menu.getMenuId()), SysMenu::getMenuId, menu.getMenuId())); |
| | | if (exist) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | return !exist; |
| | | } |
| | | |
| | | /** |