|
|
@ -1,21 +1,26 @@
|
|
|
|
package com.luoo.user.service;
|
|
|
|
package com.luoo.user.service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import client.vo.SimpleUser;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import com.luoo.user.dao.UserRealNameDao;
|
|
|
|
|
|
|
|
import com.luoo.user.dto.UserQueryReq;
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import com.luoo.user.dto.UserRealNameCheckDto;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import com.luoo.user.dto.UserRealNameFormDto;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import com.luoo.user.pojo.UserInfo;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import com.luoo.user.pojo.UserRealName;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import com.luoo.user.util.NickNameUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import api.Result;
|
|
|
|
|
|
|
|
import api.StatusCode;
|
|
|
|
|
|
|
|
import com.luoo.user.util.NickNameUtil2;
|
|
|
|
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.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
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.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import util.IdWorker;
|
|
|
|
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 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
|
|
|
|
@Service
|
|
|
|
public class UserInfoService {
|
|
|
|
public class UserInfoService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IdWorker idWorker;
|
|
|
|
private IdWorker idWorker;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private BCryptPasswordEncoder encoder;
|
|
|
|
private BCryptPasswordEncoder encoder;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private HttpServletRequest request;
|
|
|
|
private HttpServletRequest request;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@Autowired
|
|
|
|
* token解析示例
|
|
|
|
private UserRealNameDao userRealNameDao;
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void testParseToken() {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* token解析示例
|
|
|
|
String userInfoid = (String) request.getAttribute("userInfoid");
|
|
|
|
*/
|
|
|
|
String mobile = (String) request.getAttribute("mobile");
|
|
|
|
public void testParseToken() {
|
|
|
|
System.out.println("用户ID" + userInfoid);
|
|
|
|
|
|
|
|
System.out.println("手机号" + mobile);
|
|
|
|
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();
|
|
|
|
* @return
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
public List<UserInfo> findAll() {
|
|
|
|
/**
|
|
|
|
return userInfoDao.findAll();
|
|
|
|
* 根据ID查询实体
|
|
|
|
}
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
/**
|
|
|
|
* @return
|
|
|
|
* 根据ID查询实体
|
|
|
|
*/
|
|
|
|
*
|
|
|
|
public UserInfo findById(String id) {
|
|
|
|
* @param id
|
|
|
|
return userInfoDao.getById(id);
|
|
|
|
* @return
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
public UserInfo findById(String id) {
|
|
|
|
/**
|
|
|
|
return userInfoDao.getById(id);
|
|
|
|
* 修改
|
|
|
|
}
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param userInfo
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
* 修改
|
|
|
|
public void update(UserInfo userInfo) {
|
|
|
|
*
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
* @param userInfo
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void update(UserInfo userInfo) {
|
|
|
|
/**
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
* 删除
|
|
|
|
}
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
* 删除
|
|
|
|
public void deleteById(String id) {
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
String token = (String) request.getAttribute("claims_admin");
|
|
|
|
*/
|
|
|
|
if (token == null || "".equals(token)) {
|
|
|
|
public void deleteById(String id) {
|
|
|
|
throw new RuntimeException("权限不足");
|
|
|
|
|
|
|
|
}
|
|
|
|
String token = (String) request.getAttribute("claims_admin");
|
|
|
|
userInfoDao.deleteById(id);
|
|
|
|
if (token == null || "".equals(token)) {
|
|
|
|
}
|
|
|
|
throw new RuntimeException("权限不足");
|
|
|
|
|
|
|
|
}
|
|
|
|
public void sendSms(String deviceId, String mobile) {
|
|
|
|
userInfoDao.deleteById(id);
|
|
|
|
// 生成6位数字随机数
|
|
|
|
}
|
|
|
|
String checkcode = RandomStringUtils.randomNumeric(6);
|
|
|
|
|
|
|
|
// 向缓存中放一份
|
|
|
|
public void sendSms(String deviceId, String mobile) {
|
|
|
|
String redisKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
|
|
|
|
// 生成6位数字随机数
|
|
|
|
redisTemplate.opsForValue().set(redisKey, checkcode, 15, TimeUnit.MINUTES);
|
|
|
|
String checkcode = RandomStringUtils.randomNumeric(6);
|
|
|
|
|
|
|
|
// 向缓存中放一份
|
|
|
|
// 向用户发一份
|
|
|
|
String redisKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId;
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
redisTemplate.opsForValue().set(redisKey, checkcode, 15, TimeUnit.MINUTES);
|
|
|
|
map.put("mobile", mobile);
|
|
|
|
|
|
|
|
map.put("checkcode", checkcode);
|
|
|
|
// 向用户发一份
|
|
|
|
rabbitTemplate.convertAndSend("sms", map);
|
|
|
|
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) {
|
|
|
|
System.out.println("验证码是:" + checkcode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserInfo login(String mobile, String password) {
|
|
|
|
// UserInfo userInfo = userInfoDao.findByLoginname(loginname);
|
|
|
|
// UserInfo userInfo = userInfoDao.findByLoginname(loginname);
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
if (userInfo != null && encoder.matches(password, userInfo.getPassword())) {
|
|
|
|
if (userInfo != null && encoder.matches(password, userInfo.getPassword())) {
|
|
|
|
return userInfo;
|
|
|
|
return userInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public void updatefanscountandfollowcount(int x, String userInfoid, String friendid) {
|
|
|
|
public void updatefanscountandfollowcount(int x, String userInfoid, String friendid) {
|
|
|
|
userInfoDao.updatefanscount(x, friendid);
|
|
|
|
userInfoDao.updatefanscount(x, friendid);
|
|
|
|
userInfoDao.updatefollowcount(x, userInfoid);
|
|
|
|
userInfoDao.updatefollowcount(x, userInfoid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UserInfo loginOrRegister(String mobile) {
|
|
|
|
public UserInfo loginOrRegister(String mobile) {
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
if (null == userInfo) {
|
|
|
|
if (null == userInfo) {
|
|
|
|
userInfo = new UserInfo();
|
|
|
|
userInfo = new UserInfo();
|
|
|
|
userInfo.setJoinTime(new Date());
|
|
|
|
userInfo.setJoinTime(new Date());
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setMobile(mobile);
|
|
|
|
userInfo.setMobile(mobile);
|
|
|
|
userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return userInfo;
|
|
|
|
return userInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UserInfo findByMobile(String mobile) {
|
|
|
|
public UserInfo findByMobile(String mobile) {
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(mobile);
|
|
|
|
return userInfo;
|
|
|
|
return userInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
|
|
|
|
public String autoLogin(String authorization, String deviceId, String deviceBrand, String ip) {
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
if (null == userLoginDto) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
UserInfo userInfo = userInfoDao.findById(userLoginDto.getUserId()).get();
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfo.setLastLoginIp(ip);
|
|
|
|
userInfo.setLastLoginIp(ip);
|
|
|
|
userInfo.setLastUseDeviceId(deviceId);
|
|
|
|
userInfo.setLastUseDeviceId(deviceId);
|
|
|
|
userInfo.setLastUseDeviceBrand(deviceBrand);
|
|
|
|
userInfo.setLastUseDeviceBrand(deviceBrand);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(),
|
|
|
|
return Constants.TOKEN_PREFIX + jwtUtil.createJWT(userLoginDto.getUserId(), userInfo.getNickName(),
|
|
|
|
userLoginDto.getRoles(), userLoginDto.getAvatar());
|
|
|
|
userLoginDto.getRoles(), userLoginDto.getAvatar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long countByNickName(String nickName) {
|
|
|
|
public long countByNickName(String nickName) {
|
|
|
|
return userInfoDao.countByNickName(nickName);
|
|
|
|
return userInfoDao.countByNickName(nickName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String loginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
public String loginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
if (null == userInfo) {
|
|
|
|
if (null == userInfo) {
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
Date curDate = new Date();
|
|
|
|
Date curDate = new Date();
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// userInfo.setAppleId(loginUserInfo.getAppleId());
|
|
|
|
// userInfo.setAppleId(loginUserInfo.getAppleId());
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String appleLoginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
public String appleLoginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId());
|
|
|
|
UserInfo userInfo = userInfoDao.findByAppleId(loginUserInfo.getAppleId());
|
|
|
|
if (null == userInfo) {
|
|
|
|
if (null == userInfo) {
|
|
|
|
// return "未注册";
|
|
|
|
// return "未注册";
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
Date curDate = new Date();
|
|
|
|
Date curDate = new Date();
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// public String wechatloginOrRegister(UserInfo loginUserInfo) {
|
|
|
|
// 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())) {
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(loginUserInfo.getStatus())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loginUserInfo.setLastLoginTime(new Date());
|
|
|
|
loginUserInfo.setLastLoginTime(new Date());
|
|
|
|
userInfoDao.save(loginUserInfo);
|
|
|
|
userInfoDao.save(loginUserInfo);
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
+ jwtUtil.createJWT(loginUserInfo.getId(), loginUserInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, loginUserInfo.getAvatar());
|
|
|
|
+ jwtUtil.createJWT(loginUserInfo.getId(), loginUserInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, loginUserInfo.getAvatar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String wechatRegister(UserInfo loginUserInfo) {
|
|
|
|
public String wechatRegister(UserInfo loginUserInfo) {
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginUserInfo.getMobile());
|
|
|
|
if (null == userInfo) {
|
|
|
|
if (null == userInfo) {
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
userInfo = loginUserInfo;
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setId(String.valueOf(idWorker.nextId()));
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
userInfo.setNickName(NickNameUtil2.generateRandomString());
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
// userInfo.setNickName("雀乐-" + NickNameUtil.getRandomNickName());
|
|
|
|
Date curDate = new Date();
|
|
|
|
Date curDate = new Date();
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
userInfo.setJoinTime(curDate);
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
userInfo.setLastLoginTime(curDate);
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
userInfo.setStatus(UserStatusEnum.ENABLE.getStatus());
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR);
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
userInfo.setThumbnail(Constants.DEFAULT_USER_THUMBNAIL);
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
userInfo.setWxId(loginUserInfo.getWxId());
|
|
|
|
userInfo.setWxId(loginUserInfo.getWxId());
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
if (!UserStatusEnum.ENABLE.getStatus().equals(userInfo.getStatus())) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfo.setLastLoginTime(new Date());
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
return Constants.TOKEN_PREFIX
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
+ jwtUtil.createJWT(userInfo.getId(), userInfo.getNickName(), Constants.TOKEN_ROLE_APP_USER, userInfo.getAvatar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> orderByField(List<String> idList) {
|
|
|
|
public List<UserInfo> orderByField(List<String> idList) {
|
|
|
|
return userInfoDao.orderByField(idList);
|
|
|
|
return userInfoDao.orderByField(idList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> cmsOrderByField(List<String> idList) {
|
|
|
|
public List<UserInfo> cmsOrderByField(List<String> idList) {
|
|
|
|
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList());
|
|
|
|
return orderByField(idList).stream().map(this::updateAvatarPath).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
|
|
|
|
public List<SimpleUser> getSimpleUserOrderByField(List<String> idList) {
|
|
|
|
return userInfoDao.getSimpleUserOrderByField(idList);
|
|
|
|
return userInfoDao.getSimpleUserOrderByField(idList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq) {
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq) {
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum() - 1, queryReq.getPageSize());
|
|
|
|
PageRequest pageRequest = PageRequest.of(queryReq.getPageNum() - 1, queryReq.getPageSize());
|
|
|
|
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
|
|
|
|
Page<UserInfo> userInfoPage = userInfoDao.findAll(specification, pageRequest);
|
|
|
|
return userInfoPage.map(this::updateAvatarPath);
|
|
|
|
return userInfoPage.map(this::updateAvatarPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private UserInfo updateAvatarPath(UserInfo userInfo) {
|
|
|
|
private UserInfo updateAvatarPath(UserInfo userInfo) {
|
|
|
|
if (null != userInfo && null != userInfo.getAvatar()) {
|
|
|
|
if (null != userInfo && null != userInfo.getAvatar()) {
|
|
|
|
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
|
|
|
|
userInfo.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return userInfo;
|
|
|
|
return userInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
|
|
|
|
public Page<UserInfo> findSearch(UserQueryReq queryReq, int page, int size) {
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
Specification<UserInfo> specification = createUserInfoSpecification(queryReq);
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
return userInfoDao.findAll(specification, pageRequest);
|
|
|
|
return userInfoDao.findAll(specification, pageRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
|
|
|
|
private Specification<UserInfo> createUserInfoSpecification(UserQueryReq queryReq) {
|
|
|
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
return (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
List<Predicate> predicateList = new ArrayList<>();
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getId())) {
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getId())) {
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("id"), queryReq.getId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getMobile())) {
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getMobile())) {
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("mobile").as(String.class), queryReq.getMobile()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getNickName())) {
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getNickName())) {
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%'));
|
|
|
|
predicateList.add(criteriaBuilder.like(root.get("nickName"), '%' + queryReq.getNickName() + '%'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getBadge())) {
|
|
|
|
if (StringUtils.isNotBlank(queryReq.getBadge())) {
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("badge").as(String.class), queryReq.getBadge()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Objects.nonNull(queryReq.getStatus())) {
|
|
|
|
if (Objects.nonNull(queryReq.getStatus())) {
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
|
|
|
|
predicateList.add(criteriaBuilder.equal(root.get("status").as(Integer.class), queryReq.getStatus()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* if(Objects.nonNull(queryReq.getOnlineStatus())){
|
|
|
|
* if(Objects.nonNull(queryReq.getOnlineStatus())){
|
|
|
|
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
|
|
|
|
* predicateList.add(criteriaBuilder.equal(root.get("onlineStatus").as(Integer.
|
|
|
|
* class), queryReq.getOnlineStatus())); }
|
|
|
|
* class), queryReq.getOnlineStatus())); }
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateStart())) {
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateStart())) {
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
queryReq.getCreateDateStart()));
|
|
|
|
queryReq.getCreateDateStart()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateEnd())) {
|
|
|
|
if (Objects.nonNull(queryReq.getCreateDateEnd())) {
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("joinTime").as(Date.class),
|
|
|
|
queryReq.getCreateDateEnd()));
|
|
|
|
queryReq.getCreateDateEnd()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Predicate[] predicates = new Predicate[predicateList.size()];
|
|
|
|
Predicate[] predicates = new Predicate[predicateList.size()];
|
|
|
|
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("joinTime").as(Date.class)));
|
|
|
|
criteriaQuery.orderBy(criteriaBuilder.desc(root.get("joinTime").as(Date.class)));
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(predicates));
|
|
|
|
return criteriaBuilder.and(predicateList.toArray(predicates));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public UserInfo cmsFindById(String id) {
|
|
|
|
public UserInfo cmsFindById(String id) {
|
|
|
|
return updateAvatarPath(userInfoDao.getById(id));
|
|
|
|
return updateAvatarPath(userInfoDao.getById(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<UserInfo> getThanks() {
|
|
|
|
public List<UserInfo> getThanks() {
|
|
|
|
return userInfoDao.getThanks();
|
|
|
|
return userInfoDao.getThanks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void bindMobile(UserInfo userInfo){
|
|
|
|
public void bindMobile(UserInfo userInfo) {
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 校验用户名密码是否匹配
|
|
|
|
* 校验用户名密码是否匹配
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param userName 用户名
|
|
|
|
* @param userName 用户名
|
|
|
|
* @param password 密码
|
|
|
|
* @param password 密码
|
|
|
|
* @return 成功返回该用户,失败返回null
|
|
|
|
* @return 成功返回该用户,失败返回null
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public UserInfo findByUserNameAndPassword(String userName, String password) {
|
|
|
|
public UserInfo findByUserNameAndPassword(String userName, String password) {
|
|
|
|
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
|
|
|
|
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
|
|
|
|
if(userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) {
|
|
|
|
if (userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) {
|
|
|
|
return userInfoByUserName;
|
|
|
|
return userInfoByUserName;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|