@Test public void createUser() { RegisterDTO dto = new RegisterDTO(); dto.setUsername("pedro111"); dto.setPassword("123456"); dto.setConfirmPassword("123456"); log.info("dto: {}", dto); UserDO user = userService.createUser(dto); log.info("user: {}", user); assertEquals(user.getUsername(), "pedro111"); assertNull(user.getEmail()); }
@Transactional @Override public UserDO createUser(RegisterDTO dto) { boolean exist = this.checkUserExistByUsername(dto.getUsername()); if (exist) { throw new ForbiddenException("username already exist, please choose a new one", 10071); } if (StrUtil.isNotBlank(dto.getEmail())) { exist = this.checkUserExistByEmail(dto.getEmail()); if (exist) { throw new ForbiddenException("email already exist, please choose a new one", 10076); } } else { dto.setEmail(null); } UserDO user = new UserDO(); BeanUtil.copyProperties(dto, user); this.baseMapper.insert(user); if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) { checkGroupsValid(dto.getGroupIds()); checkGroupsExist(dto.getGroupIds()); List<UserGroupDO> relations = dto.getGroupIds() .stream() .map(groupId -> new UserGroupDO(user.getId(), groupId)) .collect(Collectors.toList()); userGroupMapper.insertBatch(relations); } else { UserGroupDO relation = new UserGroupDO(user.getId(), guestGroupId); userGroupMapper.insert(relation); } userIdentityService.createUsernamePasswordIdentity(user.getId(), dto.getUsername(), dto.getPassword()); return user; }
UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService { @Transactional @Override public UserDO createUser(RegisterDTO dto) { boolean exist = this.checkUserExistByUsername(dto.getUsername()); if (exist) { throw new ForbiddenException("username already exist, please choose a new one", 10071); } if (StrUtil.isNotBlank(dto.getEmail())) { exist = this.checkUserExistByEmail(dto.getEmail()); if (exist) { throw new ForbiddenException("email already exist, please choose a new one", 10076); } } else { dto.setEmail(null); } UserDO user = new UserDO(); BeanUtil.copyProperties(dto, user); this.baseMapper.insert(user); if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) { checkGroupsValid(dto.getGroupIds()); checkGroupsExist(dto.getGroupIds()); List<UserGroupDO> relations = dto.getGroupIds() .stream() .map(groupId -> new UserGroupDO(user.getId(), groupId)) .collect(Collectors.toList()); userGroupMapper.insertBatch(relations); } else { UserGroupDO relation = new UserGroupDO(user.getId(), guestGroupId); userGroupMapper.insert(relation); } userIdentityService.createUsernamePasswordIdentity(user.getId(), dto.getUsername(), dto.getPassword()); return user; } }
UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService { @Transactional @Override public UserDO createUser(RegisterDTO dto) { boolean exist = this.checkUserExistByUsername(dto.getUsername()); if (exist) { throw new ForbiddenException("username already exist, please choose a new one", 10071); } if (StrUtil.isNotBlank(dto.getEmail())) { exist = this.checkUserExistByEmail(dto.getEmail()); if (exist) { throw new ForbiddenException("email already exist, please choose a new one", 10076); } } else { dto.setEmail(null); } UserDO user = new UserDO(); BeanUtil.copyProperties(dto, user); this.baseMapper.insert(user); if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) { checkGroupsValid(dto.getGroupIds()); checkGroupsExist(dto.getGroupIds()); List<UserGroupDO> relations = dto.getGroupIds() .stream() .map(groupId -> new UserGroupDO(user.getId(), groupId)) .collect(Collectors.toList()); userGroupMapper.insertBatch(relations); } else { UserGroupDO relation = new UserGroupDO(user.getId(), guestGroupId); userGroupMapper.insert(relation); } userIdentityService.createUsernamePasswordIdentity(user.getId(), dto.getUsername(), dto.getPassword()); return user; }  }
UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService { @Transactional @Override public UserDO createUser(RegisterDTO dto) { boolean exist = this.checkUserExistByUsername(dto.getUsername()); if (exist) { throw new ForbiddenException("username already exist, please choose a new one", 10071); } if (StrUtil.isNotBlank(dto.getEmail())) { exist = this.checkUserExistByEmail(dto.getEmail()); if (exist) { throw new ForbiddenException("email already exist, please choose a new one", 10076); } } else { dto.setEmail(null); } UserDO user = new UserDO(); BeanUtil.copyProperties(dto, user); this.baseMapper.insert(user); if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) { checkGroupsValid(dto.getGroupIds()); checkGroupsExist(dto.getGroupIds()); List<UserGroupDO> relations = dto.getGroupIds() .stream() .map(groupId -> new UserGroupDO(user.getId(), groupId)) .collect(Collectors.toList()); userGroupMapper.insertBatch(relations); } else { UserGroupDO relation = new UserGroupDO(user.getId(), guestGroupId); userGroupMapper.insert(relation); } userIdentityService.createUsernamePasswordIdentity(user.getId(), dto.getUsername(), dto.getPassword()); return user; }  @Transactional @Override UserDO createUser(RegisterDTO dto); @Transactional @Override UserDO updateUserInfo(UpdateInfoDTO dto); @Override UserDO changeUserPassword(ChangePasswordDTO dto); @Override List<GroupDO> getUserGroups(Long userId); @Override List<Map<String, List<Map<String, String>>>> getStructualUserPermissions(Long userId); @Override List<PermissionDO> getUserPermissions(Long userId); @Override UserDO getUserByUsername(String username); @Override boolean checkUserExistByUsername(String username); @Override boolean checkUserExistByEmail(String email); @Override boolean checkUserExistById(Long id); @Override IPage<UserDO> getUserPageByGroupId(Page pager, Long groupId); }
UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService { @Transactional @Override public UserDO createUser(RegisterDTO dto) { boolean exist = this.checkUserExistByUsername(dto.getUsername()); if (exist) { throw new ForbiddenException("username already exist, please choose a new one", 10071); } if (StrUtil.isNotBlank(dto.getEmail())) { exist = this.checkUserExistByEmail(dto.getEmail()); if (exist) { throw new ForbiddenException("email already exist, please choose a new one", 10076); } } else { dto.setEmail(null); } UserDO user = new UserDO(); BeanUtil.copyProperties(dto, user); this.baseMapper.insert(user); if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) { checkGroupsValid(dto.getGroupIds()); checkGroupsExist(dto.getGroupIds()); List<UserGroupDO> relations = dto.getGroupIds() .stream() .map(groupId -> new UserGroupDO(user.getId(), groupId)) .collect(Collectors.toList()); userGroupMapper.insertBatch(relations); } else { UserGroupDO relation = new UserGroupDO(user.getId(), guestGroupId); userGroupMapper.insert(relation); } userIdentityService.createUsernamePasswordIdentity(user.getId(), dto.getUsername(), dto.getPassword()); return user; }  @Transactional @Override UserDO createUser(RegisterDTO dto); @Transactional @Override UserDO updateUserInfo(UpdateInfoDTO dto); @Override UserDO changeUserPassword(ChangePasswordDTO dto); @Override List<GroupDO> getUserGroups(Long userId); @Override List<Map<String, List<Map<String, String>>>> getStructualUserPermissions(Long userId); @Override List<PermissionDO> getUserPermissions(Long userId); @Override UserDO getUserByUsername(String username); @Override boolean checkUserExistByUsername(String username); @Override boolean checkUserExistByEmail(String email); @Override boolean checkUserExistById(Long id); @Override IPage<UserDO> getUserPageByGroupId(Page pager, Long groupId);  }