| | |
| | | return Result.error("账号已被注册!"); |
| | | } |
| | | |
| | | if(dto.getAccountType() == 0 && StringUtils.isEmpty(dto.getInvitationCode())){ |
| | | return Result.error("邀请码不能为空!"); |
| | | } |
| | | |
| | | String invitationCode = getInvitationCode(); |
| | | UserAccount user = new UserAccount(); |
| | | if(dto.getAccountType() == 0 && StringUtils.isNotEmpty(dto.getInvitationCode()) && !dto.getInvitationCode().equals("000000")){ |
| | | user = userAccountService.getOne(new LambdaQueryWrapper<UserAccount>() |
| | | .eq(UserAccount::getInvitationCode, dto.getInvitationCode()).last(" limit 1")); |
| | | if(ObjectUtil.isEmpty(user)){ |
| | | return Result.error("邀请码错误"); |
| | | } |
| | | } |
| | | |
| | | // 创建本地用户账户记录 |
| | | UserAccount userAccount = new UserAccount(); |
| | | userAccount.setAccount(dto.getAccount()); |
| | |
| | | userAccount.setNickname(dto.getNickname()); |
| | | userAccount.setCreateTime(new Date()); |
| | | userAccount.setUpdateTime(new Date()); |
| | | userAccount.setInvitationCode(invitationCode); |
| | | userAccount.setInvitationAccount(ObjectUtil.isNotEmpty(user.getAccount()) ? user.getAccount() : ""); |
| | | |
| | | if (!userAccountService.save(userAccount)) { |
| | | throw new RuntimeException("保存用户账户失败"); |
| | |
| | | .eq(GroupWelcomeConfig::getConfigurationName, "IM-BASICS").last(" limit 1")); |
| | | |
| | | NeteaseTeam neteaseTeam = neteaseTeamMapper.selectOne(new LambdaQueryWrapper<NeteaseTeam>().eq(NeteaseTeam::getTid,groupWelcomeConfig.getGroupId())); |
| | | if(ObjectUtil.isNotEmpty(groupWelcomeConfig) || ObjectUtil.isNotEmpty(neteaseTeam)){ |
| | | if(ObjectUtil.isNotEmpty(groupWelcomeConfig) && ObjectUtil.isNotEmpty(groupWelcomeConfig.getUserAccid())){ |
| | | addFriends(userAccount.getAccount(),groupWelcomeConfig.getUserAccid()); |
| | | } |
| | | if(ObjectUtil.isNotEmpty(groupWelcomeConfig) && ObjectUtil.isNotEmpty(groupWelcomeConfig.getGroupId()) && ObjectUtil.isNotEmpty(neteaseTeam)){ |
| | | List<String> accountList = new ArrayList<>(); |
| | | accountList.add(userAccount.getAccount()); |
| | | AddTeamMembersRequest request = new AddTeamMembersRequest(); |
| | | request.setInviteAccountIds(accountList); |
| | | request.setGroupId(neteaseTeam.getId().toString()); |
| | | request.setGroupId(ObjectUtil.isNotEmpty(neteaseTeam.getId().toString()) ? neteaseTeam.getId().toString() : null); |
| | | neteaseTeamService.inviteTeamMembers(request); |
| | | } |
| | | return Result.success("注册成功"); |
| | |
| | | } |
| | | } |
| | | |
| | | private String getInvitationCode() { |
| | | String invitationCode = null; |
| | | int maxAttempts = 100; // 最大尝试次数 |
| | | int attempts = 0; |
| | | |
| | | while (attempts < maxAttempts) { |
| | | invitationCode = generateInvitationCode(); |
| | | long count = userAccountService.count(new LambdaQueryWrapper<UserAccount>() |
| | | .eq(UserAccount::getInvitationCode, invitationCode)); |
| | | if(count <= 0){ |
| | | break; |
| | | } |
| | | attempts++; |
| | | } |
| | | |
| | | if (attempts >= maxAttempts) { |
| | | log.error("生成邀请码已超最大尝试次数!"); |
| | | throw new RuntimeException("无法生成唯一的邀请码,请稍后重试"); |
| | | } |
| | | return invitationCode; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 生成邀请码 |
| | | * @return |
| | | */ |
| | | public static String generateInvitationCode() { |
| | | Random random = new Random(); |
| | | int code = 100000 + random.nextInt(900000); |
| | | return String.valueOf(code); |
| | | } |
| | | |
| | | /** |
| | | * 优化的账号生成方法,使用雪花算法变体提高并发性能 |
| | |
| | | httpPatch.setHeader("CurTime", curTime); |
| | | httpPatch.setHeader("CheckSum", checkSum); |
| | | |
| | | // 构建请求体 |
| | | // UpdateUserInfoRequest builder = new UpdateUserInfoRequest(); |
| | | // if(StringUtils.isNotEmpty(dto.getMobile())){ |
| | | // builder.setMobile(dto.getMobile()); |
| | | // } |
| | | // if(StringUtils.isNotEmpty(dto.getName())){ |
| | | // builder.setName(dto.getName()); |
| | | // } |
| | | // if(StringUtils.isNotEmpty(dto.getSign())){ |
| | | // builder.setSign(dto.getSign()); |
| | | // } |
| | | // if(StringUtils.isNotEmpty(dto.getAvatar())){ |
| | | // builder.setAvatar(dto.getAvatar()); |
| | | // } |
| | | // String body = builder.build(); |
| | | UpdateUserInfoRequest requestBody = new UpdateUserInfoRequest(dto.getAvatar(), |
| | | dto.getName(),dto.getSign(),dto.getEmail(),dto.getMobile()); |
| | | dto.getName(),dto.getSign(),dto.getEmail(),dto.getMobile(),dto.getGender()); |
| | | String jsonBody = objectMapper.writeValueAsString(requestBody); |
| | | httpPatch.setEntity(new StringEntity(jsonBody, StandardCharsets.UTF_8)); |
| | | |
| | |
| | | } |
| | | if(StringUtils.isNotEmpty(vo.getSignature())){ |
| | | dto.setSign(vo.getSignature()); |
| | | } |
| | | if(ObjectUtil.isNotEmpty(vo.getGender())){ |
| | | dto.setGender(vo.getGender()); |
| | | } |
| | | Map<String, Object> map = updateUserAvatar(vo.getAccountId(), dto); |
| | | //更新用户属性 状态 密码 |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result batchRegister(RegisterDto dto) { |
| | | dto.setAccountType(1); |
| | | if(dto.getType() == 2){ |
| | | return register(dto); |
| | | }else{ |
| | |
| | | List<UserAccount> accounts = new ArrayList<>(count); |
| | | Set<String> generatedAccounts = new HashSet<>(count); // 用于内存中去重 |
| | | Random random = new Random(); |
| | | |
| | | String invitationCode = getInvitationCode(); |
| | | for (int i = 0; i < count; i++) { |
| | | String account; |
| | | do { |
| | |
| | | userAccount.setCreateTime(new Date()); |
| | | userAccount.setNickname("用户_" + account.substring(7)); // 简单生成昵称 |
| | | userAccount.setAccountType(1); // 设置账号类型为1 |
| | | |
| | | userAccount.setInvitationCode(invitationCode); |
| | | accounts.add(userAccount); |
| | | } |
| | | return accounts; |