diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index fc7b8db..d0970bf 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -39,6 +39,7 @@ import org.springframework.data.mongodb.core.aggregation.Aggregation; 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.scheduling.annotation.Async; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -59,475 +60,512 @@ import java.util.stream.Collectors; @RequestMapping("/my") @Api(tags = "MyController") public class MyController extends BaseController { - private static final String REDIS_KEY_THANKS = "thanks"; - @Autowired - private S3Service s3Service; - @Autowired - private UserInfoService userInfoService; - @Autowired - private IdWorker idWorker; - @Autowired - private UserCollectInfoService userCollectInfoService; - - @Autowired - private FeedbackService feedbackService; - - @Autowired - private MyService myService; - - @Autowired - private MongoTemplate mongoTemplate; - - @Autowired - private RabbitTemplate rabbitTemplate; - - @Autowired - private SensitiveWordBs sensitiveWordBs; - - @Autowired - private RedisTemplate redisTemplate; - - @Autowired - private UserMessageDao userMessageDao; - - @Autowired - private UserPointLogService userPointLogService; - - @Autowired - private UserinfoShippingAddressService userinfoShippingAddressService; - - @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") - @GetMapping("/userInfo") - @GlobalInterceptor(checkAppUserLogin = true) - public Result getUserInfo( - @RequestHeader(value = "Authorization", required = true) String authorization) { - UserLoginDto userLoginDto = getUserLoginDto(authorization); - UserInfo user = userInfoService.findById(userLoginDto.getUserId()); - UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet()); - userRespDTO.setMobile(user.getMobile()); - userRespDTO.setWxId(user.getWxId()); - userRespDTO.setAppleId(user.getAppleId()); - userRespDTO.setWxNickname(user.getWxNickname()); - userRespDTO.setAppleEmail(user.getAppleEmail()); - userRespDTO.setEnableNotice(1); - userRespDTO.setEnablePush(1); - userRespDTO.setVipStatus(user.getVipStatus()); - userRespDTO.setVipExpireTime(user.getVipExpireTime()); - userRespDTO.setEnableChat(user.getEnableChat()); - userRespDTO.setEnableComment(user.getEnableComment()); - userRespDTO.setPoint(user.getPoint()); - userRespDTO.setMyInvitationCode(user.getInvitationCode()); - userRespDTO.setIsBetaUser(user.getIsBetaUser()); - - String invitationUserId = user.getInvitationUserId(); - if (StringUtils.isNotEmpty(invitationUserId)) { - UserInfo myInvitationUser = userInfoService.findById(invitationUserId); - userRespDTO.setInvitationUserId(myInvitationUser.getId()); - userRespDTO.setInvitationCode(myInvitationUser.getInvitationCode()); - } else { - userRespDTO.setInvitationCode(null); - } - - if (null != user.getEnableNotice()) { - userRespDTO.setEnableNotice(user.getEnableNotice()); - } - if (null != user.getEnablePush()) { - userRespDTO.setEnablePush(user.getEnablePush()); - } - return Result.success(userRespDTO); - } - - @ApiOperation(value = "1.1 根据邀请码获取用户部分信息", notes = "无认证") - @GetMapping("/userInfo/invite") - public Result getUserInfoForInvite(String inviteCode) { - UserInfo userInfoByInvitationCode = userInfoService.getUserInfoByInvitationCode(inviteCode); - if(userInfoByInvitationCode != null) { - return Result.success(new UserInfoForInviteVO(userInfoByInvitationCode.getNickName(), Constants.RESOURCE_PREFIX + userInfoByInvitationCode.getAvatar(), inviteCode)); - } else { - return Result.failed(ErrorConstants.USER_INVITE_CODE_NOT_EXIST); - } - } - - @ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息") - @PutMapping("/userInfo") - @GlobalInterceptor(checkAppUserLogin = true) - public Result updateUserInfo(@RequestHeader(value = "Authorization", required = true) String authorization, - @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) { - UserLoginDto userLoginDto = getUserLoginDto(authorization); - UserInfo user = userInfoService.findById(userLoginDto.getUserId()); - String nickName = EmojiConverterUtil.encode(userInfoUpdateDto.getNickName()); - - String result = sensitiveWordBs.findFirst(nickName); - if (StringUtils.isNotEmpty(result)) { - return Result.failed(StatusCode.USER_SENSITIVE_INFO); - } - if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) { - long count = userInfoService.countByNickName(nickName); - if (count > 0) { - return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST); - } - } - - if (!StringTools.isEmpty(nickName)) { - user.setNickName(nickName); - rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); - } - if (!StringTools.isEmpty(userInfoUpdateDto.getSignature())) { - String signature = sensitiveWordBs.findFirst(userInfoUpdateDto.getSignature()); - if (StringUtils.isNotEmpty(signature)) { - return Result.failed(StatusCode.USER_SENSITIVE_INFO); - } - user.setSignature(userInfoUpdateDto.getSignature()); - } - if (!StringTools.isEmpty(userInfoUpdateDto.getBirthDay())) { - user.setBirthday(DateUtil.parse(userInfoUpdateDto.getBirthDay(), - DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); - } - if (null != userInfoUpdateDto.getSex()) { - user.setSex(userInfoUpdateDto.getSex()); - } - - user.setModifyTime(new Date()); - userInfoService.update(user); - - Integer point = 0; - // 信息是否已完善 - if (user.getBirthday() != null - && StringUtils.isNotBlank(user.getNickName()) - && !Objects.isNull(user.getSex()) - && StringUtils.isNotBlank(user.getSignature()) - ) { - point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_INFORMATION, authorization); - } - - if (StringUtils.isNotBlank(userInfoUpdateDto.getInvitationCode()) && StringUtils.isBlank(user.getInvitationUserId())) { - // 只有没有被邀请过的才会触发,再次修改无效 - userInfoService.bindInvitationCode(user, userInfoUpdateDto.getInvitationCode()); - } - - - return Result.success(point > 0 ? "更新成功,获得" + point + "积分" : "更新成功"); - } - - @ApiOperation(value = "3.上传个人头像", notes = "图片存入S3,桶为indie,目录为 user/avatar/, 缩略图大小为200X200") - @PostMapping("/avatar") - @GlobalInterceptor(checkAppUserLogin = true) - public Result uploadAvatar(@RequestHeader(value = "Authorization", required = true) String authorization, - @VerifyParam(required = true) MultipartFile file) throws IOException { - UserLoginDto userLoginDto = getUserLoginDto(authorization); - - byte[] avatar = file.getBytes(); - String fileId = userLoginDto.getUserId() + "_" + idWorker.nextId(); - String avatarName = fileId - + StringTools.getFileSuffix(file.getOriginalFilename()); - String avatarFilePath = Constants.USER_AVATAR_DIRECTORY + avatarName; - s3Service.uploadImage("indie", avatarFilePath, avatar); - - - UserInfo user = userInfoService.findById(userLoginDto.getUserId()); - user.setAvatar(avatarFilePath); - - byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_200, Constants.LENGTH_200); - 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 { - user.setThumbnail(avatarFilePath); - } - - userInfoService.update(user); - rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); - - userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_AVATAR, authorization); - return Result.success(Constants.RESOURCE_PREFIX + user.getThumbnail()); - } - - @ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息") - @GetMapping("/otherUserInfo/{userId}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result getOtherUserInfo( - @RequestHeader(value = "Authorization", required = true) String authorization, - @VerifyParam(required = true) @PathVariable String userId) { - UserInfo user = userInfoService.findById(userId); - if (null == user) { - return Result.failed(StatusCode.USER_INVALID_USER_ID); - } - - UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet()); - userRespDTO.setIpLocation(IpUtil.getIpLocation(user.getLastLoginIp())); - - UserLoginDto userLoginDto = getUserLoginDto(authorization); - //若当前登录用户与查询他人 用户 id一致,则为我的主页,不查询与他人关系 - if (userId.equals(userLoginDto.getUserId())) { - return Result.success(userRespDTO); - } - 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)}) - @GetMapping("/blackList/{pageNum}/{pageSize}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result> getBlackList( - @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - UserLoginDto userLoginDto = getUserLoginDto(authorization); - return getCollectedUserInfo(userLoginDto.getUserId(), pageNum, pageSize, CollectTypeEnum.BLACK_LIST); - } - - @ApiOperation(value = "6.查询关注人信息") - @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)}) - @GetMapping("/follows/{userId}/{pageNum}/{pageSize}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result> getFollows( - @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) String userId, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - - return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FOLLOWS); - } - - @ApiOperation(value = "7.查询粉丝信息") - @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", required = true), - @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)}) - @GetMapping("/fans/{userId}/{pageNum}/{pageSize}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result> getFans( - @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) String userId, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FANS); - } - - @ApiOperation(value = "8.意见反馈", notes = "每天最多反馈30条") - @PostMapping("/feedback") - @GlobalInterceptor(checkAppUserLogin = true, frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 30) - public Result sendFeedback(@RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "反馈类型,3个值,0:bug, 1:建议,2:其它", required = true) @VerifyParam(required = true) @RequestParam("type") Integer type, - @ApiParam(value = "反馈内容,最多300字", required = true) @VerifyParam(required = true, max = 300) @RequestParam("content") String content, - @ApiParam(value = "图片,单张图片最大5M,一次上传最多10张图片", required = false) @RequestParam("files") List files, - @ApiParam(value = "联系方式(可选),最多50字", required = false) @RequestParam("contact") @VerifyParam(max = 50) String contact) { - UserLoginDto userLoginDto = getUserLoginDto(authorization); - Feedback feedback = new Feedback(); - feedback.setFeedbackId(String.valueOf(idWorker.nextId())); - feedback.setType(type); - feedback.setUserId(userLoginDto.getUserId()); - feedback.setNickName(EmojiConverterUtil.encode(userLoginDto.getNickName())); - feedback.setContent(EmojiConverterUtil.encode(content)); - feedbackService.send(feedback, getInputStream(files)); - return Result.success(); - } - - private List getInputStream(List 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(); - try { - feedbackImage.setInputStream(multipartFile.getInputStream()); - } catch (Exception e) { - e.printStackTrace(); - } - feedbackImage.setContentType(multipartFile.getContentType()); - feedbackImage.setOriginalFilename(multipartFile.getOriginalFilename()); - feedbackImage.setSize(multipartFile.getSize()); - return feedbackImage; - } - - private Result> getCollectedUserInfo(String userId, Integer pageNum, Integer pageSize, - CollectTypeEnum collectTypeEnum) { - Pageable pageable = PageRequest.of(pageNum - 1, pageSize); - boolean isGetFan = isGetFan(collectTypeEnum); - Page userCollectInfos = isGetFan ? userCollectInfoService.findByObjectIdAndCollectType(userId, CollectTypeEnum.FOLLOWS, pageable) : userCollectInfoService.findByUserIdAndCollectType(userId, collectTypeEnum, pageable); - Function idFunction = isGetFan ? UserCollectInfo::getUserId : UserCollectInfo::getObjectId; - List objectIds = userCollectInfos.stream().map(idFunction).collect(Collectors.toList()); - if (objectIds.isEmpty()) { - return Result.success(new PageResult(0L, Collections.emptyList())); - } - List userInfos = userInfoService.orderByField(objectIds); - Set bothFollowSet = userCollectInfos.stream().filter(c -> Boolean.TRUE.equals(c.getIsMutualFans())).map(u -> isGetFan ? u.getUserId() : u.getObjectId()).collect(Collectors.toSet()); - List results = userInfos.stream().map(s -> getUserRespDTO(s, false, bothFollowSet)) - .collect(Collectors.toList()); - return Result.success(new PageResult(Long.valueOf(results.size()), results)); - } - - private boolean isGetFan(CollectTypeEnum collectTypeEnum) { - return CollectTypeEnum.FANS.equals(collectTypeEnum); - } - - private UserRespDTO getUserRespDTO(UserInfo user, boolean withCount, Set bothFollowSet) { - UserRespDTO userRespDTO = new UserRespDTO(); - BeanUtils.copyProperties(user, userRespDTO); - if (!StringTools.isEmpty(user.getBadges())) { - Set badgeSet = new HashSet<>(); - Arrays.stream(user.getBadges().split(",")).forEach(b -> { - int code = Integer.valueOf(b.substring(0, 1)); - badgeSet.add(code); - if (code == UserBadgeEnum.CONTRIBUTOR.getCode()) { - userRespDTO.setContributorRole(UserBadgeEnum.getByCode(Integer.valueOf(b.split("_")[0])).getDesc()); - } - }); - userRespDTO.setBadgeList(new ArrayList<>(badgeSet)); - } - if (null != userRespDTO.getAvatar()) { - userRespDTO.setAvatar(getAvatar(user)); - } - if (null != user.getBirthday()) { - userRespDTO.setBirthDay( - DateUtil.format(user.getBirthday(), DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); - } - if (!bothFollowSet.isEmpty() && bothFollowSet.contains(userRespDTO.getId())) { - userRespDTO.setRelation(UserRelationEnum.BOTH_FOLLOW.getStatus()); - } - if (!withCount) { - return userRespDTO; - } - /** - * 获取点赞数和评论数 - */ - Criteria criteria = Criteria.where("userId").is(userRespDTO.getId()); - Aggregation agg = Aggregation.newAggregation( - Aggregation.match(criteria),//匹配条件 - Aggregation.group().sum("thumbupCount").as("totalThumbup") - .sum("commentCount").as("totalComment") - ); - - AggregationResults results = mongoTemplate.aggregate(agg, "comment", TotalCommentVo.class); - - TotalCommentVo totalCommentVo = results.getUniqueMappedResult(); - if (null != totalCommentVo) { - userRespDTO.setThumbUpCount(totalCommentVo.getTotalThumbup()); - userRespDTO.setCommentReplyCount(totalCommentVo.getTotalComment()); - } - UserMessage userMessage = userMessageDao.findTopByUserIdOrderBySendTimeDesc(user.getId()); - userRespDTO.setHaveNewMessage(false); - if (null != userMessage) { - int read = userMessage.getHaveRead(); - userRespDTO.setHaveNewMessage(read == 0 ? true : false); - } - return userRespDTO; - } - - private String getAvatar(UserInfo user) { - if (StringTools.isEmpty(user.getThumbnail())) { - return Constants.RESOURCE_PREFIX + user.getAvatar(); - } - return Constants.RESOURCE_PREFIX + user.getThumbnail(); - } - - // 查询我的获赞 - @ApiOperation(value = "9.查询我的获赞的分页列表", notes = "游客无法获取") - @GetMapping("/myThumbupList/{page}/{size}") - public Result getMyThumbupList(@PathVariable int page, @PathVariable int size, @RequestHeader(value = "Authorization", required = true) String authorization) { - - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - Page pageList = myService.getMyThumbupList(userId, page, size); - - List list = pageList.stream().parallel().map(x -> getPublicationLike(x)).collect(Collectors.toList()); - - - return Result.success(new PageResult(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.setNickName(userInfo.getNickName()); - 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) { - - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - Page pageList = myService.getMyCommentReplyList(userId, page, size); - List list = pageList.stream().parallel().map(x -> getCommentHis(x)).collect(Collectors.toList()); - return Result.success(new PageResult(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.setNickName(userInfo.getNickName()); - commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar()); - } - - return commentHis; - } - - // 查询我收到的评论 - @ApiOperation(value = "11.感谢", notes = "贡献者列表") - @GetMapping("/thanks") - public Result> getThanks() { - return Result.success(getThankList()); - } - - @SuppressWarnings("unchecked") - private List getThankList() { - List thanks = (List) 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()); - redisTemplate.opsForValue().set(REDIS_KEY_THANKS, thanks); - } - return thanks; - } - - - @ApiOperation(value = "12 注销账号", notes = "注销账号") - @PostMapping("/logOff") - public Result logOff(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam LogoffReq logoffReq) { - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - // 得到缓存中的验证码 - String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + logoffReq.getDeviceId(); - String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey); - if (StringTools.isEmpty(redisMobileCheckCode)) { - return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); - } - if (!redisMobileCheckCode.equals(logoffReq.getMobileCheckCode())) { - return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); - } - - // 删除账号 + + private static final String REDIS_KEY_THANKS = "thanks"; + @Autowired + private S3Service s3Service; + @Autowired + private UserInfoService userInfoService; + @Autowired + private IdWorker idWorker; + @Autowired + private UserCollectInfoService userCollectInfoService; + + @Autowired + private FeedbackService feedbackService; + + @Autowired + private MyService myService; + + @Autowired + private MongoTemplate mongoTemplate; + + @Autowired + private RabbitTemplate rabbitTemplate; + + @Autowired + private SensitiveWordBs sensitiveWordBs; + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private UserMessageDao userMessageDao; + + @Autowired + private UserPointLogService userPointLogService; + + @Autowired + private UserinfoShippingAddressService userinfoShippingAddressService; + + @ApiOperation(value = "1.获取个人信息", notes = "游客无法获取个人信息") + @GetMapping("/userInfo") + @GlobalInterceptor(checkAppUserLogin = true) + public Result getUserInfo( + @RequestHeader(value = "Authorization", required = true) String authorization) { + UserLoginDto userLoginDto = getUserLoginDto(authorization); + UserInfo user = userInfoService.findById(userLoginDto.getUserId()); + UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet()); + userRespDTO.setMobile(user.getMobile()); + userRespDTO.setWxId(user.getWxId()); + userRespDTO.setAppleId(user.getAppleId()); + userRespDTO.setWxNickname(user.getWxNickname()); + userRespDTO.setAppleEmail(user.getAppleEmail()); + userRespDTO.setEnableNotice(1); + userRespDTO.setEnablePush(1); + userRespDTO.setVipStatus(user.getVipStatus()); + userRespDTO.setVipExpireTime(user.getVipExpireTime()); + userRespDTO.setEnableChat(user.getEnableChat()); + userRespDTO.setEnableComment(user.getEnableComment()); + userRespDTO.setPoint(user.getPoint()); + userRespDTO.setMyInvitationCode(user.getInvitationCode()); + userRespDTO.setIsBetaUser(user.getIsBetaUser()); + + String invitationUserId = user.getInvitationUserId(); + if (StringUtils.isNotEmpty(invitationUserId)) { + UserInfo myInvitationUser = userInfoService.findById(invitationUserId); + userRespDTO.setInvitationUserId(myInvitationUser.getId()); + userRespDTO.setInvitationCode(myInvitationUser.getInvitationCode()); + } else { + userRespDTO.setInvitationCode(null); + } + + if (null != user.getEnableNotice()) { + userRespDTO.setEnableNotice(user.getEnableNotice()); + } + if (null != user.getEnablePush()) { + userRespDTO.setEnablePush(user.getEnablePush()); + } + return Result.success(userRespDTO); + } + + @ApiOperation(value = "1.1 根据邀请码获取用户部分信息", notes = "无认证") + @GetMapping("/userInfo/invite") + public Result getUserInfoForInvite(String inviteCode) { + UserInfo userInfoByInvitationCode = userInfoService.getUserInfoByInvitationCode(inviteCode); + if (userInfoByInvitationCode != null) { + return Result.success(new UserInfoForInviteVO(userInfoByInvitationCode.getNickName(), + Constants.RESOURCE_PREFIX + userInfoByInvitationCode.getAvatar(), inviteCode)); + } else { + return Result.failed(ErrorConstants.USER_INVITE_CODE_NOT_EXIST); + } + } + + @ApiOperation(value = "2.更新个人信息", notes = "游客无法编辑个人信息") + @PutMapping("/userInfo") + @GlobalInterceptor(checkAppUserLogin = true) + public Result updateUserInfo( + @RequestHeader(value = "Authorization", required = true) String authorization, + @VerifyParam(required = true) @RequestBody UserInfoUpdateDto userInfoUpdateDto) { + UserLoginDto userLoginDto = getUserLoginDto(authorization); + UserInfo user = userInfoService.findById(userLoginDto.getUserId()); + if (StringUtils.isNotBlank(userInfoUpdateDto.getInvitationCode()) && StringUtils.isBlank( + user.getInvitationUserId())) { + // 只有没有被邀请过的才会触发,再次修改无效 + userInfoService.bindInvitationCode(user, userInfoUpdateDto.getInvitationCode()); + + return Result.success("更新成功"); + } else { + + String nickName = EmojiConverterUtil.encode(userInfoUpdateDto.getNickName()); + + String result = sensitiveWordBs.findFirst(nickName); + if (StringUtils.isNotEmpty(result)) { + return Result.failed(StatusCode.USER_SENSITIVE_INFO); + } + if (!StringTools.isEmpty(nickName) && !nickName.equals(user.getNickName())) { + long count = userInfoService.countByNickName(nickName); + if (count > 0) { + return Result.failed(StatusCode.USER_NICK_NAME_HAS_BEEN_EXIST); + } + } + + if (!StringTools.isEmpty(nickName)) { + user.setNickName(nickName); + rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); + } + if (!StringTools.isEmpty(userInfoUpdateDto.getSignature())) { + String signature = sensitiveWordBs.findFirst(userInfoUpdateDto.getSignature()); + if (StringUtils.isNotEmpty(signature)) { + return Result.failed(StatusCode.USER_SENSITIVE_INFO); + } + user.setSignature(userInfoUpdateDto.getSignature()); + } + if (!StringTools.isEmpty(userInfoUpdateDto.getBirthDay())) { + user.setBirthday(DateUtil.parse(userInfoUpdateDto.getBirthDay(), + DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); + } + if (null != userInfoUpdateDto.getSex()) { + user.setSex(userInfoUpdateDto.getSex()); + } + + user.setModifyTime(new Date()); + userInfoService.update(user); + + Integer point = 0; + // 信息是否已完善 + if (user.getBirthday() != null + && StringUtils.isNotBlank(user.getNickName()) + && !Objects.isNull(user.getSex()) + && StringUtils.isNotBlank(user.getSignature()) + ) { + point = userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_INFORMATION, + authorization); + } + return Result.success("更新成功"); + } + + } + + @ApiOperation(value = "3.上传个人头像", notes = "图片存入S3,桶为indie,目录为 user/avatar/, 缩略图大小为200X200") + @PostMapping("/avatar") + @GlobalInterceptor(checkAppUserLogin = true) + public Result uploadAvatar( + @RequestHeader(value = "Authorization", required = true) String authorization, + @VerifyParam(required = true) MultipartFile file) throws IOException { + UserLoginDto userLoginDto = getUserLoginDto(authorization); + + byte[] avatar = file.getBytes(); + String fileId = userLoginDto.getUserId() + "_" + idWorker.nextId(); + String avatarName = fileId + + StringTools.getFileSuffix(file.getOriginalFilename()); + String avatarFilePath = Constants.USER_AVATAR_DIRECTORY + avatarName; + s3Service.uploadImage("indie", avatarFilePath, avatar); + + UserInfo user = userInfoService.findById(userLoginDto.getUserId()); + user.setAvatar(avatarFilePath); + + byte[] thumbnail = ScaleFilter.createThumbnail(file.getInputStream(), Constants.LENGTH_200, + Constants.LENGTH_200); + 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 { + user.setThumbnail(avatarFilePath); + } + + userInfoService.update(user); + rabbitTemplate.convertAndSend("userInfoCommentCache", userLoginDto.getUserId()); + + userPointLogService.addByTaskNew(TaskPointIdConstants.MODIFY_AVATAR, authorization); + return Result.success(Constants.RESOURCE_PREFIX + user.getThumbnail()); + } + + @ApiOperation(value = "4.查看他人信息", notes = "游客无法查看他人信息") + @GetMapping("/otherUserInfo/{userId}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result getOtherUserInfo( + @RequestHeader(value = "Authorization", required = true) String authorization, + @VerifyParam(required = true) @PathVariable String userId) { + UserInfo user = userInfoService.findById(userId); + if (null == user) { + return Result.failed(StatusCode.USER_INVALID_USER_ID); + } + + UserRespDTO userRespDTO = getUserRespDTO(user, true, Collections.emptySet()); + userRespDTO.setIpLocation(IpUtil.getIpLocation(user.getLastLoginIp())); + + UserLoginDto userLoginDto = getUserLoginDto(authorization); + //若当前登录用户与查询他人 用户 id一致,则为我的主页,不查询与他人关系 + if (userId.equals(userLoginDto.getUserId())) { + return Result.success(userRespDTO); + } + 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)}) + @GetMapping("/blackList/{pageNum}/{pageSize}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> getBlackList( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + UserLoginDto userLoginDto = getUserLoginDto(authorization); + return getCollectedUserInfo(userLoginDto.getUserId(), pageNum, pageSize, + CollectTypeEnum.BLACK_LIST); + } + + @ApiOperation(value = "6.查询关注人信息") + @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", required = true), + @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)}) + @GetMapping("/follows/{userId}/{pageNum}/{pageSize}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> getFollows( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable @VerifyParam(required = true) String userId, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + + return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FOLLOWS); + } + + @ApiOperation(value = "7.查询粉丝信息") + @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户id", required = true), + @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)}) + @GetMapping("/fans/{userId}/{pageNum}/{pageSize}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> getFans( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable @VerifyParam(required = true) String userId, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + return getCollectedUserInfo(userId, pageNum, pageSize, CollectTypeEnum.FANS); + } + + @ApiOperation(value = "8.意见反馈", notes = "每天最多反馈30条") + @PostMapping("/feedback") + @GlobalInterceptor(checkAppUserLogin = true, frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 30) + public Result sendFeedback( + @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "反馈类型,3个值,0:bug, 1:建议,2:其它", required = true) @VerifyParam(required = true) @RequestParam("type") Integer type, + @ApiParam(value = "反馈内容,最多300字", required = true) @VerifyParam(required = true, max = 300) @RequestParam("content") String content, + @ApiParam(value = "图片,单张图片最大5M,一次上传最多10张图片", required = false) @RequestParam("files") List files, + @ApiParam(value = "联系方式(可选),最多50字", required = false) @RequestParam("contact") @VerifyParam(max = 50) String contact) { + UserLoginDto userLoginDto = getUserLoginDto(authorization); + Feedback feedback = new Feedback(); + feedback.setFeedbackId(String.valueOf(idWorker.nextId())); + feedback.setType(type); + feedback.setUserId(userLoginDto.getUserId()); + feedback.setNickName(EmojiConverterUtil.encode(userLoginDto.getNickName())); + feedback.setContent(EmojiConverterUtil.encode(content)); + feedbackService.send(feedback, getInputStream(files)); + return Result.success(); + } + + private List getInputStream(List 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(); + try { + feedbackImage.setInputStream(multipartFile.getInputStream()); + } catch (Exception e) { + e.printStackTrace(); + } + feedbackImage.setContentType(multipartFile.getContentType()); + feedbackImage.setOriginalFilename(multipartFile.getOriginalFilename()); + feedbackImage.setSize(multipartFile.getSize()); + return feedbackImage; + } + + private Result> getCollectedUserInfo(String userId, Integer pageNum, + Integer pageSize, + CollectTypeEnum collectTypeEnum) { + Pageable pageable = PageRequest.of(pageNum - 1, pageSize); + boolean isGetFan = isGetFan(collectTypeEnum); + Page userCollectInfos = + isGetFan ? userCollectInfoService.findByObjectIdAndCollectType(userId, + CollectTypeEnum.FOLLOWS, pageable) + : userCollectInfoService.findByUserIdAndCollectType(userId, collectTypeEnum, + pageable); + Function idFunction = + isGetFan ? UserCollectInfo::getUserId : UserCollectInfo::getObjectId; + List objectIds = userCollectInfos.stream().map(idFunction) + .collect(Collectors.toList()); + if (objectIds.isEmpty()) { + return Result.success(new PageResult(0L, Collections.emptyList())); + } + List userInfos = userInfoService.orderByField(objectIds); + Set bothFollowSet = userCollectInfos.stream() + .filter(c -> Boolean.TRUE.equals(c.getIsMutualFans())) + .map(u -> isGetFan ? u.getUserId() : u.getObjectId()).collect(Collectors.toSet()); + List results = userInfos.stream() + .map(s -> getUserRespDTO(s, false, bothFollowSet)) + .collect(Collectors.toList()); + return Result.success(new PageResult(Long.valueOf(results.size()), results)); + } + + private boolean isGetFan(CollectTypeEnum collectTypeEnum) { + return CollectTypeEnum.FANS.equals(collectTypeEnum); + } + + private UserRespDTO getUserRespDTO(UserInfo user, boolean withCount, + Set bothFollowSet) { + UserRespDTO userRespDTO = new UserRespDTO(); + BeanUtils.copyProperties(user, userRespDTO); + if (!StringTools.isEmpty(user.getBadges())) { + Set badgeSet = new HashSet<>(); + Arrays.stream(user.getBadges().split(",")).forEach(b -> { + int code = Integer.valueOf(b.substring(0, 1)); + badgeSet.add(code); + if (code == UserBadgeEnum.CONTRIBUTOR.getCode()) { + userRespDTO.setContributorRole( + UserBadgeEnum.getByCode(Integer.valueOf(b.split("_")[0])).getDesc()); + } + }); + userRespDTO.setBadgeList(new ArrayList<>(badgeSet)); + } + if (null != userRespDTO.getAvatar()) { + userRespDTO.setAvatar(getAvatar(user)); + } + if (null != user.getBirthday()) { + userRespDTO.setBirthDay( + DateUtil.format(user.getBirthday(), + DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern())); + } + if (!bothFollowSet.isEmpty() && bothFollowSet.contains(userRespDTO.getId())) { + userRespDTO.setRelation(UserRelationEnum.BOTH_FOLLOW.getStatus()); + } + if (!withCount) { + return userRespDTO; + } + /** + * 获取点赞数和评论数 + */ + Criteria criteria = Criteria.where("userId").is(userRespDTO.getId()); + Aggregation agg = Aggregation.newAggregation( + Aggregation.match(criteria),//匹配条件 + Aggregation.group().sum("thumbupCount").as("totalThumbup") + .sum("commentCount").as("totalComment") + ); + + AggregationResults results = mongoTemplate.aggregate(agg, "comment", + TotalCommentVo.class); + + TotalCommentVo totalCommentVo = results.getUniqueMappedResult(); + if (null != totalCommentVo) { + userRespDTO.setThumbUpCount(totalCommentVo.getTotalThumbup()); + userRespDTO.setCommentReplyCount(totalCommentVo.getTotalComment()); + } + UserMessage userMessage = userMessageDao.findTopByUserIdOrderBySendTimeDesc(user.getId()); + userRespDTO.setHaveNewMessage(false); + if (null != userMessage) { + int read = userMessage.getHaveRead(); + userRespDTO.setHaveNewMessage(read == 0 ? true : false); + } + return userRespDTO; + } + + private String getAvatar(UserInfo user) { + if (StringTools.isEmpty(user.getThumbnail())) { + return Constants.RESOURCE_PREFIX + user.getAvatar(); + } + return Constants.RESOURCE_PREFIX + user.getThumbnail(); + } + + // 查询我的获赞 + @ApiOperation(value = "9.查询我的获赞的分页列表", notes = "游客无法获取") + @GetMapping("/myThumbupList/{page}/{size}") + public Result getMyThumbupList(@PathVariable int page, @PathVariable int size, + @RequestHeader(value = "Authorization", required = true) String authorization) { + + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + Page pageList = myService.getMyThumbupList(userId, page, size); + + List list = pageList.stream().parallel().map(x -> getPublicationLike(x)) + .collect(Collectors.toList()); + + return Result.success(new PageResult(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.setNickName(userInfo.getNickName()); + 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) { + + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + Page pageList = myService.getMyCommentReplyList(userId, page, size); + List list = pageList.stream().parallel().map(x -> getCommentHis(x)) + .collect(Collectors.toList()); + return Result.success(new PageResult(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.setNickName(userInfo.getNickName()); + commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX + userInfo.getAvatar()); + } + + return commentHis; + } + + // 查询我收到的评论 + @ApiOperation(value = "11.感谢", notes = "贡献者列表") + @GetMapping("/thanks") + public Result> getThanks() { + return Result.success(getThankList()); + } + + @SuppressWarnings("unchecked") + private List getThankList() { + List thanks = (List) 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()); + redisTemplate.opsForValue().set(REDIS_KEY_THANKS, thanks); + } + return thanks; + } + + + @ApiOperation(value = "12 注销账号", notes = "注销账号") + @PostMapping("/logOff") + public Result logOff( + @RequestHeader(value = "Authorization", required = true) String authorization, + @VerifyParam LogoffReq logoffReq) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + // 得到缓存中的验证码 + String redisMobileCheckCodeKey = + Constants.REDIS_KEY_MOBILE_CHECK_CODE + logoffReq.getDeviceId(); + String redisMobileCheckCode = (String) redisTemplate.opsForValue() + .get(redisMobileCheckCodeKey); + if (StringTools.isEmpty(redisMobileCheckCode)) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); + } + if (!redisMobileCheckCode.equals(logoffReq.getMobileCheckCode())) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); + } + + // 删除账号 // UserInfo userInfo = userInfoService.findById(userId); // userInfo.setMobile("已注销"); // userInfo.setAvatar(Constants.DEFAULT_USER_AVATAR); @@ -536,264 +574,288 @@ public class MyController extends BaseController { // userInfo.setAppleEmail(""); // userInfo.setWxNickname(""); // userInfoService.update(userInfo); - userInfoService.deleteById(userId); - return Result.success(); - } - - - @ApiOperation(value = "13 绑定手机号", notes = "绑定手机号") - @PostMapping("/bindMobile") - public Result bindMobile(@RequestHeader(value = "Authorization", required = true) String authorization, @VerifyParam LoginReq loginReq) { - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - // 得到缓存中的验证码 - String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId(); - String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey); - if (StringTools.isEmpty(redisMobileCheckCode)) { - return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); - } - if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) { - return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); - } - - UserInfo userInfo1 = userInfoService.findByMobile(loginReq.getMobile()); - UserInfo userInfo2 = userInfoService.findById(userId); - if (null != userInfo1) { - // 如果绑定的手机号已存在 + userInfoService.deleteById(userId); + return Result.success(); + } + + + @ApiOperation(value = "13 绑定手机号", notes = "绑定手机号") + @PostMapping("/bindMobile") + public Result bindMobile( + @RequestHeader(value = "Authorization", required = true) String authorization, + @VerifyParam LoginReq loginReq) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + // 得到缓存中的验证码 + String redisMobileCheckCodeKey = + Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId(); + String redisMobileCheckCode = (String) redisTemplate.opsForValue() + .get(redisMobileCheckCodeKey); + if (StringTools.isEmpty(redisMobileCheckCode)) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); + } + if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) { + return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); + } + + UserInfo userInfo1 = userInfoService.findByMobile(loginReq.getMobile()); + UserInfo userInfo2 = userInfoService.findById(userId); + if (null != userInfo1) { + // 如果绑定的手机号已存在 // userInfo1.setMobile(loginReq.getMobile()); - userInfo1.setAppleId(userInfo2.getAppleId()); - userInfo1.setAppleEmail(userInfo2.getAppleEmail()); - userInfoService.update(userInfo1); - String token = userInfoService.loginOrRegister(userInfo1); - userInfoService.deleteById(userId); - return Result.success(token); - - } - userInfo2.setMobile(loginReq.getMobile()); - userInfoService.update(userInfo2); - String token = userInfoService.loginOrRegister(userInfo2); - return Result.success(token); - } - - @ApiOperation(value = "14.1 启用/停用 消息, 0为停用,1为启用", notes = "启用/停用 消息, 0为停用,1为启用") - @PutMapping("/enableNotice/{flag}") - public Result updateEnableNotice(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) { - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - UserInfo userInfo = userInfoService.findById(userId); - userInfo.setEnableNotice(flag); - userInfoService.update(userInfo); - return Result.success(); - } - - @ApiOperation(value = "14.2 启用/停用 推送, 0为停用,1为启用", notes = "启用/停用 推送, 0为停用,1为启用") - @PutMapping("/enablePush/{flag}") - public Result updateEnablePush(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) { - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - UserInfo userInfo = userInfoService.findById(userId); - userInfo.setEnablePush(flag); - userInfoService.update(userInfo); - return Result.success(); - } - - @ApiOperation(value = "14.3 启用/停用 私信, 0为停用,1为启用", notes = "启用/停用 私信, 0为停用,1为启用") - @PutMapping("/enableChat/{flag}") - public Result updateEnableChat(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) { - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - UserInfo userInfo = userInfoService.findById(userId); - userInfo.setEnableChat(flag); - userInfoService.update(userInfo); - return Result.success(); - } - - @ApiOperation(value = "14.4 是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论", notes = "是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论") - @PutMapping("/enableComment/{flag}") - public Result updateEnableComment(@RequestHeader(value = "Authorization", required = true) String authorization, @PathVariable int flag) { - //验证是否登录,并且拿到ID - UserLoginDto userLoginDto = getUserLoginDto(authorization); - if (null == userLoginDto) { - return Result.unauthorized(null); - } - String userId = userLoginDto.getUserId(); - UserInfo userInfo = userInfoService.findById(userId); - if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.ACTIVE.getCode()) || Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { - userInfo.setEnableComment(flag); - userInfoService.update(userInfo); - return Result.success(); - } else { - return Result.failed("会员专享,非会员不允许修改"); - } - } - - 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]); - } - - @ApiOperation(value = "15.1 提交实名认证") - @PostMapping("/approve/real/name") - public Result 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 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 realNameCheck(@RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable String id) { - userInfoService.unBindRealName(authorization, id); - return Result.success(); - } - - @ApiOperation(value = "15.4 获取实名认证详情-废弃") - @GetMapping("/get/real/name/{id}") - public Result getUserRealName( - @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "实名认证的id", required = true) @PathVariable String id) { - return Result.success(userInfoService.getUserRealName(id)); - } - - @ApiOperation(value = "15.5 查询实名认证列表-废弃") - @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), - @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)}) - @GetMapping("/real/name/{pageNum}/{pageSize}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result> getUserRealNameList( - @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - - return Result.success(userInfoService.getUserRealNameList()); - } - - /** - * 获取用户实名认证信息 - * - * @param userId 用户id - * @return 实名认证信息 - */ - @GetMapping("/info/real/name/{userId}") - public Boolean getRealNameInfo(@PathVariable String userId) { - return userInfoService.getRealNameInfo(userId); - } - - @ApiOperation(value = "16.1 用户绑定银行卡号") - @PostMapping("/add/bank") - @GlobalInterceptor(checkAppUserLogin = true) - public Result addUserBank(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "添加用户银行卡绑定对象", required = true) @Validated @RequestBody UserBankAddDto userBankAddDto - ) { - - userInfoService.addUserBank(authorization, userBankAddDto); - return Result.success(); - } - - @ApiOperation(value = "16.2 用户解绑银行卡") - @PostMapping("/del/bank/{id}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result delUserBank(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "用户绑定银行卡id", required = true) @PathVariable String id) { - userInfoService.untieCard(authorization, id); - return Result.success(); - } - - @ApiOperation(value = "16.3 查看用户已绑定的银行卡号") - @GetMapping("/bank/info") - @GlobalInterceptor(checkAppUserLogin = true) - public Result getUserBankInfo(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) { - return Result.success(userInfoService.getUserBank(authorization)); - } - - @ApiOperation(value = "17.1 发出提现申请") - @PostMapping("/approve/withdraw") - @GlobalInterceptor(checkAppUserLogin = true) - public Result approveWithdraw(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "金额", required = true) BigDecimal amount) { - userInfoService.approveWithdraw(authorization, amount); - return Result.success(); - } - - @ApiOperation(value = "17.2 查询提现记录") - @GetMapping("/withdraw/{pageNum}/{pageSize}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result> pageResultResult( - @RequestHeader(value = "Authorization", required = true) String authorization, - @PathVariable @VerifyParam(required = true) Integer pageNum, - @PathVariable @VerifyParam(required = true) Integer pageSize) { - - return Result.success(userInfoService.withdrawPageResult(authorization, pageNum, pageSize)); - } - - @ApiOperation(value = "18 用户生成邀请码") - @PostMapping("/invitation/code") - @GlobalInterceptor(checkAppUserLogin = true) - public Result createInvitationCode(@ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) { - return Result.success(userInfoService.createInvitationCode(authorization)); - } - - @ApiOperation(value = "19.1 获取用户收货地址列表") - @GetMapping("/address/list") - @GlobalInterceptor(checkAppUserLogin = true) - public Result> getUserinfoShippingAddressList( - @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) { - return Result.success(userinfoShippingAddressService.getUserinfoShippingAddressList()); - } - - @ApiOperation(value = "19.2 添加用户收货地址") - @PostMapping("/address/add") - @GlobalInterceptor(checkAppUserLogin = true) - public Result addUserinfoShippingAddress( - @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "添加用户收货地址对象", required = true) @Validated @RequestBody UserinfoShippingAddressAddDTO userinfoShippingAddressAddDTO) { - userinfoShippingAddressService.add(userinfoShippingAddressAddDTO); - return Result.success(); - } - - @ApiOperation(value = "19.3 删除用户收货地址") - @PostMapping("/address/del/{id}") - @GlobalInterceptor(checkAppUserLogin = true) - public Result delUserinfoShippingAddress( - @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "用户收货地址id", required = true) @PathVariable String id) { - userinfoShippingAddressService.delete(id); - return Result.success(); - } - - @ApiOperation(value = "19.4 修改用户收货地址") - @PostMapping("/address/update") - @GlobalInterceptor(checkAppUserLogin = true) - public Result updateUserinfoShippingAddress( - @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, - @ApiParam(value = "修改用户收货地址对象", required = true) @Validated @RequestBody UserinfoShippingAddressUpdateDTO userinfoShippingAddressUpdateDTO) { - userinfoShippingAddressService.update(userinfoShippingAddressUpdateDTO); - return Result.success(); - } + userInfo1.setAppleId(userInfo2.getAppleId()); + userInfo1.setAppleEmail(userInfo2.getAppleEmail()); + userInfoService.update(userInfo1); + String token = userInfoService.loginOrRegister(userInfo1); + userInfoService.deleteById(userId); + return Result.success(token); + + } + userInfo2.setMobile(loginReq.getMobile()); + userInfoService.update(userInfo2); + String token = userInfoService.loginOrRegister(userInfo2); + return Result.success(token); + } + + @ApiOperation(value = "14.1 启用/停用 消息, 0为停用,1为启用", notes = "启用/停用 消息, 0为停用,1为启用") + @PutMapping("/enableNotice/{flag}") + public Result updateEnableNotice( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable int flag) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setEnableNotice(flag); + userInfoService.update(userInfo); + return Result.success(); + } + + @ApiOperation(value = "14.2 启用/停用 推送, 0为停用,1为启用", notes = "启用/停用 推送, 0为停用,1为启用") + @PutMapping("/enablePush/{flag}") + public Result updateEnablePush( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable int flag) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setEnablePush(flag); + userInfoService.update(userInfo); + return Result.success(); + } + + @ApiOperation(value = "14.3 启用/停用 私信, 0为停用,1为启用", notes = "启用/停用 私信, 0为停用,1为启用") + @PutMapping("/enableChat/{flag}") + public Result updateEnableChat( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable int flag) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + userInfo.setEnableChat(flag); + userInfoService.update(userInfo); + return Result.success(); + } + + @ApiOperation(value = "14.4 是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论", notes = "是否关闭评论,0为不关闭评论,1为启用关闭评论,默认不关闭评论") + @PutMapping("/enableComment/{flag}") + public Result updateEnableComment( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable int flag) { + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); + UserInfo userInfo = userInfoService.findById(userId); + if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.ACTIVE.getCode()) + || Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) { + userInfo.setEnableComment(flag); + userInfoService.update(userInfo); + return Result.success(); + } else { + return Result.failed("会员专享,非会员不允许修改"); + } + } + + 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]); + } + + @ApiOperation(value = "15.1 提交实名认证") + @PostMapping("/approve/real/name") + public Result 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 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 realNameCheck( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable String id) { + userInfoService.unBindRealName(authorization, id); + return Result.success(); + } + + @ApiOperation(value = "15.4 获取实名认证详情-废弃") + @GetMapping("/get/real/name/{id}") + public Result getUserRealName( + @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "实名认证的id", required = true) @PathVariable String id) { + return Result.success(userInfoService.getUserRealName(id)); + } + + @ApiOperation(value = "15.5 查询实名认证列表-废弃") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "分页: 页码,以1开始", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页: 每页数量", required = true)}) + @GetMapping("/real/name/{pageNum}/{pageSize}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> getUserRealNameList( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + + return Result.success(userInfoService.getUserRealNameList()); + } + + /** + * 获取用户实名认证信息 + * + * @param userId 用户id + * @return 实名认证信息 + */ + @GetMapping("/info/real/name/{userId}") + public Boolean getRealNameInfo(@PathVariable String userId) { + return userInfoService.getRealNameInfo(userId); + } + + @ApiOperation(value = "16.1 用户绑定银行卡号") + @PostMapping("/add/bank") + @GlobalInterceptor(checkAppUserLogin = true) + public Result addUserBank( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "添加用户银行卡绑定对象", required = true) @Validated @RequestBody UserBankAddDto userBankAddDto + ) { + + userInfoService.addUserBank(authorization, userBankAddDto); + return Result.success(); + } + + @ApiOperation(value = "16.2 用户解绑银行卡") + @PostMapping("/del/bank/{id}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result delUserBank( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "用户绑定银行卡id", required = true) @PathVariable String id) { + userInfoService.untieCard(authorization, id); + return Result.success(); + } + + @ApiOperation(value = "16.3 查看用户已绑定的银行卡号") + @GetMapping("/bank/info") + @GlobalInterceptor(checkAppUserLogin = true) + public Result getUserBankInfo( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) { + return Result.success(userInfoService.getUserBank(authorization)); + } + + @ApiOperation(value = "17.1 发出提现申请") + @PostMapping("/approve/withdraw") + @GlobalInterceptor(checkAppUserLogin = true) + public Result approveWithdraw( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "金额", required = true) BigDecimal amount) { + userInfoService.approveWithdraw(authorization, amount); + return Result.success(); + } + + @ApiOperation(value = "17.2 查询提现记录") + @GetMapping("/withdraw/{pageNum}/{pageSize}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> pageResultResult( + @RequestHeader(value = "Authorization", required = true) String authorization, + @PathVariable @VerifyParam(required = true) Integer pageNum, + @PathVariable @VerifyParam(required = true) Integer pageSize) { + + return Result.success(userInfoService.withdrawPageResult(authorization, pageNum, pageSize)); + } + + @ApiOperation(value = "18 用户生成邀请码") + @PostMapping("/invitation/code") + @GlobalInterceptor(checkAppUserLogin = true) + public Result createInvitationCode( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) { + return Result.success(userInfoService.createInvitationCode(authorization)); + } + + @ApiOperation(value = "19.1 获取用户收货地址列表") + @GetMapping("/address/list") + @GlobalInterceptor(checkAppUserLogin = true) + public Result> getUserinfoShippingAddressList( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization) { + return Result.success(userinfoShippingAddressService.getUserinfoShippingAddressList()); + } + + @ApiOperation(value = "19.2 添加用户收货地址") + @PostMapping("/address/add") + @GlobalInterceptor(checkAppUserLogin = true) + public Result addUserinfoShippingAddress( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "添加用户收货地址对象", required = true) @Validated @RequestBody UserinfoShippingAddressAddDTO userinfoShippingAddressAddDTO) { + userinfoShippingAddressService.add(userinfoShippingAddressAddDTO); + return Result.success(); + } + + @ApiOperation(value = "19.3 删除用户收货地址") + @PostMapping("/address/del/{id}") + @GlobalInterceptor(checkAppUserLogin = true) + public Result delUserinfoShippingAddress( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "用户收货地址id", required = true) @PathVariable String id) { + userinfoShippingAddressService.delete(id); + return Result.success(); + } + + @ApiOperation(value = "19.4 修改用户收货地址") + @PostMapping("/address/update") + @GlobalInterceptor(checkAppUserLogin = true) + public Result updateUserinfoShippingAddress( + @ApiParam(value = "用户token", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, + @ApiParam(value = "修改用户收货地址对象", required = true) @Validated @RequestBody UserinfoShippingAddressUpdateDTO userinfoShippingAddressUpdateDTO) { + userinfoShippingAddressService.update(userinfoShippingAddressUpdateDTO); + return Result.success(); + } }