Search in sources :

Example 1 with SysRole

use of com.jun.plugin.system.entity.SysRole in project jun_springboot_api_service by wujun728.

the class RoleController method pageInfo.

@PostMapping("/roles")
@ApiOperation(value = "分页获取角色信息接口")
@LogAnnotation(title = "角色管理", action = "分页获取角色信息")
@RequiresPermissions("sys:role:list")
@SuppressWarnings("unchecked")
public DataResult pageInfo(@RequestBody SysRole vo) {
    Page page = new Page(vo.getPage(), vo.getLimit());
    LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery();
    if (!StringUtils.isEmpty(vo.getName())) {
        queryWrapper.like(SysRole::getName, vo.getName());
    }
    if (!StringUtils.isEmpty(vo.getStartTime())) {
        queryWrapper.gt(SysRole::getCreateTime, vo.getStartTime());
    }
    if (!StringUtils.isEmpty(vo.getEndTime())) {
        queryWrapper.lt(SysRole::getCreateTime, vo.getEndTime());
    }
    if (!StringUtils.isEmpty(vo.getStatus())) {
        queryWrapper.eq(SysRole::getStatus, vo.getStatus());
    }
    queryWrapper.orderByDesc(SysRole::getCreateTime);
    return DataResult.success(roleService.page(page, queryWrapper));
}
Also used : SysRole(com.jun.plugin.system.entity.SysRole) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) LogAnnotation(com.jun.plugin.system.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with SysRole

use of com.jun.plugin.system.entity.SysRole in project jun_springboot_api_service by wujun728.

the class UserServiceImpl method getUserOwnRole.

@Override
public UserOwnRoleRespVO getUserOwnRole(String userId) {
    List<String> roleIdsByUserId = userRoleService.getRoleIdsByUserId(userId);
    List<SysRole> list = roleService.list();
    UserOwnRoleRespVO vo = new UserOwnRoleRespVO();
    vo.setAllRole(list);
    vo.setOwnRoles(roleIdsByUserId);
    return vo;
}
Also used : SysRole(com.jun.plugin.system.entity.SysRole) UserOwnRoleRespVO(com.jun.plugin.system.vo.resp.UserOwnRoleRespVO)

Example 3 with SysRole

use of com.jun.plugin.system.entity.SysRole in project jun_springboot_api_service by wujun728.

the class RoleServiceImpl method updateRole.

@Transactional(rollbackFor = Exception.class)
@Override
public void updateRole(SysRole vo) {
    SysRole sysRole = sysRoleMapper.selectById(vo.getId());
    if (null == sysRole) {
        log.error("传入 的 id:{}不合法", vo.getId());
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    sysRoleMapper.updateById(vo);
    // 删除角色权限关联
    rolePermissionService.remove(Wrappers.<SysRolePermission>lambdaQuery().eq(SysRolePermission::getRoleId, sysRole.getId()));
    if (!CollectionUtils.isEmpty(vo.getPermissions())) {
        RolePermissionOperationReqVO reqVO = new RolePermissionOperationReqVO();
        reqVO.setRoleId(sysRole.getId());
        reqVO.setPermissionIds(vo.getPermissions());
        rolePermissionService.addRolePermission(reqVO);
        // 刷新权限
        httpSessionService.refreshRolePermission(sysRole.getId());
    }
}
Also used : SysRolePermission(com.jun.plugin.system.entity.SysRolePermission) BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysRole(com.jun.plugin.system.entity.SysRole) RolePermissionOperationReqVO(com.jun.plugin.system.vo.req.RolePermissionOperationReqVO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SysRole

use of com.jun.plugin.system.entity.SysRole in project jun_springboot_api_service by wujun728.

the class RoleServiceImpl method detailInfo.

@Override
public SysRole detailInfo(String id) {
    SysRole sysRole = sysRoleMapper.selectById(id);
    if (sysRole == null) {
        log.error("传入 的 id:{}不合法", id);
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    List<PermissionRespNode> permissionRespNodes = permissionService.selectAllByTree();
    LambdaQueryWrapper<SysRolePermission> queryWrapper = Wrappers.<SysRolePermission>lambdaQuery().select(SysRolePermission::getPermissionId).eq(SysRolePermission::getRoleId, sysRole.getId());
    Set<Object> checkList = new HashSet<>(rolePermissionService.listObjs(queryWrapper));
    setChecked(permissionRespNodes, checkList);
    sysRole.setPermissionRespNodes(permissionRespNodes);
    LambdaQueryWrapper<SysRoleDeptEntity> queryWrapperDept = Wrappers.<SysRoleDeptEntity>lambdaQuery().select(SysRoleDeptEntity::getDeptId).eq(SysRoleDeptEntity::getRoleId, sysRole.getId());
    List<DeptRespNodeVO> deptRespNodes = deptService.deptTreeList(null, true);
    Set<Object> checkDeptList = new HashSet<>(sysRoleDeptService.listObjs(queryWrapperDept));
    setCheckedDept(deptRespNodes, checkDeptList);
    sysRole.setDeptRespNodes(deptRespNodes);
    return sysRole;
}
Also used : SysRolePermission(com.jun.plugin.system.entity.SysRolePermission) PermissionRespNode(com.jun.plugin.system.vo.resp.PermissionRespNode) DeptRespNodeVO(com.jun.plugin.system.vo.resp.DeptRespNodeVO) BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysRole(com.jun.plugin.system.entity.SysRole) SysRoleDeptEntity(com.jun.plugin.system.entity.SysRoleDeptEntity) HashSet(java.util.HashSet)

Example 5 with SysRole

use of com.jun.plugin.system.entity.SysRole in project jun_springboot_api_service by wujun728.

the class RoleController method bindDept.

@PostMapping("/role/bindDept")
@ApiOperation(value = "绑定角色部门接口")
@LogAnnotation(title = "角色管理", action = "绑定角色部门信息")
@RequiresPermissions("sys:role:bindDept")
public DataResult bindDept(@RequestBody SysRole vo) {
    if (StringUtils.isEmpty(vo.getId())) {
        return DataResult.fail("id不能为空");
    }
    if (roleService.getById(vo.getId()) == null) {
        return DataResult.fail("获取角色失败");
    }
    // 先删除所有绑定
    sysRoleDeptService.remove(Wrappers.<SysRoleDeptEntity>lambdaQuery().eq(SysRoleDeptEntity::getRoleId, vo.getId()));
    // 如果不是自定义
    if (vo.getDataScope() != 2) {
        vo.setDepts(null);
    }
    if (!CollectionUtils.isEmpty(vo.getDepts())) {
        List<SysRoleDeptEntity> list = new ArrayList<>();
        for (String deptId : vo.getDepts()) {
            SysRoleDeptEntity sysRoleDeptEntity = new SysRoleDeptEntity();
            sysRoleDeptEntity.setDeptId(deptId);
            sysRoleDeptEntity.setRoleId(vo.getId());
            list.add(sysRoleDeptEntity);
        }
        sysRoleDeptService.saveBatch(list);
    }
    roleService.updateById(new SysRole().setId(vo.getId()).setDataScope(vo.getDataScope()));
    return DataResult.success();
}
Also used : ArrayList(java.util.ArrayList) SysRole(com.jun.plugin.system.entity.SysRole) SysRoleDeptEntity(com.jun.plugin.system.entity.SysRoleDeptEntity) LogAnnotation(com.jun.plugin.system.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SysRole (com.jun.plugin.system.entity.SysRole)5 LogAnnotation (com.jun.plugin.system.common.aop.annotation.LogAnnotation)2 BusinessException (com.jun.plugin.system.common.exception.BusinessException)2 SysRoleDeptEntity (com.jun.plugin.system.entity.SysRoleDeptEntity)2 SysRolePermission (com.jun.plugin.system.entity.SysRolePermission)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 RolePermissionOperationReqVO (com.jun.plugin.system.vo.req.RolePermissionOperationReqVO)1 DeptRespNodeVO (com.jun.plugin.system.vo.resp.DeptRespNodeVO)1 PermissionRespNode (com.jun.plugin.system.vo.resp.PermissionRespNode)1 UserOwnRoleRespVO (com.jun.plugin.system.vo.resp.UserOwnRoleRespVO)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Transactional (org.springframework.transaction.annotation.Transactional)1