Java Code Examples for com.ruoyi.system.domain.SysRole

The following examples show how to use com.ruoyi.system.domain.SysRole. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: supplierShop   Source File: SysUserServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 查询用户所属角色组
 * 
 * @param userId 用户ID
 * @return 结果
 */
@Override
public String selectUserRoleGroup(Long userId)
{
    List<SysRole> list = roleMapper.selectRolesByUserId(userId);
    StringBuffer idsStr = new StringBuffer();
    for (SysRole role : list)
    {
        idsStr.append(role.getRoleName()).append(",");
    }
    if (StringUtils.isNotEmpty(idsStr.toString()))
    {
        return idsStr.substring(0, idsStr.length() - 1);
    }
    return idsStr.toString();
}
 
Example 2
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 根据用户ID查询角色
 * 
 * @param userId 用户ID
 * @return 角色列表
 */
@Override
public List<SysRole> selectRolesByUserId(Long userId)
{
    List<SysRole> userRoles = roleMapper.selectRolesByUserId(userId);
    List<SysRole> roles = selectRoleAll();
    for (SysRole role : roles)
    {
        for (SysRole userRole : userRoles)
        {
            if (role.getRoleId().longValue() == userRole.getRoleId().longValue())
            {
                role.setFlag(true);
                break;
            }
        }
    }
    return roles;
}
 
Example 3
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 新增角色菜单信息
 * 
 * @param role 角色对象
 */
public int insertRoleMenu(SysRole role)
{
    int rows = 1;
    // 新增用户与角色管理
    List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
    for (Long menuId : role.getMenuIds())
    {
        SysRoleMenu rm = new SysRoleMenu();
        rm.setRoleId(role.getRoleId());
        rm.setMenuId(menuId);
        list.add(rm);
    }
    if (list.size() > 0)
    {
        rows = roleMenuMapper.batchRoleMenu(list);
    }
    return rows;
}
 
Example 4
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 新增角色部门信息(数据权限)
 *
 * @param role 角色对象
 */
public int insertRoleDept(SysRole role)
{
    int rows = 1;
    // 新增角色与部门(数据权限)管理
    List<SysRoleDept> list = new ArrayList<SysRoleDept>();
    for (Long deptId : role.getDeptIds())
    {
        SysRoleDept rd = new SysRoleDept();
        rd.setRoleId(role.getRoleId());
        rd.setDeptId(deptId);
        list.add(rd);
    }
    if (list.size() > 0)
    {
        rows = roleDeptMapper.batchRoleDept(list);
    }
    return rows;
}
 
Example 5
Source Project: supplierShop   Source File: SysRoleController.java    License: MIT License 6 votes vote down vote up
/**
 * 新增保存角色
 */
@RequiresPermissions("system:role:add")
@Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated SysRole role)
{
    if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
    {
        return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
    }
    else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
    {
        return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
    }
    role.setCreateBy(ShiroUtils.getLoginName());
    ShiroUtils.clearCachedAuthorizationInfo();
    return toAjax(roleService.insertRole(role));

}
 
