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

@ -1,18 +1,25 @@
package com.luoo.user.controller;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
import api.Result;
import api.StatusCode;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.luoo.user.dao.UserMessageDao;
import com.luoo.user.dto.FeedbackImage;
import com.luoo.user.dto.TotalCommentVo;
import com.luoo.user.dto.*;
import com.luoo.user.dto.request.LoginReq;
import com.luoo.user.dto.request.LogoffReq;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.*;
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.springframework.amqp.rabbit.core.RabbitTemplate;
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.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
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.IdWorker;
import util.ScaleFilter;
import util.StringTools;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController
@CrossOrigin
@RequestMapping("/my")
@ -148,11 +128,11 @@ public class MyController extends BaseController {
if (!StringTools.isEmpty(nickName)) {
user.setNickName(nickName);
rabbitTemplate.convertAndSend("userInfoCommentCache",userLoginDto.getUserId());
rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId());
}
if (!StringTools.isEmpty(userInfoUpdateDto.getSignature())) {
String signature = sensitiveWordBs.findFirst(userInfoUpdateDto.getSignature());
if(StringUtils.isNotEmpty(signature)) {
if (StringUtils.isNotEmpty(signature)) {
return Result.failed(StatusCode.USER_SENSITIVE_INFO);
}
user.setSignature(userInfoUpdateDto.getSignature());
@ -177,7 +157,7 @@ public class MyController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
byte[] avatar = file.getBytes();
String fileId=userLoginDto.getUserId() + "_" + idWorker.nextId();
String fileId = userLoginDto.getUserId() + "_" + idWorker.nextId();
String avatarName = fileId
+ StringTools.getFileSuffix(file.getOriginalFilename());
String avatarFilePath = Constants.USER_AVATAR_DIRECTORY + avatarName;
@ -188,18 +168,18 @@ public class MyController extends BaseController {
user.setAvatar(avatarFilePath);
byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_200, Constants.LENGTH_200);
if(null!=thumbnail) {
String thumbnailName = fileId+"_thumbnail"
if (null != thumbnail) {
String thumbnailName = fileId + "_thumbnail"
+ StringTools.getFileSuffix(file.getOriginalFilename());
String thumbnailFilePath = Constants.USER_AVATAR_DIRECTORY + thumbnailName;
s3Service.uploadImage("indie", thumbnailFilePath, thumbnail);
user.setThumbnail(thumbnailFilePath);
}else {
} else {
user.setThumbnail(avatarFilePath);
}
userInfoService.update(user);
rabbitTemplate.convertAndSend("userInfoCommentCache",userLoginDto.getUserId());
rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId());
return Result.success(Constants.RESOURCE_PREFIX + user.getThumbnail());
}
@ -219,16 +199,16 @@ public class MyController extends BaseController {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
//若当前登录用户与查询他人 用户 id一致则为我的主页不查询与他人关系
if(userId.equals(userLoginDto.getUserId())) {
if (userId.equals(userLoginDto.getUserId())) {
return Result.success(userRespDTO);
}
userRespDTO.setRelation(userCollectInfoService.getRelation(userLoginDto.getUserId(),userId).getStatus());
userRespDTO.setRelation(userCollectInfoService.getRelation(userLoginDto.getUserId(), userId).getStatus());
return Result.success(userRespDTO);
}
@ApiOperation(value = "5.查询黑名单")
@ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)})
@GetMapping("/blackList/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserRespDTO>> getBlackList(
@ -240,9 +220,9 @@ public class MyController extends BaseController {
}
@ApiOperation(value = "6.查询关注人信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)})
@GetMapping("/follows/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserRespDTO>> getFollows(
@ -255,9 +235,9 @@ public class MyController extends BaseController {
}
@ApiOperation(value = "7.查询粉丝信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "pageNum", value = "分页: 页码以1开始", required = true),
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true) })
@ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)})
@GetMapping("/fans/{userId}/{pageNum}/{pageSize}")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<UserRespDTO>> getFans(
@ -288,16 +268,17 @@ public class MyController extends BaseController {
}
private List<FeedbackImage> getInputStream(List<MultipartFile> files) {
if(null==files) {
if (null == files) {
return Collections.emptyList();
}
return files.stream().map(this::getFeedbackImage).collect(Collectors.toList());
}
private FeedbackImage getFeedbackImage(MultipartFile multipartFile) {
FeedbackImage feedbackImage=new FeedbackImage();
FeedbackImage feedbackImage = new FeedbackImage();
try {
feedbackImage.setInputStream(multipartFile.getInputStream());
}catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
feedbackImage.setContentType(multipartFile.getContentType());
@ -308,16 +289,16 @@ public class MyController extends BaseController {
private Result<PageResult<UserRespDTO>> getCollectedUserInfo(String userId, Integer pageNum, Integer pageSize,
CollectTypeEnum collectTypeEnum) {
Pageable pageable = PageRequest.of(pageNum-1,pageSize);
boolean isGetFan=isGetFan(collectTypeEnum);
Page<UserCollectInfo> userCollectInfos = isGetFan?userCollectInfoService.findByObjectIdAndCollectType(userId,CollectTypeEnum.FOLLOWS,pageable):userCollectInfoService.findByUserIdAndCollectType(userId,collectTypeEnum,pageable);
Function<UserCollectInfo,String> idFunction=isGetFan?UserCollectInfo::getUserId:UserCollectInfo::getObjectId;
List<String> objectIds=userCollectInfos.stream().map(idFunction).collect(Collectors.toList());
Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
boolean isGetFan = isGetFan(collectTypeEnum);
Page<UserCollectInfo> userCollectInfos = isGetFan ? userCollectInfoService.findByObjectIdAndCollectType(userId, CollectTypeEnum.FOLLOWS, pageable) : userCollectInfoService.findByUserIdAndCollectType(userId, collectTypeEnum, pageable);
Function<UserCollectInfo, String> idFunction = isGetFan ? UserCollectInfo::getUserId : UserCollectInfo::getObjectId;
List<String> objectIds = userCollectInfos.stream().map(idFunction).collect(Collectors.toList());
if (objectIds.isEmpty()) {
return Result.success(new PageResult<UserRespDTO>(0L, Collections.emptyList()));
}
List<UserInfo> userInfos = userInfoService.orderByField(objectIds);
Set<String> bothFollowSet=userCollectInfos.stream().filter(c->Boolean.TRUE.equals(c.getIsMutualFans())).map(u->isGetFan?u.getUserId():u.getObjectId()).collect(Collectors.toSet());
Set<String> bothFollowSet = userCollectInfos.stream().filter(c -> Boolean.TRUE.equals(c.getIsMutualFans())).map(u -> isGetFan ? u.getUserId() : u.getObjectId()).collect(Collectors.toSet());
List<UserRespDTO> results = userInfos.stream().map(s -> getUserRespDTO(s, false, bothFollowSet))
.collect(Collectors.toList());
return Result.success(new PageResult<UserRespDTO>(Long.valueOf(results.size()), results));
@ -330,12 +311,12 @@ public class MyController extends BaseController {
private UserRespDTO getUserRespDTO(UserInfo user, boolean withCount, Set<String> bothFollowSet) {
UserRespDTO userRespDTO = new UserRespDTO();
BeanUtils.copyProperties(user, userRespDTO);
if(!StringTools.isEmpty(user.getBadges())) {
if (!StringTools.isEmpty(user.getBadges())) {
Set<Integer> badgeSet = new HashSet<>();
Arrays.stream(user.getBadges().split(",")).forEach(b->{
int code=Integer.valueOf(b.substring(0, 1));
Arrays.stream(user.getBadges().split(",")).forEach(b -> {
int code = Integer.valueOf(b.substring(0, 1));
badgeSet.add(code);
if(code==UserBadgeEnum.CONTRIBUTOR.getCode()) {
if (code == UserBadgeEnum.CONTRIBUTOR.getCode()) {
userRespDTO.setContributorRole(UserBadgeEnum.getByCode(Integer.valueOf(b.split("_")[0])).getDesc());
}
});
@ -364,24 +345,24 @@ public class MyController extends BaseController {
.sum("commentCount").as("totalComment")
);
AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg,"comment", TotalCommentVo.class);
AggregationResults<TotalCommentVo> results = mongoTemplate.aggregate(agg, "comment", TotalCommentVo.class);
TotalCommentVo totalCommentVo = results.getUniqueMappedResult();
if(null != totalCommentVo) {
if (null != totalCommentVo) {
userRespDTO.setThumbUpCount(totalCommentVo.getTotalThumbup());
userRespDTO.setCommentReplyCount(totalCommentVo.getTotalComment());
}
UserMessage userMessage = userMessageDao.findTopByUserIdOrderBySendTimeDesc(user.getId());
userRespDTO.setHaveNewMessage(false);
if (null!=userMessage) {
if (null != userMessage) {
int read = userMessage.getHaveRead();
userRespDTO.setHaveNewMessage(read==0?true:false);
userRespDTO.setHaveNewMessage(read == 0 ? true : false);
}
return userRespDTO;
}
private String getAvatar(UserInfo user) {
if(StringTools.isEmpty(user.getThumbnail())) {
if (StringTools.isEmpty(user.getThumbnail())) {
return Constants.RESOURCE_PREFIX + user.getAvatar();
}
return Constants.RESOURCE_PREFIX + user.getThumbnail();
@ -390,7 +371,7 @@ public class MyController extends BaseController {
// 查询我的获赞
@ApiOperation(value = "9.查询我的获赞的分页列表", notes = "游客无法获取")
@GetMapping("/myThumbupList/{page}/{size}")
public Result getMyThumbupList(@PathVariable int page,@PathVariable int size,@RequestHeader(value = "Authorization", required = true) String authorization) {
public Result getMyThumbupList(@PathVariable int page, @PathVariable int size, @RequestHeader(value = "Authorization", required = true) String authorization) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
@ -398,30 +379,30 @@ public class MyController extends BaseController {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
Page<PublicationLike> pageList = myService.getMyThumbupList(userId,page,size);
List<PublicationLike> list = pageList.stream().parallel().map(x->getPublicationLike(x)).collect(Collectors.toList());
Page<PublicationLike> pageList = myService.getMyThumbupList(userId, page, size);
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));
}
private PublicationLike getPublicationLike(PublicationLike publicationLike) {
UserInfo userInfo = userInfoService.findById(publicationLike.getUserId());
publicationLike.setNickName("已注销");
publicationLike.setAvatar(Constants.RESOURCE_PREFIX+Constants.DEFAULT_USER_THUMBNAIL);
if(null != userInfo) {
publicationLike.setAvatar(Constants.RESOURCE_PREFIX + Constants.DEFAULT_USER_THUMBNAIL);
if (null != userInfo) {
publicationLike.setNickName(userInfo.getNickName());
publicationLike.setAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar());
publicationLike.setAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
}
return publicationLike;
}
// 查询我收到的评论
@ApiOperation(value = "10.查询我收到的评论分页列表", notes = "游客无法获取")
@GetMapping("/myCommentReplyList/{page}/{size}")
public Result getMyCommentReplyList(@PathVariable int page,@PathVariable int size,@RequestHeader(value = "Authorization", required = true) String authorization) {
public Result getMyCommentReplyList(@PathVariable int page, @PathVariable int size, @RequestHeader(value = "Authorization", required = true) String authorization) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
@ -429,19 +410,19 @@ public class MyController extends BaseController {
return Result.unauthorized(null);
}
String userId = userLoginDto.getUserId();
Page<CommentHis> pageList = myService.getMyCommentReplyList(userId,page,size);
List<CommentHis> list = pageList.stream().parallel().map(x->getCommentHis(x)).collect(Collectors.toList());
return Result.success(new PageResult<CommentHis>(Long.valueOf(list.size()),list));
Page<CommentHis> pageList = myService.getMyCommentReplyList(userId, page, size);
List<CommentHis> list = pageList.stream().parallel().map(x -> getCommentHis(x)).collect(Collectors.toList());
return Result.success(new PageResult<CommentHis>(Long.valueOf(list.size()), list));
}
private CommentHis getCommentHis(CommentHis commentHis) {
UserInfo userInfo = userInfoService.findById(commentHis.getCommenterId());
commentHis.setNickName("已注销");
commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX+Constants.DEFAULT_USER_THUMBNAIL);
if(null != userInfo) {
commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX + Constants.DEFAULT_USER_THUMBNAIL);
if (null != userInfo) {
commentHis.setNickName(userInfo.getNickName());
commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX+userInfo.getAvatar());
commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar());
}
return commentHis;
@ -458,7 +439,7 @@ public class MyController extends BaseController {
private List<UserRespDTO> getThankList() {
List<UserRespDTO> thanks = (List<UserRespDTO>) redisTemplate.opsForValue().get(REDIS_KEY_THANKS);
if (CollectionUtils.isEmpty(thanks)) {
thanks = userInfoService.getThanks().stream().sorted(Comparator.comparing(u->getIndex(u))).map(user->getUserRespDTO(user, false, Collections.emptySet())).collect(Collectors.toList());
thanks = userInfoService.getThanks().stream().sorted(Comparator.comparing(u -> getIndex(u))).map(user -> getUserRespDTO(user, false, Collections.emptySet())).collect(Collectors.toList());
redisTemplate.opsForValue().set(REDIS_KEY_THANKS, thanks);
}
return thanks;
@ -466,7 +447,7 @@ public class MyController extends BaseController {
@ApiOperation(value = "12 注销账号", notes = "注销账号")
@PostMapping ("/logOff")
@PostMapping("/logOff")
public Result<Void> logOff(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam LogoffReq logoffReq) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
@ -499,7 +480,7 @@ public class MyController extends BaseController {
@ApiOperation(value = "13 绑定手机号", notes = "绑定手机号")
@PostMapping ("/bindMobile")
@PostMapping("/bindMobile")
public Result<String> bindMobile(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam LoginReq loginReq) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
@ -517,7 +498,7 @@ public class MyController extends BaseController {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
}
UserInfo userInfo1 =userInfoService.findByMobile(loginReq.getMobile());
UserInfo userInfo1 = userInfoService.findByMobile(loginReq.getMobile());
UserInfo userInfo2 = userInfoService.findById(userId);
if (null != userInfo1) {
// 如果绑定的手机号已存在
@ -538,7 +519,7 @@ public class MyController extends BaseController {
@ApiOperation(value = "14.1 启用/停用 消息, 0为停用1为启用", notes = "启用/停用 消息, 0为停用1为启用")
@PutMapping("/enableNotice/{flag}")
public Result<Void> updateEnableNotice(@RequestHeader(value = "Authorization", required = true) String authorization,@PathVariable int flag){
public Result<Void> updateEnableNotice(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
@ -553,7 +534,7 @@ public class MyController extends BaseController {
@ApiOperation(value = "14.2 启用/停用 推送, 0为停用1为启用", notes = "启用/停用 推送, 0为停用1为启用")
@PutMapping("/enablePush/{flag}")
public Result<Void> updateEnablePush(@RequestHeader(value = "Authorization", required = true) String authorization,@PathVariable int flag){
public Result<Void> updateEnablePush(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) {
//验证是否登录并且拿到ID
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
@ -565,7 +546,34 @@ public class MyController extends BaseController {
userInfoService.update(userInfo);
return Result.success();
}
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;
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,27 +28,20 @@ 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
*
*/
@Service
public class UserInfoService {
@ -67,6 +65,9 @@ public class UserInfoService {
@Autowired
private JwtUtil jwtUtil;
@Autowired
private UserRealNameDao userRealNameDao;
/**
* token
*/
@ -409,7 +410,7 @@ public class UserInfoService {
}
public void bindMobile(UserInfo userInfo){
public void bindMobile(UserInfo userInfo) {
userInfoDao.save(userInfo);
}
@ -422,10 +423,103 @@ public class UserInfoService {
*/
public UserInfo findByUserNameAndPassword(String userName, String password) {
UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName);
if(userInfoByUserName != null && encoder.matches(password, userInfoByUserName.getPassword())) {
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