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

@ -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