use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.
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);
}
use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.
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);
}
}
use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.
the class UserServiceImpl method register.
@Override
public void register(SysUser sysUser) {
SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername()));
if (sysUserOne != null) {
throw new BusinessException("用户名已存在!");
}
sysUser.setSalt(PasswordUtils.getSalt());
String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt());
sysUser.setPassword(encode);
sysUserMapper.insert(sysUser);
}
use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.
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);
respVO.setJwtToken(JwtUtil.sign(vo.getUsername()));
return respVO;
}
Aggregations