Example 6
Source Project: supplierShop   Source File: SysRoleController.java    License: MIT License 6 votes vote down vote up
/**
 * 修改保存角色
 */
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated SysRole role)
{
    if (UserConstants.ROLE_NAME_NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
    {
        return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
    }
    else if (UserConstants.ROLE_KEY_NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
    {
        return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
    }
    role.setUpdateBy(ShiroUtils.getLoginName());
    ShiroUtils.clearCachedAuthorizationInfo();
    return toAjax(roleService.updateRole(role));
}
 
Example 7
Source Project: RuoYi   Source File: SysRoleServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 新增角色菜单信息
 *
 * @param role 角色对象
 */
private int insertRoleMenu(SysRole role) {
    int rows = 1;
    // 新增用户与角色管理
    List<SysRoleMenu> list = new ArrayList<>();
    for (Long menuId : role.getMenuIds()) {
        SysRoleMenu rm = new SysRoleMenu();
        rm.setRoleId(role.getRoleId());
        rm.setMenuId(menuId);
        list.add(rm);
    }
    if (!CollectionUtils.isEmpty(list)) {
        rows = roleMenuMapper.batchRoleMenu(list);
    }
    return rows;
}
 
Example 8
Source Project: ruoyiplus   Source File: SysDeptServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 根据角色ID查询部门(数据权限)
 *
 * @param role 角色对象
 * @return 部门列表(数据权限)
 */
@Override
public List<Map<String, Object>> roleDeptTreeData(SysRole role)
{
    Long roleId = role.getRoleId();
    List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
    List<SysDept> deptList = selectDeptList(new SysDept());
    if (StringUtils.isNotNull(roleId))
    {
        List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId);
        trees = getTrees(deptList, true, roleDeptList);
    }
    else
    {
        trees = getTrees(deptList, false, null);
    }
    return trees;
}
 
Example 9
Source Project: ruoyiplus   Source File: SysRoleServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 新增角色菜单信息
 * 
 * @param role 角色对象
 */
public int insertRoleMenu(SysRole role)
{
    int rows = 1;
    // 新增用户与角色管理
    List<SysRoleMenu> list = new ArrayList<SysRoleMenu>();
    for (Long menuId : role.getMenuIds())
    {
        SysRoleMenu rm = new SysRoleMenu();
        rm.setRoleId(role.getRoleId());
        rm.setMenuId(menuId);
        list.add(rm);
    }
    if (list.size() > 0)
    {
        rows = roleMenuMapper.batchRoleMenu(list);
    }
    return rows;
}
 
Example 10
Source Project: ruoyiplus   Source File: SysMenuServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 根据角色ID查询菜单
 * 
 * @param role 角色对象
 * @return 菜单列表
 */
@Override
public List<Map<String, Object>> roleMenuTreeData(SysRole role)
{
    Long roleId = role.getRoleId();
    List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
    List<SysMenu> menuList = menuMapper.selectMenuAll();
    if (StringUtils.isNotNull(roleId))
    {
        List<String> roleMenuList = menuMapper.selectMenuTree(roleId);
        trees = getTrees(menuList, true, roleMenuList, true);
    }
    else
    {
        trees = getTrees(menuList, false, null, true);
    }
    return trees;
}
 
Example 11
Source Project: RuoYi   Source File: SysRoleController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 修改保存角色
 */
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public AjaxResult editSave(SysRole role) {
    role.setUpdateBy(ShiroUtils.getLoginName());
    ShiroUtils.clearCachedAuthorizationInfo();
    return toAjax(roleService.updateRole(role));
}
 
Example 12
Source Project: ruoyiplus   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
/**
 * 校验角色名称
 */
@PostMapping("/checkRoleNameUnique")
@ResponseBody
public String checkRoleNameUnique(SysRole role)
{
    return roleService.checkRoleNameUnique(role);
}
 
Example 13
Source Project: ruoyiplus   Source File: SysDeptController.java    License: MIT License 5 votes vote down vote up
/**
 * 加载角色部门(数据权限)列表树,适配EleTree
 */
@GetMapping("/roleDeptTreeData2")
@ResponseBody
public Map deptTreeData2(SysRole role)
{
    Map retMap = new HashMap();
    List<Map<String, Object>> tree = deptService.roleDeptTreeData(role);
    tree = EleTreeWrapper.getInstance().getTree(tree,"pId","id");
    retMap.put("code",0);
    retMap.put("data",tree);
    return retMap;

}
 
Example 14
Source Project: ruoyiplus   Source File: SysMenuController.java    License: MIT License 5 votes vote down vote up
/**
 * 加载所有菜单列表树
 */
@GetMapping("/menuTreeData")
@ResponseBody
public List<Map<String, Object>> menuTreeData(SysRole role)
{
    List<Map<String, Object>> tree = menuService.menuTreeData();
    return tree;
}
 
Example 15
Source Project: RuoYi   Source File: SysRoleServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 校验角色名称是否唯一
 *
 * @param role 角色信息
 * @return 结果
 */
@Override
public String checkRoleNameUnique(SysRole role) {
    SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
    if (ObjectUtil.isNotNull(info) && !info.getRoleId().equals(role.getRoleId())) {
        return UserConstants.ROLE_NAME_NOT_UNIQUE;
    }
    return UserConstants.ROLE_NAME_UNIQUE;
}
 
Example 16
Source Project: RuoYi   Source File: SysDeptServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 根据角色ID查询部门(数据权限)
 *
 * @param role 角色对象
 * @return 部门列表(数据权限)
 */
@Override
public List<Ztree> roleDeptTreeData(SysRole role) {
    Long roleId = role.getRoleId();
    List<Ztree> ztrees;
    List<SysDept> deptList = selectDeptList(new SysDept());
    if (ObjectUtil.isNotNull(roleId)) {
        List<String> roleDeptList = deptMapper.selectRoleDeptTree(roleId);
        ztrees = initZtree(deptList, roleDeptList);
    } else {
        ztrees = initZtree(deptList);
    }
    return ztrees;
}
 
Example 17
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 批量删除角色信息
 * 
 * @param ids 需要删除的数据ID
 * @throws Exception
 */
@Override
public int deleteRoleByIds(String ids) throws BusinessException
{
    Long[] roleIds = Convert.toLongArray(ids);
    for (Long roleId : roleIds)
    {
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0)
        {
            throw new BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    return roleMapper.deleteRoleByIds(roleIds);
}
 
Example 18
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 修改保存角色信息
 * 
 * @param role 角色信息
 * @return 结果
 */
@Override
@Transactional
public int updateRole(SysRole role)
{
    // 修改角色信息
    roleMapper.updateRole(role);
    // 删除角色与菜单关联
    roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId());
    return insertRoleMenu(role);
}
 
Example 19
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 修改数据权限信息
 * 
 * @param role 角色信息
 * @return 结果
 */
@Override
@Transactional
public int authDataScope(SysRole role)
{
    // 修改角色信息
    roleMapper.updateRole(role);
    // 删除角色与部门关联
    roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
    // 新增角色和部门信息(数据权限)
    return insertRoleDept(role);
}
 
Example 20
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 校验角色名称是否唯一
 * 
 * @param role 角色信息
 * @return 结果
 */
@Override
public String checkRoleNameUnique(SysRole role)
{
    Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
    SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
    if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
    {
        return UserConstants.ROLE_NAME_NOT_UNIQUE;
    }
    return UserConstants.ROLE_NAME_UNIQUE;
}
 
Example 21
Source Project: supplierShop   Source File: SysRoleServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 校验角色权限是否唯一
 * 
 * @param role 角色信息
 * @return 结果
 */
@Override
public String checkRoleKeyUnique(SysRole role)
{
    Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
    SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
    if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue())
    {
        return UserConstants.ROLE_KEY_NOT_UNIQUE;
    }
    return UserConstants.ROLE_KEY_UNIQUE;
}
 
