Search in sources :

Example 1 with UserRoleOperationReqVO

use of com.company.project.vo.req.UserRoleOperationReqVO in project springboot-manager by aitangbao.

the class UserController method setUserOwnRole.

@PutMapping("/user/roles/{userId}")
@ApiOperation(value = "赋予角色-用户赋予角色接口")
@LogAnnotation(title = "用户管理", action = "赋予角色-用户赋予角色接口")
@RequiresPermissions("sys:user:update:role")
public DataResult setUserOwnRole(@PathVariable("userId") String userId, @RequestBody List<String> roleIds) {
    LambdaQueryWrapper<SysUserRole> queryWrapper = Wrappers.lambdaQuery();
    queryWrapper.eq(SysUserRole::getUserId, userId);
    userRoleService.remove(queryWrapper);
    if (!CollectionUtils.isEmpty(roleIds)) {
        UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
        reqVO.setUserId(userId);
        reqVO.setRoleIds(roleIds);
        userRoleService.addUserRoleInfo(reqVO);
    }
    // 刷新权限
    httpSessionService.refreshUerId(userId);
    return DataResult.success();
}
Also used : UserRoleOperationReqVO(com.company.project.vo.req.UserRoleOperationReqVO) SysUserRole(com.company.project.entity.SysUserRole) LogAnnotation(com.company.project.common.aop.annotation.LogAnnotation) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with UserRoleOperationReqVO

use of com.company.project.vo.req.UserRoleOperationReqVO in project springboot-manager by aitangbao.

the class UserServiceImpl method addUser.

@Override
public void addUser(SysUser vo) {
    SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
    if (sysUserOne != null) {
        throw new BusinessException("用户已存在,请勿重复添加!");
    }
    vo.setSalt(PasswordUtils.getSalt());
    String encode = PasswordUtils.encode(vo.getPassword(), vo.getSalt());
    vo.setPassword(encode);
    vo.setStatus(1);
    vo.setCreateWhere(1);
    sysUserMapper.insert(vo);
    if (!CollectionUtils.isEmpty(vo.getRoleIds())) {
        UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
        reqVO.setUserId(vo.getId());
        reqVO.setRoleIds(vo.getRoleIds());
        userRoleService.addUserRoleInfo(reqVO);
    }
}
Also used : UserRoleOperationReqVO(com.company.project.vo.req.UserRoleOperationReqVO) BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser)

Aggregations

UserRoleOperationReqVO (com.company.project.vo.req.UserRoleOperationReqVO)2 LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)1 BusinessException (com.company.project.common.exception.BusinessException)1 SysUser (com.company.project.entity.SysUser)1 SysUserRole (com.company.project.entity.SysUserRole)1 ApiOperation (io.swagger.annotations.ApiOperation)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1