| | |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | @Resource |
| | | private final YunxinApiHttpClient yunxinClient; |
| | | |
| | | // 使用构造函数注入(推荐) |
| | |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) // 添加事务注解确保操作原子性 |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result register(RegisterDto dto) { |
| | | try { |
| | | // 验证手机号是否已存在(数据库唯一索引提供最终保障) |
| | | // 验证手机号是否已存在 |
| | | List<UserAccount> accounts = userAccountService.list( |
| | | new LambdaQueryWrapper<>(UserAccount.class) |
| | | .eq(UserAccount::getAccount, dto.getAccount()) |
| | | ); |
| | | |
| | | if (!CollectionUtils.isEmpty(accounts)) { |
| | | return Result.error("手机号已注册!"); |
| | | return Result.error("账号已被注册!"); |
| | | } |
| | | |
| | | // 创建本地用户账户记录 |
| | |
| | | userAccount.setCloudMessageAccount(dto.getAccount()); |
| | | userAccount.setPassword(SymmetricCryptoUtil.encryptPassword(dto.getPassword())); |
| | | userAccount.setCreateTime(new Date()); |
| | | userAccount.setNickname(dto.getAccount()); |
| | | |
| | | userAccount.setNickname(dto.getNickname()); |
| | | |
| | | if (!userAccountService.save(userAccount)) { |
| | | return Result.error("注册失败,请重试"); |
| | | throw new RuntimeException("保存用户账户失败"); // 改为抛出异常 |
| | | } |
| | | |
| | | // 注册云信账号(远程调用) |
| | | Map<String, String> paramMap = new HashMap<>(); |
| | | paramMap.put("accid", dto.getAccount()); |
| | | if(StringUtils.isNotEmpty(dto.getName())){ |
| | | paramMap.put("name", dto.getName()); |
| | | if(StringUtils.isNotEmpty(dto.getNickname())){ |
| | | paramMap.put("name", dto.getNickname()); |
| | | } |
| | | paramMap.put("token", dto.getPassword()); |
| | | |
| | |
| | | neteaseTeamService.inviteTeamMembers(request); |
| | | } |
| | | return Result.success("注册成功"); |
| | | } else if (code == 414) { |
| | | // 手动触发回滚(事务注解会自动处理) |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | return Result.error("账号已被注册!"); |
| | | } else { |
| | | // 其他错误码同样触发回滚 |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | log.error("云信注册失败,响应: {}, traceId: {}", data, response.getTraceId()); |
| | | return Result.error("注册失败,错误码: " + code); |
| | | // 所有非200状态码都抛出异常触发回滚 |
| | | throw new RuntimeException("云信注册失败,错误码: " + code + ", 响应: " + data); |
| | | } |
| | | } catch (YunxinSdkException e) { |
| | | // 云信调用异常时回滚事务 |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | log.error("云信服务调用异常 traceId: {}", e.getTraceId(), e); |
| | | return Result.error("注册失败,系统异常"); |
| | | } catch (Exception e) { |
| | | // 其他异常同样回滚 |
| | | TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
| | | log.error("注册过程发生未知异常", e); |
| | | return Result.error("注册失败,请重试"); |
| | | // 记录异常日志 |
| | | log.error("注册过程发生异常", e); |
| | | // 重新抛出异常以确保事务回滚 |
| | | throw new RuntimeException("注册失败: " + e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | |
| | | httpPatch.setHeader("CheckSum", checkSum); |
| | | |
| | | // 构建请求体 |
| | | UpdateUserInfoRequest builder = new UpdateUserInfoRequest(); |
| | | if(StringUtils.isNotEmpty(dto.getMobile())){ |
| | | builder.setMobile(dto.getMobile()); |
| | | }else if(StringUtils.isNotEmpty(dto.getName())){ |
| | | builder.setName(dto.getName()); |
| | | }else if(StringUtils.isNotEmpty(dto.getSign())){ |
| | | builder.setSign(dto.getSign()); |
| | | }else if(StringUtils.isNotEmpty(dto.getAvatar())){ |
| | | builder.setAvatar(dto.getAvatar()); |
| | | } |
| | | String body = builder.build(); |
| | | String jsonBody = objectMapper.writeValueAsString(body); |
| | | // 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()); |
| | | String jsonBody = objectMapper.writeValueAsString(requestBody); |
| | | // String jsonBody = objectMapper.writeValueAsString(body); |
| | | httpPatch.setEntity(new StringEntity(jsonBody, StandardCharsets.UTF_8)); |
| | | |
| | | // 执行请求 |
| | |
| | | |
| | | if (neteaseResponse.isSuccess()) { |
| | | result.put("success", true); |
| | | result.put("message", "头像更新成功"); |
| | | result.put("message", "更新成功"); |
| | | result.put("data", neteaseResponse.getData()); |
| | | } else { |
| | | result.put("success", false); |
| | | result.put("message", "头像更新失败: " + neteaseResponse.getMsg()); |
| | | result.put("message", "更新失败: " + neteaseResponse.getMsg()); |
| | | result.put("errorCode", neteaseResponse.getCode()); |
| | | } |
| | | |
| | |
| | | UpdateUserBusinessDto dto = new UpdateUserBusinessDto(); |
| | | if(StringUtils.isNotEmpty(vo.getPhoneNumber())){ |
| | | dto.setMobile(vo.getPhoneNumber()); |
| | | }else if(StringUtils.isNotEmpty(vo.getNickname())){ |
| | | } |
| | | if(StringUtils.isNotEmpty(vo.getNickname())){ |
| | | dto.setName(vo.getNickname()); |
| | | }else if(StringUtils.isNotEmpty(vo.getSignature())){ |
| | | } |
| | | if(StringUtils.isNotEmpty(vo.getSignature())){ |
| | | dto.setSign(vo.getSignature()); |
| | | } |
| | | Map<String, Object> map = updateUserAvatar(vo.getAccountId(), dto); |
| | |
| | | AjaxResult ajaxResult = updateAccountProperties(vo.getAccountId(), vo); |
| | | if(ajaxResult.isSuccess()){ |
| | | UserAccount userAccount = userAccountService.getById(vo.getId()); |
| | | userAccount.setPhoneNumber(vo.getPhoneNumber()); |
| | | userAccount.setAccount(vo.getAccountId()); |
| | | userAccount.setNickname(vo.getNickname()); |
| | | userAccount.setPassword(SymmetricCryptoUtil.encryptPassword(vo.getPassword())); |
| | | userAccount.setSignature(vo.getSignature()); |
| | | if (StringUtils.isNotBlank(vo.getPhoneNumber())) { |
| | | userAccount.setPhoneNumber(vo.getPhoneNumber()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(vo.getAccountId())) { |
| | | userAccount.setAccount(vo.getAccountId()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(vo.getNickname())) { |
| | | userAccount.setNickname(vo.getNickname()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(vo.getPassword())) { |
| | | userAccount.setPassword(SymmetricCryptoUtil.encryptPassword(vo.getPassword())); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(vo.getSignature())) { |
| | | userAccount.setSignature(vo.getSignature()); |
| | | } |
| | | userAccount.setUpdateTime(new Date()); |
| | | userAccountService.updateById(userAccount); |
| | | }else{ |
| | |
| | | if(null != vo.getStatus() && vo.getStatus() == 0){ |
| | | builder.setEnabled(false); |
| | | builder.setNeedKick(true); |
| | | }else if(StringUtils.isNotEmpty(vo.getPassword())){ |
| | | } |
| | | if(StringUtils.isNotEmpty(vo.getPassword())){ |
| | | builder.setToken(vo.getPassword()); |
| | | } |
| | | // 只设置需要的字段 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result batchRegister(RegisterDto dto) { |
| | | if(dto.getType() == 2){ |
| | | return register(dto); |