release- 新增实名认证业务

release-2024-08-08
pikaqiudeshujia 7 months ago
parent 3d99a4e2fb
commit 2db32b6213

@ -27,4 +27,13 @@ public class ErrorConstants {
public final static String PRICING_MUST_BE_GREATER_THAN_0 = "定价必须大于0"; public final static String PRICING_MUST_BE_GREATER_THAN_0 = "定价必须大于0";
public final static String ALBUM_SONG_LIST_IS_EMPTY = "专辑歌曲为空"; public final static String ALBUM_SONG_LIST_IS_EMPTY = "专辑歌曲为空";
// 用户部分
public final static String REAL_NAME_APPROVE_IS_EXISTS = "该用户实名认证已存在";
public final static String REAL_NAME_IS_CHECKED = "该用户实名认证已审核完成";
public final static String REAL_NAME_ERROR = "实名认证错误";
public final static String REASONS_FOR_REFUSAL_MUST_BE_GIVEN = "必须填写拒绝理由";
} }

@ -0,0 +1,32 @@
package enums;
import lombok.Getter;
/**
* @Author: yawei.huang
* @Package: enums
* @Project: luoo_parent
* @Date: 2024/5/6 15:40
* @Filename: UserRealNameStateEnum
* @Describe:
*/
@Getter
public enum UserRealNameStateEnum {
UNBIND(-1, "解绑"),
CREATE(1, "待审核"),
PASS(2, "通过"),
FAIL(3, "不通过");
private Integer code;
private String desc;
UserRealNameStateEnum(Integer status, String desc) {
this.code = status;
this.desc = desc;
}
}

@ -0,0 +1,22 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.UserRealName;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dao
* @Project: luoo_parent
* @Date: 2024/5/6 15:37
* @Filename: UserRealNameDao
* @Describe:
*/
public interface UserRealNameDao extends JpaRepository<UserRealName,String>, JpaSpecificationExecutor<UserRealName> {
@Query(value = "select * from indie_user.tb_user_real_name where user_id = ? and (state = 1 or state = 2)",nativeQuery = true)
public List<UserRealName> checkExist(String userId);
}

@ -0,0 +1,31 @@
package com.luoo.user.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dto
* @Project: luoo_parent
* @Date: 2024/5/6 15:54
* @Filename: UserRealNameCheckDto
* @Describe:
*/
@Data
public class UserRealNameCheckDto implements Serializable {
@ApiModelProperty("实名认证id")
@NotBlank(message = "id不能为空")
private String id;
@ApiModelProperty("审核结果")
@NotNull(message = "审核结果不能为空")
private Integer state;
@ApiModelProperty("拒绝理由")
private String content;
}

@ -0,0 +1,48 @@
package com.luoo.user.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* @Author: yawei.huang
* @Package: com.luoo.user.dto
* @Project: luoo_parent
* @Date: 2024/5/6 15:30
* @Filename: UserRealNameAddDto
* @Describe:
*/
@Data
public class UserRealNameFormDto implements Serializable {
/**
*
*/
@ApiModelProperty("真名")
@NotBlank(message = "姓名不能为空")
private String realName;
/**
*
*/
@ApiModelProperty("身份证号")
@NotBlank(message = "身份证号不能为空")
private String idCard;
/**
* url
*/
@ApiModelProperty("身份证正面url")
@NotBlank(message = "请上传身份证正面")
private String frontUrl;
/**
* url
*/
@ApiModelProperty("身份证反面url")
@NotBlank(message = "请上传身份证反面")
private String backUrl;
}

@ -0,0 +1,95 @@
package com.luoo.user.pojo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
*
*
* @TableName tb_user_real_name
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Builder
@Entity
@Table(name = "tb_user_real_name")
public class UserRealName implements Serializable {
/**
* id
*/
@Id
@ApiModelProperty("id")
private String id;
/**
* user_infoid
*/
@ApiModelProperty("user_info表id")
private String userId;
/**
*
*/
@ApiModelProperty("真名")
private String realName;
/**
*
*/
@ApiModelProperty("身份证号")
private String idCard;
/**
* url
*/
@ApiModelProperty("身份证正面url")
private String frontUrl;
/**
* url
*/
@ApiModelProperty("身份证反面url")
private String backUrl;
/**
* 1- 2- 3- -1
*/
@ApiModelProperty("实名认证状态 1-审核中 2-审核通过 3-审核失败 -1解绑")
private Integer state;
/**
*
*/
@ApiModelProperty("拒绝理由")
private String content;
/**
*
*/
@ApiModelProperty("创建时间")
@CreatedDate
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;
/**
*
*/
@ApiModelProperty("修改时间")
@LastModifiedDate
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime updateTime;
/**
*
*/
@ApiModelProperty("创建人")
private String createUser;
/**
*
*/
@ApiModelProperty("修改人")
private String updateUser;
}

@ -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);
}
} }

@ -0,0 +1,18 @@
create table tb_user_real_name
(
id varchar(20) not null comment 'id'
primary key,
user_id varchar(20) not null comment 'user_info表id',
real_name varchar(255) not null comment '真名',
id_card varchar(255) null comment '身份证号',
front_url varchar(255) null comment '身份证正面url',
back_url varchar(255) null comment '身份证反面url',
state int null comment '实名认证状态 1-审核中 2-审核通过 3-审核失败 -1解绑',
content longtext null comment '拒绝理由',
create_time datetime null comment '创建时间',
update_time datetime null comment '修改时间',
create_user varchar(20) null comment '创建人',
update_user varchar(20) null comment '修改人'
)
comment '实名认证表单';
Loading…
Cancel
Save