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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations