use of com.albedo.java.modules.sys.domain.UserRoleDo in project albedo by somowhere.
the class UserServiceImpl method saveOrUpdate.
/**
* 保存用户信息
*
* @param userDto DTO 对象
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(UserDto userDto) {
boolean add = ObjectUtil.isEmpty(userDto.getId());
if (add) {
ArgumentAssert.notEmpty(userDto.getPassword(), "密码不能为空");
}
// username before comparing with database
if (exitUserByUserName(userDto)) {
throw new EntityExistException(UserDto.class, "username", userDto.getUsername());
}
// email before comparing with database
if (StringUtil.isNotEmpty(userDto.getEmail()) && exitUserByEmail(userDto)) {
throw new EntityExistException(UserDto.class, "email", userDto.getEmail());
}
// phone before comparing with database
if (StringUtil.isNotEmpty(userDto.getPhone()) && exitUserByPhone(userDto)) {
throw new EntityExistException(UserDto.class, "phone", userDto.getPhone());
}
UserDo userDo = add ? new UserDo() : repository.selectById(userDto.getId());
BeanUtil.copyProperties(userDto, userDo, true);
if (StringUtil.isNotEmpty(userDto.getPassword())) {
userDo.setPassword(passwordEncoder.encode(userDto.getPassword()));
}
super.saveOrUpdate(userDo);
userDto.setId(userDo.getId());
if (add || CollUtil.isNotEmpty(userDto.getRoleIdList())) {
ArgumentAssert.notEmpty(userDto.getRoleIdList(), "用户角色不能为空");
if (!add) {
SysCacheUtil.delUserCaches(userDo.getId(), userDo.getUsername());
}
List<UserRoleDo> userRoleDoList = userDto.getRoleIdList().stream().map(roleId -> UserRoleDo.builder().userId(userDo.getId()).roleId(roleId).build()).collect(Collectors.toList());
userRoleService.removeRoleByUserId(userDo.getId());
userRoleService.saveBatch(userRoleDoList);
}
}
use of com.albedo.java.modules.sys.domain.UserRoleDo in project albedo by somowhere.
the class UserRoleServiceImpl method initAdmin.
@Override
public boolean initAdmin(Long userId) {
RoleDo roleDo = roleRepository.selectOne(Wraps.<RoleDo>lbQ().eq(RoleDo::getCode, CommonConstants.ADMIN_ROLE_CODE));
ArgumentAssert.notNull(roleDo, "初始化用户角色失败, 无法查询到内置角色:%s", CommonConstants.ADMIN_ROLE_CODE);
UserRoleDo userRoleDo = UserRoleDo.builder().userId(userId).roleId(roleDo.getId()).build();
return super.save(userRoleDo);
}
Aggregations