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

@ -1,18 +1,25 @@
package com.luoo.user.controller; package com.luoo.user.controller;
import java.io.IOException; import annotation.GlobalInterceptor;
import java.util.*; import annotation.VerifyParam;
import java.util.function.Function; import api.PageResult;
import java.util.stream.Collectors; import api.Result;
import api.StatusCode;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs; import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.luoo.user.dao.UserMessageDao; import com.luoo.user.dao.UserMessageDao;
import com.luoo.user.dto.FeedbackImage; import com.luoo.user.dto.*;
import com.luoo.user.dto.TotalCommentVo;
import com.luoo.user.dto.request.LoginReq; import com.luoo.user.dto.request.LoginReq;
import com.luoo.user.dto.request.LogoffReq; import com.luoo.user.dto.request.LogoffReq;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.*; import com.luoo.user.pojo.*;
import com.luoo.user.service.*; import com.luoo.user.service.*;
import com.luoo.user.util.EmojiConverterUtil;
import com.luoo.user.util.IpUtil;
import constants.Constants;
import controller.BaseController;
import dto.UserLoginDto;
import enums.*;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -26,46 +33,19 @@ import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import constants.Constants;
import controller.BaseController;
import com.luoo.user.dto.UserInfoUpdateDto;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.util.EmojiConverterUtil;
import com.luoo.user.util.IpUtil;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;
import dto.UserLoginDto;
import enums.CollectTypeEnum;
import enums.DateTimePatternEnum;
import enums.RequestFrequencyTypeEnum;
import enums.UserBadgeEnum;
import enums.UserRelationEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import util.DateUtil; import util.DateUtil;
import util.IdWorker; import util.IdWorker;
import util.ScaleFilter; import util.ScaleFilter;
import util.StringTools; import util.StringTools;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/my") @RequestMapping("/my")
@ -293,6 +273,7 @@ public class MyController extends BaseController {
} }
return files.stream().map(this::getFeedbackImage).collect(Collectors.toList()); return files.stream().map(this::getFeedbackImage).collect(Collectors.toList());
} }
private FeedbackImage getFeedbackImage(MultipartFile multipartFile) { private FeedbackImage getFeedbackImage(MultipartFile multipartFile) {
FeedbackImage feedbackImage = new FeedbackImage(); FeedbackImage feedbackImage = new FeedbackImage();
try { try {
@ -403,7 +384,6 @@ public class MyController extends BaseController {
List<PublicationLike> list = pageList.stream().parallel().map(x -> getPublicationLike(x)).collect(Collectors.toList()); List<PublicationLike> list = pageList.stream().parallel().map(x -> getPublicationLike(x)).collect(Collectors.toList());
return Result.success(new PageResult<PublicationLike>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<PublicationLike>(Long.valueOf(list.size()), list));
} }
@ -418,6 +398,7 @@ public class MyController extends BaseController {
return publicationLike; return publicationLike;
} }
// 查询我收到的评论 // 查询我收到的评论
@ApiOperation(value = "10.查询我收到的评论分页列表", notes = "游客无法获取") @ApiOperation(value = "10.查询我收到的评论分页列表", notes = "游客无法获取")
@GetMapping("/myCommentReplyList/{page}/{size}") @GetMapping("/myCommentReplyList/{page}/{size}")
@ -565,7 +546,34 @@ public class MyController extends BaseController {
userInfoService.update(userInfo); userInfoService.update(userInfo);
return Result.success(); return Result.success();
} }
private Integer getIndex(UserInfo u) { private Integer getIndex(UserInfo u) {
return Integer.valueOf(Arrays.stream(u.getBadges().split(",")).filter(s -> s.startsWith(String.valueOf(UserBadgeEnum.CONTRIBUTOR.getCode()))).findFirst().get().split("_")[1]); return Integer.valueOf(Arrays.stream(u.getBadges().split(",")).filter(s -> s.startsWith(String.valueOf(UserBadgeEnum.CONTRIBUTOR.getCode()))).findFirst().get().split("_")[1]);
} }
@ApiOperation(value = "15.1 提交实名认证")
@PostMapping("/approve/real/name")
public Result<Void> approveRealName(@RequestHeader(value = "Authorization", required = true) String authorization,
@Validated @RequestBody UserRealNameFormDto userRealNameFormDto) {
userInfoService.approveRealName(authorization, userRealNameFormDto);
return Result.success();
}
@ApiOperation(value = "15.2 审核实名认证")
@PostMapping("/check/real/name")
public Result<Void> checkRealName(@RequestHeader(value = "Authorization", required = true) String authorization,
@Validated @RequestBody UserRealNameCheckDto userRealNameCheckDto) {
userInfoService.checkRealName(authorization, userRealNameCheckDto);
return Result.success();
}
@ApiOperation(value = "15.3 审核实名解绑")
@PostMapping("/unbind/real/name/{id}")
public Result<Void> realNameCheck(@RequestHeader(value = "Authorization", required = true) String authorization,
@PathVariable String id) {
userInfoService.unBindRealName(authorization, id);
return Result.success();
}
} }

@ -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,27 +28,20 @@ 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 {
@ -67,6 +65,9 @@ public class UserInfoService {
@Autowired @Autowired
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@Autowired
private UserRealNameDao userRealNameDao;
/** /**
* token * token
*/ */
@ -428,4 +429,97 @@ public class UserInfoService {
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