|
|
|
|
@@ -1,18 +1,14 @@
|
|
|
|
|
package com.bao.dating.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.bao.dating.common.Result;
|
|
|
|
|
import com.bao.dating.common.ResultCode;
|
|
|
|
|
import com.bao.dating.common.aliyun.AliOssUtil;
|
|
|
|
|
import com.bao.dating.common.aliyun.GreenImageScan;
|
|
|
|
|
import com.bao.dating.common.aliyun.GreenTextScan;
|
|
|
|
|
import com.bao.dating.common.aliyun.SmsUtil;
|
|
|
|
|
import com.bao.dating.common.result.AliOssResult;
|
|
|
|
|
import com.bao.dating.common.result.GreenAuditResult;
|
|
|
|
|
import com.bao.dating.config.RedisConfig;
|
|
|
|
|
import com.bao.dating.context.UserContext;
|
|
|
|
|
import com.bao.dating.mapper.UserMapper;
|
|
|
|
|
import com.bao.dating.pojo.dto.UserInfoDTO;
|
|
|
|
|
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
|
|
|
|
import com.bao.dating.pojo.dto.UserLoginDTO;
|
|
|
|
|
import com.bao.dating.pojo.entity.User;
|
|
|
|
|
import com.bao.dating.pojo.vo.UserInfoVO;
|
|
|
|
|
@@ -28,6 +24,7 @@ import io.jsonwebtoken.Claims;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
@@ -245,12 +242,12 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新用户信息
|
|
|
|
|
* @param userInfoUpdateDTO
|
|
|
|
|
* @param userInfoDTO
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public UserInfoVO updateUserInfo(UserInfoUpdateDTO userInfoUpdateDTO) {
|
|
|
|
|
Long userId = userInfoUpdateDTO.getUserId();
|
|
|
|
|
public UserInfoVO updateUserInfo(UserInfoDTO userInfoDTO) {
|
|
|
|
|
Long userId = userInfoDTO.getUserId();
|
|
|
|
|
User user = userMapper.selectByUserId(userId);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
throw new RuntimeException("用户不存在");
|
|
|
|
|
@@ -259,16 +256,16 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
// 将需要审核的内容合并成一个文本,用于减少调用次数
|
|
|
|
|
StringBuilder textBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
if (userInfoUpdateDTO.getNickname() != null && !userInfoUpdateDTO.getNickname().isEmpty()) {
|
|
|
|
|
textBuilder.append(userInfoUpdateDTO.getNickname()).append(" ");
|
|
|
|
|
if (userInfoDTO.getNickname() != null && !userInfoDTO.getNickname().isEmpty()) {
|
|
|
|
|
textBuilder.append(userInfoDTO.getNickname()).append(" ");
|
|
|
|
|
}
|
|
|
|
|
if (userInfoUpdateDTO.getHobbies() != null && !userInfoUpdateDTO.getHobbies().isEmpty()) {
|
|
|
|
|
if (userInfoDTO.getHobbies() != null && !userInfoDTO.getHobbies().isEmpty()) {
|
|
|
|
|
// 将爱好列表转换为字符串,用空格分隔
|
|
|
|
|
String hobbiesStr = String.join(" ", userInfoUpdateDTO.getHobbies());
|
|
|
|
|
String hobbiesStr = String.join(" ", userInfoDTO.getHobbies());
|
|
|
|
|
textBuilder.append(hobbiesStr).append(" ");
|
|
|
|
|
}
|
|
|
|
|
if (userInfoUpdateDTO.getSignature() != null && !userInfoUpdateDTO.getSignature().isEmpty()) {
|
|
|
|
|
textBuilder.append(userInfoUpdateDTO.getSignature()).append(" ");
|
|
|
|
|
if (userInfoDTO.getSignature() != null && !userInfoDTO.getSignature().isEmpty()) {
|
|
|
|
|
textBuilder.append(userInfoDTO.getSignature()).append(" ");
|
|
|
|
|
}
|
|
|
|
|
// 文本审核
|
|
|
|
|
if (textBuilder.length() > 0) {
|
|
|
|
|
@@ -330,92 +327,6 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
return userInfoVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新用户信息
|
|
|
|
|
*
|
|
|
|
|
* @param userInfoUpdateDTO 用户信息更新参数
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public UserInfoVO updateUserInfo(UserInfoUpdateDTO userInfoUpdateDTO) {
|
|
|
|
|
Long userId = userInfoUpdateDTO.getUserId();
|
|
|
|
|
User user = userMapper.selectByUserId(userId);
|
|
|
|
|
if (user == null) {
|
|
|
|
|
throw new RuntimeException("用户不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将需要审核的内容合并成一个文本,用于减少调用次数
|
|
|
|
|
StringBuilder textBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
if (userInfoUpdateDTO.getNickname() != null && !userInfoUpdateDTO.getNickname().isEmpty()) {
|
|
|
|
|
textBuilder.append(userInfoUpdateDTO.getNickname()).append(" ");
|
|
|
|
|
}
|
|
|
|
|
if (userInfoUpdateDTO.getHobbies() != null && !userInfoUpdateDTO.getHobbies().isEmpty()) {
|
|
|
|
|
// 将爱好列表转换为字符串,用空格分隔
|
|
|
|
|
String hobbiesStr = String.join(" ", userInfoUpdateDTO.getHobbies());
|
|
|
|
|
textBuilder.append(hobbiesStr).append(" ");
|
|
|
|
|
}
|
|
|
|
|
if (userInfoUpdateDTO.getSignature() != null && !userInfoUpdateDTO.getSignature().isEmpty()) {
|
|
|
|
|
textBuilder.append(userInfoUpdateDTO.getSignature()).append(" ");
|
|
|
|
|
}
|
|
|
|
|
// 文本审核
|
|
|
|
|
if (textBuilder.length() > 0) {
|
|
|
|
|
Map textResult;
|
|
|
|
|
try {
|
|
|
|
|
textResult = greenTextScan.greeTextScan(textBuilder.toString());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("用户信息文本审核失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String suggestion = (String) textResult.get("suggestion");
|
|
|
|
|
|
|
|
|
|
if (GreenAuditResult.BLOCK.equals(suggestion)) {
|
|
|
|
|
throw new RuntimeException("用户信息包含违规内容,修改失败");
|
|
|
|
|
}
|
|
|
|
|
if (GreenAuditResult.REVIEW.equals(suggestion)) {
|
|
|
|
|
throw new RuntimeException("用户信息需要人工审核,暂无法修改");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 图片审核
|
|
|
|
|
List<String> imageKeys = new ArrayList<>();
|
|
|
|
|
if (userInfoUpdateDTO.getAvatarUrl() != null && !userInfoUpdateDTO.getAvatarUrl().isEmpty()) {
|
|
|
|
|
imageKeys.add(userInfoUpdateDTO.getAvatarUrl());
|
|
|
|
|
}
|
|
|
|
|
if (userInfoUpdateDTO.getBackgroundUrl() != null && !userInfoUpdateDTO.getBackgroundUrl().isEmpty()) {
|
|
|
|
|
imageKeys.add(userInfoUpdateDTO.getBackgroundUrl());
|
|
|
|
|
}
|
|
|
|
|
if (!imageKeys.isEmpty()) {
|
|
|
|
|
Map imageResult;
|
|
|
|
|
try {
|
|
|
|
|
imageResult = greenImageScan.imageScan(imageKeys);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException("用户图片审核失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String suggestion = (String) imageResult.get("suggestion");
|
|
|
|
|
|
|
|
|
|
if (GreenAuditResult.BLOCK.equals(suggestion)) {
|
|
|
|
|
throw new RuntimeException("头像或背景图不合规,修改失败");
|
|
|
|
|
}
|
|
|
|
|
if (GreenAuditResult.REVIEW.equals(suggestion)) {
|
|
|
|
|
throw new RuntimeException("头像或背景图需要人工审核,暂无法修改");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 默认昵称兜底
|
|
|
|
|
if (userInfoUpdateDTO.getNickname() == null || userInfoUpdateDTO.getNickname().trim().isEmpty()) {
|
|
|
|
|
userInfoUpdateDTO.setNickname(user.getUserName());
|
|
|
|
|
}
|
|
|
|
|
userInfoUpdateDTO.setUpdatedAt(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
// 更新数据库
|
|
|
|
|
userMapper.updateUserInfoByUserId(userInfoUpdateDTO);
|
|
|
|
|
|
|
|
|
|
// 封装返回结果
|
|
|
|
|
User updatedUser = userMapper.selectByUserId(userInfoUpdateDTO.getUserId());
|
|
|
|
|
UserInfoVO userInfoVO = new UserInfoVO();
|
|
|
|
|
BeanUtils.copyProperties(updatedUser, userInfoVO);
|
|
|
|
|
return userInfoVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户注册
|
|
|
|
|
@@ -459,11 +370,13 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
@Override
|
|
|
|
|
public UserLoginVO emailLogin(String email, String code) {
|
|
|
|
|
User user = userMapper.selectByUserEmailUser(email);
|
|
|
|
|
if (user == null)
|
|
|
|
|
if (user == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
boolean flag = verificationCodeService.verifyEmailCode(email, code);
|
|
|
|
|
if (!flag)
|
|
|
|
|
if (!flag) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// 生成token
|
|
|
|
|
String token = JwtUtil.generateToken(String.valueOf(user.getUserId()));
|
|
|
|
|
UserLoginVO userLoginVO = new UserLoginVO();
|
|
|
|
|
|