feat(新增): 🚀 根据角色获取菜单
This commit is contained in:
parent
9fd983ec5c
commit
2735f56d83
|
@ -15,4 +15,12 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||||
* @return 角色列表
|
* @return 角色列表
|
||||||
*/
|
*/
|
||||||
List<SysRole> selectByUserId(Long userId);
|
List<SysRole> selectByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据角色id获取角色权限
|
||||||
|
*
|
||||||
|
* @param roleId 角色Id
|
||||||
|
* @return 菜单列表Id
|
||||||
|
*/
|
||||||
|
List<Long> selectByRoleId4MenuId(Long roleId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.atguigu.auth.service.impl;
|
package com.atguigu.auth.service.impl;
|
||||||
|
|
||||||
import com.atguigu.auth.mapper.SysMenuMapper;
|
import com.atguigu.auth.mapper.SysMenuMapper;
|
||||||
|
import com.atguigu.auth.mapper.SysRoleMapper;
|
||||||
import com.atguigu.auth.service.SysMenuService;
|
import com.atguigu.auth.service.SysMenuService;
|
||||||
|
import com.atguigu.auth.service.SysRoleMenuService;
|
||||||
import com.atguigu.common.utlis.MenuHelper;
|
import com.atguigu.common.utlis.MenuHelper;
|
||||||
import com.atguigu.constant.MessageConstant;
|
import com.atguigu.constant.MessageConstant;
|
||||||
import com.atguigu.exception.BunnyException;
|
import com.atguigu.exception.BunnyException;
|
||||||
|
@ -9,6 +11,7 @@ import com.atguigu.model.system.SysMenu;
|
||||||
import com.atguigu.vo.system.AssginMenuVo;
|
import com.atguigu.vo.system.AssginMenuVo;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,6 +26,10 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||||
|
@Autowired
|
||||||
|
private SysRoleMenuService sysRoleMenuService;
|
||||||
|
@Autowired
|
||||||
|
private SysRoleMapper sysRoleMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单
|
* 获取菜单
|
||||||
|
@ -63,7 +70,19 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysMenu> findSysMenuByRoleId(Long roleId) {
|
public List<SysMenu> findSysMenuByRoleId(Long roleId) {
|
||||||
return null;
|
// 查询所有权限列表
|
||||||
|
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(SysMenu::getStatus, 1);
|
||||||
|
List<SysMenu> allSysMenuList = list(wrapper);
|
||||||
|
|
||||||
|
// 根据角色id获取角色权限
|
||||||
|
List<Long> menuIdList = sysRoleMapper.selectByRoleId4MenuId(roleId);
|
||||||
|
|
||||||
|
allSysMenuList.forEach(permission -> {
|
||||||
|
permission.setSelect(menuIdList.contains(permission.getId()));
|
||||||
|
});
|
||||||
|
|
||||||
|
return MenuHelper.buildTree(allSysMenuList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,4 +7,11 @@
|
||||||
FROM sys_role
|
FROM sys_role
|
||||||
WHERE id IN (SELECT role_id FROM sys_user_role WHERE user_id = #{user_id})
|
WHERE id IN (SELECT role_id FROM sys_user_role WHERE user_id = #{user_id})
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据角色id获取角色权限 -->
|
||||||
|
<select id="selectByRoleId4MenuId" resultType="java.lang.Long">
|
||||||
|
SELECT menu_id
|
||||||
|
FROM sys_role_menu
|
||||||
|
WHERE role_id = #{role_id}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue