|
|
|
@ -1,21 +1,26 @@
|
|
|
|
|
package com.luoo.user.service;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
import api.StatusCode;
|
|
|
|
|
import client.vo.SimpleUser;
|
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
|
import com.luoo.user.dao.UserRealNameDao;
|
|
|
|
|
import com.luoo.user.dto.UserQueryReq;
|
|
|
|
|
import com.luoo.user.dto.UserRealNameCheckDto;
|
|
|
|
|
import com.luoo.user.dto.UserRealNameFormDto;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.pojo.UserRealName;
|
|
|
|
|
import com.luoo.user.util.NickNameUtil;
|
|
|
|
|
import com.luoo.user.util.NickNameUtil2;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import constants.ErrorConstants;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.UserRealNameStateEnum;
|
|
|
|
|
import enums.UserStatusEnum;
|
|
|
|
|
import exception.BizException;
|
|
|
|
|
import org.apache.commons.lang.ObjectUtils;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
@ -23,238 +28,234 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import util.IdWorker;
|
|
|
|
|
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
|
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
|
import com.luoo.user.dto.UserQueryReq;
|
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
|
import com.luoo.user.util.NickNameUtil;
|
|
|
|
|
|
|
|
|
|
import client.vo.SimpleUser;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.UserStatusEnum;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 服务层
|
|
|
|
|
*
|
|
|
|
|
* @author Administrator
|
|
|
|
|
*
|
|
|
|
|
* @author Administrator
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class UserInfoService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BCryptPasswordEncoder encoder;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* token解析示例
|
|
|
|
|
*/
|
|
|
|
|
public void testParseToken() {
|
|
|
|
|
|
|
|
|
|
String userInfoid = (String) request.getAttribute("userInfoid");
|
|
|
|
|
String mobile = (String) request.getAttribute("mobile");
|
|
|
|
|
System.out.println("用户ID" + userInfoid);
|
|
|
|
|
System.out.println("手机号" + mobile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询全部列表
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<UserInfo> findAll() {
|
|
|
|
|
return userInfoDao.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询实体
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public UserInfo findById(String id) {
|
|
|
|
|
return userInfoDao.getById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*
|
|
|
|
|
* @param userInfo
|
|
|
|
|
*/
|
|
|
|
|
public void update(UserInfo userInfo) {
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
public void deleteById(String id) {
|
|
|
|
|
|
|
|
|
|
String token = (String) request.getAttribute("claims_admin");
|
|
|
|
|
if (token == null || "".equals(token)) {
|
|
|
|
|
throw new RuntimeException("权限不足");
|
|
|
|
|
}
|
|
|
|
|
userInfoDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sendSms(String deviceId, String mobile) {
|
|
|
|
|
// 生成6位数字随机数
|
|
|
|
|
String checkcode = RandomStringUtils.randomNumeric(6);
|
|
|
|
|
// 向缓存中放一份
|
|
|
|
|
String redisKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey, checkcode, 15, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
// 向用户发一份
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("mobile", mobile);
|
|
|
|
|
map.put("checkcode", checkcode);
|
|
|
|
|
rabbitTemplate.convertAndSend("sms", map);
|
|
|
|
|
|
|
|
|
|
// 在控制台放一份(方便测试)
|
|
|
|
|
|
|
|
|
|
System.out.println("验证码是:" + checkcode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo login(String mobile, String password) {
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private BCryptPasswordEncoder encoder;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserRealNameDao userRealNameDao;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* token解析示例
|
|
|
|
|
*/
|
|
|
|
|
public void testParseToken() {
|
|
|
|
|
|
|
|
|
|
String userInfoid = (String) request.getAttribute("userInfoid");
|
|
|
|
|
String mobile = (String) request.getAttribute("mobile");
|
|
|
|
|
System.out.println("用户ID" + userInfoid);
|
|
|
|
|
System.out.println("手机号" + mobile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询全部列表
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<UserInfo> findAll() {
|
|
|
|
|
return userInfoDao.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据ID查询实体
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public UserInfo findById(String id) {
|
|
|
|
|
return userInfoDao.getById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*
|
|
|
|
|
* @param userInfo
|
|
|
|
|
*/
|
|
|
|
|
public void update(UserInfo userInfo) {
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
public void deleteById(String id) {
|
|
|
|
|
|
|
|
|
|
String token = (String) request.getAttribute("claims_admin");
|
|
|
|
|
if (token == null || "".equals(token)) {
|
|
|
|
|
throw new RuntimeException("权限不足");
|
|
|
|
|
}
|
|
|
|
|
userInfoDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sendSms(String deviceId, String mobile) {
|
|
|
|
|
// 生成6位数字随机数
|
|
|
|
|
String checkcode = RandomStringUtils.randomNumeric(6);
|
|
|
|
|
// 向缓存中放一份
|
|
|
|
|
String redisKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey, checkcode, 15, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
// 向用户发一份
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("mobile", mobile);
|
|
|
|
|
map.put("checkcode", checkcode);
|
|
|
|
|
rabbitTemplate.convertAndSend("sms", map);
|
|
|
|
|
|
|
|
|
|
// 在控制台放一份(方便测试)
|
|
|
|
|
|
|
|
|
|
System.out.println("验证码是:" + checkcode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo login(String mobile, String password) {
|
|
|
|
|
// UserInfo userInfo = userInfoDao.findByLoginname(loginname);
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
|
if (userInfo != null && encoder.matches(password, userInfo.getPassword())) {
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public void updatefanscountandfollowcount(int x, String userInfoid, String friendid) {
|
|
|
|
|
userInfoDao.updatefanscount(x, friendid);
|
|
|
|
|
userInfoDao.updatefollowcount(x, userInfoid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo loginOrRegister(String mobile) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo = new UserInfo();
|
|
|
|
|
userInfo.setJoinTime(new Date());
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
userInfo.setMobile(mobile);
|
|
|
|
|
userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
}
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo findByMobile(String mobile) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfo.setLastLoginIp(ip);
|
|
|
|
|
userInfo.setLastUseDeviceId(deviceId);
|
|
|
|
|
userInfo.setLastUseDeviceBrand(deviceBrand);
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(),
|
|
|
|
|
userLoginDto.getRoles(), userLoginDto.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long countByNickName(String nickName) {
|
|
|
|
|
return userInfoDao.countByNickName(nickName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String loginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
|
if (userInfo != null && encoder.matches(password, userInfo.getPassword())) {
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
|
public void updatefanscountandfollowcount(int x, String userInfoid, String friendid) {
|
|
|
|
|
userInfoDao.updatefanscount(x, friendid);
|
|
|
|
|
userInfoDao.updatefollowcount(x, userInfoid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo loginOrRegister(String mobile) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo = new UserInfo();
|
|
|
|
|
userInfo.setJoinTime(new Date());
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
userInfo.setMobile(mobile);
|
|
|
|
|
userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
}
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo findByMobile(String mobile) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
|
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfo.setLastLoginIp(ip);
|
|
|
|
|
userInfo.setLastUseDeviceId(deviceId);
|
|
|
|
|
userInfo.setLastUseDeviceBrand(deviceBrand);
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(),
|
|
|
|
|
userLoginDto.getRoles(), userLoginDto.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long countByNickName(String nickName) {
|
|
|
|
|
return userInfoDao.countByNickName(nickName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String loginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// userInfo.setAppleId(loginUserInfo.getAppleId());
|
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
|
}
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String appleLoginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId());
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
|
}
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String appleLoginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId());
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
// return "未注册";
|
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
|
}
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
|
}
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// public String wechatloginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
@ -286,146 +287,239 @@ public class UserInfoService {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String wechatlogin(UserInfo loginUserInfo) {
|
|
|
|
|
public String wechatlogin(UserInfo loginUserInfo) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(loginUserInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
loginUserInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(loginUserInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(loginUserInfo.getId(), loginUserInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, loginUserInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(loginUserInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
loginUserInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(loginUserInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(loginUserInfo.getId(), loginUserInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, loginUserInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String wechatRegister(UserInfo loginUserInfo) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
|
public String wechatRegister(UserInfo loginUserInfo) {
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
|
if (null == userInfo) {
|
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userInfo.setWxId(loginUserInfo.getWxId());
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> orderByField(List<String> idList) {
|
|
|
|
|
return userInfoDao.orderByField(idList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> cmsOrderByField(List<String> idList) {
|
|
|
|
|
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
|
|
|
|
|
return userInfoDao.getSimpleUserOrderByField(idList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq) {
|
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum() - 1, queryReq.getPageSize());
|
|
|
|
|
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
return userInfoPage.map(this::updateAvatarPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserInfo updateAvatarPath(UserInfo userInfo) {
|
|
|
|
|
if (null != userInfo && null != userInfo.getAvatar()) {
|
|
|
|
|
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
|
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
return userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
|
|
|
|
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getId())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getMobile())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getNickName())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%'));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getBadge())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryReq.getStatus())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* if(Objects.nonNull(queryReq.getOnlineStatus())){
|
|
|
|
|
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
|
|
|
|
|
* class), queryReq.getOnlineStatus())); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateStart())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateStart()));
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateEnd())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateEnd()));
|
|
|
|
|
}
|
|
|
|
|
Predicate[] predicates = new Predicate[predicateList.size()];
|
|
|
|
|
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("joinTime").as(Date.class)));
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(predicates));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo cmsFindById(String id) {
|
|
|
|
|
return updateAvatarPath(userInfoDao.getById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> getThanks() {
|
|
|
|
|
return userInfoDao.getThanks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void bindMobile(UserInfo userInfo){
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验用户名密码是否匹配
|
|
|
|
|
*
|
|
|
|
|
* @param userName 用户名
|
|
|
|
|
* @param password 密码
|
|
|
|
|
* @return 成功返回该用户,失败返回null
|
|
|
|
|
*/
|
|
|
|
|
public UserInfo findByUserNameAndPassword(String userName, String password) {
|
|
|
|
|
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
|
|
|
|
|
if(userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) {
|
|
|
|
|
return userInfoByUserName;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Date curDate = new Date();
|
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
} else {
|
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userInfo.setWxId(loginUserInfo.getWxId());
|
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> orderByField(List<String> idList) {
|
|
|
|
|
return userInfoDao.orderByField(idList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> cmsOrderByField(List<String> idList) {
|
|
|
|
|
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
|
|
|
|
|
return userInfoDao.getSimpleUserOrderByField(idList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq) {
|
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum() - 1, queryReq.getPageSize());
|
|
|
|
|
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
return userInfoPage.map(this::updateAvatarPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UserInfo updateAvatarPath(UserInfo userInfo) {
|
|
|
|
|
if (null != userInfo && null != userInfo.getAvatar()) {
|
|
|
|
|
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
|
|
|
|
|
}
|
|
|
|
|
return userInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
|
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
return userInfoDao.findAll(specification, pageRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
|
|
|
|
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getId())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getMobile())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getNickName())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%'));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getBadge())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryReq.getStatus())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* if(Objects.nonNull(queryReq.getOnlineStatus())){
|
|
|
|
|
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
|
|
|
|
|
* class), queryReq.getOnlineStatus())); }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateStart())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateStart()));
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateEnd())) {
|
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
|
queryReq.getCreateDateEnd()));
|
|
|
|
|
}
|
|
|
|
|
Predicate[] predicates = new Predicate[predicateList.size()];
|
|
|
|
|
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("joinTime").as(Date.class)));
|
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(predicates));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UserInfo cmsFindById(String id) {
|
|
|
|
|
return updateAvatarPath(userInfoDao.getById(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> getThanks() {
|
|
|
|
|
return userInfoDao.getThanks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void bindMobile(UserInfo userInfo) {
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验用户名密码是否匹配
|
|
|
|
|
*
|
|
|
|
|
* @param userName 用户名
|
|
|
|
|
* @param password 密码
|
|
|
|
|
* @return 成功返回该用户,失败返回null
|
|
|
|
|
*/
|
|
|
|
|
public UserInfo findByUserNameAndPassword(String userName, String password) {
|
|
|
|
|
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
|
|
|
|
|
if (userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) {
|
|
|
|
|
return userInfoByUserName;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交实名认证
|
|
|
|
|
*
|
|
|
|
|
* @param token token
|
|
|
|
|
* @param userRealNameFormDto 实名认证对象
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void approveRealName(String token, UserRealNameFormDto userRealNameFormDto) {
|
|
|
|
|
UserRealName userRealName = new UserRealName();
|
|
|
|
|
BeanUtils.copyProperties(userRealNameFormDto, userRealName);
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
if (user != null) {
|
|
|
|
|
userRealName.setCreateUser(user.getUserId());
|
|
|
|
|
} else {
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
userRealName.setState(UserRealNameStateEnum.CREATE.getCode());
|
|
|
|
|
|
|
|
|
|
// 校验是否允许
|
|
|
|
|
List<UserRealName> userRealNames = userRealNameDao.checkExist(user.getUserId());
|
|
|
|
|
if (!userRealNames.isEmpty()) {
|
|
|
|
|
// 该用户实名认证已存在
|
|
|
|
|
throw new BizException(ErrorConstants.REAL_NAME_APPROVE_IS_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userRealNameDao.save(userRealName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 审核实名认证
|
|
|
|
|
*
|
|
|
|
|
* @param token token
|
|
|
|
|
* @param userRealNameCheckDto 审核对象
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void checkRealName(String token, UserRealNameCheckDto userRealNameCheckDto) {
|
|
|
|
|
|
|
|
|
|
UserRealName userRealName = userRealNameDao.findById(userRealNameCheckDto.getId()).get();
|
|
|
|
|
if (userRealName == null) {
|
|
|
|
|
// 实名认证错误
|
|
|
|
|
throw new BizException(ErrorConstants.REAL_NAME_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ObjectUtils.notEqual(UserRealNameStateEnum.CREATE.getCode(), userRealName.getState())) {
|
|
|
|
|
// 该用户实名认证已审核完成
|
|
|
|
|
throw new BizException(ErrorConstants.REAL_NAME_IS_CHECKED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ObjectUtils.equals(UserRealNameStateEnum.FAIL.getCode(), userRealNameCheckDto.getState())
|
|
|
|
|
&& StringUtils.isBlank(userRealNameCheckDto.getContent())) {
|
|
|
|
|
// 必须填写拒绝理由
|
|
|
|
|
throw new BizException(ErrorConstants.REASONS_FOR_REFUSAL_MUST_BE_GIVEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
if (user != null) {
|
|
|
|
|
userRealName.setCreateUser(user.getUserId());
|
|
|
|
|
} else {
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userRealName.setContent(userRealNameCheckDto.getContent());
|
|
|
|
|
userRealName.setState(userRealNameCheckDto.getState());
|
|
|
|
|
userRealName.setUpdateUser(user.getUserId());
|
|
|
|
|
userRealNameDao.save(userRealName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解绑实名认证
|
|
|
|
|
*
|
|
|
|
|
* @param token token
|
|
|
|
|
* @param id 实名认证id
|
|
|
|
|
*/
|
|
|
|
|
public void unBindRealName(String token, String id) {
|
|
|
|
|
UserRealName userRealName = userRealNameDao.findById(id).get();
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
if (user != null) {
|
|
|
|
|
if (ObjectUtils.notEqual(user.getUserId(), userRealName.getCreateUser())) {
|
|
|
|
|
// 必须本人操作
|
|
|
|
|
throw new BizException(ErrorConstants.MUST_OPERATE_IN_PERSON);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 用户校验失败,请重新登录
|
|
|
|
|
throw new BizException(ErrorConstants.USER_VERIFICATION_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userRealName.setState(UserRealNameStateEnum.UNBIND.getCode());
|
|
|
|
|
userRealName.setUpdateUser(user.getUserId());
|
|
|
|
|
userRealNameDao.save(userRealName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|