Example 22
Source Project: ruoyiplus   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
/**
 * 角色状态修改
 */
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:role:edit")
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(SysRole role)
{
    return toAjax(roleService.changeStatus(role));
}
 
Example 23
Source Project: RuoYi   Source File: SysRoleController.java    License: Apache License 2.0 5 votes vote down vote up
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:role:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysRole role) {
    List<SysRole> list = roleService.selectRoleList(role);
    ExcelUtil<SysRole> util = new ExcelUtil<>(SysRole.class);
    return util.exportExcel(list, "角色信息");
}
 
Example 24
Source Project: supplierShop   Source File: SysMenuController.java    License: MIT License 5 votes vote down vote up
/**
 * 加载角色菜单列表树
 */
@GetMapping("/roleMenuTreeData")
@ResponseBody
public List<Ztree> roleMenuTreeData(SysRole role)
{
    Long userId = ShiroUtils.getUserId();
    List<Ztree> ztrees = menuService.roleMenuTreeData(role, userId);
    return ztrees;
}
 
Example 25
Source Project: supplierShop   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:role:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysRole role)
{
    List<SysRole> list = roleService.selectRoleList(role);
    ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
    return util.exportExcel(list, "角色数据");
}
 
Example 26
Source Project: supplierShop   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
/**
 * 校验角色名称
 */
@PostMapping("/checkRoleNameUnique")
@ResponseBody
public String checkRoleNameUnique(SysRole role)
{
    return roleService.checkRoleNameUnique(role);
}
 
Example 27
Source Project: supplierShop   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
/**
 * 角色状态修改
 */
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@RequiresPermissions("system:role:edit")
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(SysRole role)
{
    return toAjax(roleService.changeStatus(role));
}
 
Example 28
Source Project: RuoYi   Source File: SysRoleServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 根据用户ID查询角色
 *
 * @param userId 用户ID
 * @return 角色列表
 */
@Override
public List<SysRole> selectRolesByUserId(Long userId) {
    List<SysRole> userRoles = roleMapper.selectRolesByUserId(userId);
    List<SysRole> roles = selectRoleAll();
    for (SysRole role : roles) {
        for (SysRole userRole : userRoles) {
            if (role.getRoleId().equals(userRole.getRoleId())) {
                role.setFlag(true);
                break;
            }
        }
    }
    return roles;
}
 
Example 29
Source Project: RuoYi   Source File: SysRoleServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 批量删除角色信息
 *
 * @param ids 需要删除的数据ID
 * @throws BusinessException 异常
 */
@Override
public int deleteRoleByIds(String ids) {
    Long[] roleIds = Convert.toLongArray(ids);
    for (Long roleId : roleIds) {
        SysRole role = selectRoleById(roleId);
        if (countUserRoleByRoleId(roleId) > 0) {
            throw new BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName()));
        }
    }
    return roleMapper.deleteRoleByIds(roleIds);
}
 
Example 30
Source Project: ruoyiplus   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
/**
 * 新增保存角色
 */
@RequiresPermissions("system:role:add")
@Log(title = "角色管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public AjaxResult addSave(SysRole role)
{
    role.setCreateBy(ShiroUtils.getLoginName());
    ShiroUtils.clearCachedAuthorizationInfo();
    return toAjax(roleService.insertRole(role));

}