Search in sources :

Example 1 with SysRoleDeptEntity

use of com.jun.plugin.system.entity.SysRoleDeptEntity 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 2 with SysRoleDeptEntity

use of com.jun.plugin.system.entity.SysRoleDeptEntity 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)2 SysRoleDeptEntity (com.jun.plugin.system.entity.SysRoleDeptEntity)2 LogAnnotation (com.jun.plugin.system.common.aop.annotation.LogAnnotation)1 BusinessException (com.jun.plugin.system.common.exception.BusinessException)1 SysRolePermission (com.jun.plugin.system.entity.SysRolePermission)1 DeptRespNodeVO (com.jun.plugin.system.vo.resp.DeptRespNodeVO)1 PermissionRespNode (com.jun.plugin.system.vo.resp.PermissionRespNode)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1