Search in sources :

Example 1 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class SysDictDetailServiceImpl method listByPage.

@Override
public IPage<SysDictDetailEntity> listByPage(Page<SysDictDetailEntity> page, String dictId) {
    SysDictEntity sysDictEntity = sysDictMapper.selectById(dictId);
    if (sysDictEntity == null) {
        throw new BusinessException("获取字典数据失败!");
    }
    LambdaQueryWrapper<SysDictDetailEntity> wrapper = Wrappers.lambdaQuery();
    wrapper.eq(SysDictDetailEntity::getDictId, dictId);
    wrapper.orderByAsc(SysDictDetailEntity::getSort);
    IPage<SysDictDetailEntity> result = sysDictDetailMapper.selectPage(page, wrapper);
    if (!CollectionUtils.isEmpty(result.getRecords())) {
        result.getRecords().parallelStream().forEach(entity -> entity.setDictName(sysDictEntity.getName()));
    }
    return result;
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysDictDetailEntity(com.company.project.entity.SysDictDetailEntity) SysDictEntity(com.company.project.entity.SysDictEntity)

Example 2 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class UserServiceImpl method login.

@Override
public LoginRespVO login(SysUser vo) {
    SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
    if (null == sysUser) {
        throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
    }
    if (sysUser.getStatus() == 2) {
        throw new BusinessException(BaseResponseCode.USER_LOCK);
    }
    if (!PasswordUtils.matches(sysUser.getSalt(), vo.getPassword(), sysUser.getPassword())) {
        throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
    }
    LoginRespVO respVO = new LoginRespVO();
    BeanUtils.copyProperties(sysUser, respVO);
    // true:允许多处登陆; false:只能单处登陆,顶掉之前登陆
    if (!allowMultipleLogin) {
        httpSessionService.abortUserById(sysUser.getId());
    }
    if (StringUtils.isNotBlank(sysUser.getDeptId())) {
        SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
        if (sysDept != null) {
            sysUser.setDeptNo(sysDept.getDeptNo());
        }
    }
    String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId()));
    respVO.setAccessToken(token);
    return respVO;
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) LoginRespVO(com.company.project.vo.resp.LoginRespVO) SysUser(com.company.project.entity.SysUser) SysDept(com.company.project.entity.SysDept)

Example 3 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class UserServiceImpl method updateUserInfoMy.

@Override
public void updateUserInfoMy(SysUser vo) {
    SysUser user = sysUserMapper.selectById(httpSessionService.getCurrentUserId());
    if (null == user) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    if (!StringUtils.isEmpty(vo.getPassword())) {
        String newPassword = PasswordUtils.encode(vo.getPassword(), user.getSalt());
        vo.setPassword(newPassword);
    } else {
        vo.setPassword(null);
    }
    vo.setUpdateId(httpSessionService.getCurrentUserId());
    sysUserMapper.updateById(vo);
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser)

Example 4 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class UserServiceImpl method updatePwd.

@Override
public void updatePwd(SysUser vo) {
    SysUser sysUser = sysUserMapper.selectById(vo.getId());
    if (sysUser == null) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    if ("test".equals(env) && "guest".equals(sysUser.getUsername())) {
        throw new BusinessException("演示环境禁止修改演示账号密码");
    }
    if (!PasswordUtils.matches(sysUser.getSalt(), vo.getOldPwd(), sysUser.getPassword())) {
        throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR);
    }
    if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) {
        throw new BusinessException("新密码不能与旧密码相同");
    }
    sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()));
    sysUserMapper.updateById(sysUser);
    // 退出用户
    httpSessionService.abortAllUserByToken();
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser)

Example 5 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class UserServiceImpl method updateUserInfo.

@Override
public void updateUserInfo(SysUser vo) {
    SysUser sysUser = sysUserMapper.selectById(vo.getId());
    if (null == sysUser) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    // 如果用户名变更
    if (!sysUser.getUsername().equals(vo.getUsername())) {
        SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
        if (sysUserOne != null) {
            throw new BusinessException("用户名已存在!");
        }
    }
    // 如果用户名、密码、状态 变更,删除redis中用户绑定的角色跟权限
    if (!sysUser.getUsername().equals(vo.getUsername()) || (!StringUtils.isEmpty(vo.getPassword()) && !sysUser.getPassword().equals(PasswordUtils.encode(vo.getPassword(), sysUser.getSalt()))) || !sysUser.getStatus().equals(vo.getStatus())) {
        httpSessionService.abortUserById(vo.getId());
    }
    if (!StringUtils.isEmpty(vo.getPassword())) {
        String newPassword = PasswordUtils.encode(vo.getPassword(), sysUser.getSalt());
        vo.setPassword(newPassword);
    } else {
        vo.setPassword(null);
    }
    vo.setUpdateId(httpSessionService.getCurrentUserId());
    sysUserMapper.updateById(vo);
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser)

Aggregations

BusinessException (com.company.project.common.exception.BusinessException)24 SysUser (com.company.project.entity.SysUser)7 SysDept (com.company.project.entity.SysDept)5 SysPermission (com.company.project.entity.SysPermission)3 SysRolePermission (com.company.project.entity.SysRolePermission)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SysRole (com.company.project.entity.SysRole)2 DeptRespNodeVO (com.company.project.vo.resp.DeptRespNodeVO)2 IOException (java.io.IOException)2 JSONObject (com.alibaba.fastjson.JSONObject)1 LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)1 ColumnEntity (com.company.project.entity.ColumnEntity)1 SysDictDetailEntity (com.company.project.entity.SysDictDetailEntity)1 SysDictEntity (com.company.project.entity.SysDictEntity)1 SysFilesEntity (com.company.project.entity.SysFilesEntity)1 SysJobEntity (com.company.project.entity.SysJobEntity)1 SysRoleDeptEntity (com.company.project.entity.SysRoleDeptEntity)1 TableEntity (com.company.project.entity.TableEntity)1 RolePermissionOperationReqVO (com.company.project.vo.req.RolePermissionOperationReqVO)1 UserRoleOperationReqVO (com.company.project.vo.req.UserRoleOperationReqVO)1