Search in sources :

Example 6 with UserInfo

use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.

the class NewsCommentServiceImpl method getNewsCommentList.

@Override
public PageVO<NewsCommentBO> getNewsCommentList(Integer newsId, Pageable pageable, Integer userId) {
    Page<NewsCommentBO> allByNewsIdAndIsDel = newsCommentRepository.findAllByNewsIdAndIsDel(newsId, false, pageable);
    List<NewsCommentBO> commentList = allByNewsIdAndIsDel.getContent();
    commentList.forEach(li -> {
        // 评论中评论的回复只显示未删除的点赞最多的三条
        if (li.getReplies().size() > 3) {
            li.setReplies(li.getReplies().stream().filter(de -> !de.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()).subList(0, 3));
            li.setIsNeedOpen(true);
        } else {
            li.setIsNeedOpen(false);
        }
        // 评论字段赋值
        UserInfo userInfo = userInfoService.selectById(li.getUserId());
        li.setUserName(userInfo.getUsername());
        li.setAvatar(userInfo.getPicPath());
        if (li.getZan() > 0 && userId != null) {
            CommentZanBO zanInfo = commentZanRepository.findOne(li.getId());
            if (zanInfo != null && zanInfo.getZanUserList().parallelStream().anyMatch(zan -> zan.equals(userId))) {
                li.setIsPraised(true);
            } else {
                li.setIsPraised(false);
            }
        } else {
            li.setIsPraised(false);
        }
        // 设置能否删除该评论字段
        if (li.getUserId().equals(userId)) {
            li.setIsCanDel(true);
        } else {
            li.setIsCanDel(false);
        }
        // 回复字段赋值
        li.getReplies().forEach(re -> handleReplies(re, userId));
    });
    return new PageVO(allByNewsIdAndIsDel, pageable.getPageNumber(), commentList);
}
Also used : java.util(java.util) CommentZanRepository(com.ch999.haha.admin.repository.redis.CommentZanRepository) PageVO(com.ch999.haha.admin.vo.PageVO) Resource(javax.annotation.Resource) NewsCommentService(com.ch999.haha.admin.service.NewsCommentService) StopWatch(org.springframework.util.StopWatch) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) UserInfoService(com.ch999.haha.admin.service.UserInfoService) CommentReplyVO(com.ch999.haha.admin.vo.CommentReplyVO) CollectionUtils(org.apache.commons.collections.CollectionUtils) PageableVo(com.ch999.haha.common.PageableVo) Service(org.springframework.stereotype.Service) UserInfo(com.ch999.haha.admin.entity.UserInfo) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO) NewsCommentRepository(com.ch999.haha.admin.repository.mongo.NewsCommentRepository) Pageable(org.springframework.data.domain.Pageable) PageVO(com.ch999.haha.admin.vo.PageVO) UserInfo(com.ch999.haha.admin.entity.UserInfo) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO)

Example 7 with UserInfo

use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.

the class UserInfoApi method updateAvatar.

/**
 * 修改用户信息
 *
 * @param type             要修改的类型有{avatar,name,mobile,description,pwd}
 * @param userInfoUpdateVO
 * @return
 */
@PostMapping("/updateUserInfo/{type}/v1")
public Result<String> updateAvatar(@PathVariable("type") String type, UserInfoUpdateVO userInfoUpdateVO, HttpServletResponse httpResponse) {
    // 设置ajax跨域可访问
    httpResponse.addHeader("Access-Control-Allow-Origin", "*");
    UserInfoBO loginUser = userComponent.getLoginUser();
    if (loginUser.getId() == null) {
        return Result.error("unLogin", "请登录后再进行操作");
    }
    UserInfo userInfo = new UserInfo(loginUser.getId());
    userInfo.setPicPath(userInfoBORepository.findOne(loginUser.getId()).getUserInfo().getPicPath());
    switch(type) {
        case "avatar":
            if (userInfoUpdateVO.getFile() == null) {
                return Result.error("null", "请选择图片");
            }
            if (userComponent.updateUserAvatar(loginUser.getId(), userInfoUpdateVO.getFile())) {
                return Result.success();
            }
            return Result.error("error", "头像更改失败");
        case "name":
            if (StringUtils.isBlank(userInfoUpdateVO.getName())) {
                return Result.error("null", "用户名不能为空");
            } else if (!userInfoUpdateVO.getName().equals(loginUser.getUserInfo().getUsername()) && !userComponent.checkCanUse(type, userInfoUpdateVO.getName())) {
                return Result.error("null", "昵称修改失败该昵称已被占用");
            }
            userInfo.setUsername(userInfoUpdateVO.getName());
            break;
        case "description":
            if (StringUtils.isBlank(userInfoUpdateVO.getDescription())) {
                return Result.error("null", "个性签名不能为空");
            }
            userInfo.setAutograph(userInfoUpdateVO.getDescription());
            break;
        case "mobile":
            if (StringUtils.isBlank(userInfoUpdateVO.getMobile())) {
                return Result.error("null", "请输入要修改的手机号码");
            } else if (!userInfoUpdateVO.getMobile().matches(Phone.CK)) {
                return Result.error("error", "请输入正确的的电话号码");
            } else if (!userInfoUpdateVO.getMobile().equals(loginUser.getUserInfo().getMobile()) && !userComponent.checkCanUse(type, userInfoUpdateVO.getMobile())) {
                return Result.error("error", "手机号修改失败该号码已被占用");
            }
            userInfo.setMobile(userInfoUpdateVO.getMobile());
            break;
        case "pwd":
            if (StringUtils.isBlank(userInfoUpdateVO.getOldPwd())) {
                return Result.error("null", "请输入原密码");
            } else if (!userInfoService.selectById(loginUser.getId()).getPwd().equals(userInfoUpdateVO.getOldPwd())) {
                return Result.error("error", "原密码输入错误,密码修改失败");
            } else if (StringUtils.isBlank(userInfoUpdateVO.getNewPwd1()) || StringUtils.isBlank(userInfoUpdateVO.getNewPwd2()) || !userInfoUpdateVO.getNewPwd2().equals(userInfoUpdateVO.getNewPwd1())) {
                return Result.error("error", "新密码未输入或两次密码输入不一致,密码修改失败");
            }
            userInfo.setPwd(userInfoUpdateVO.getNewPwd1());
            break;
        default:
            return Result.error("error", "不支持该类型的修改");
    }
    // 修改数据库
    userInfoService.updateById(userInfo);
    UserInfo userInfo1 = userInfoService.selectById(loginUser.getId());
    // 修改缓存
    UserInfoBO one = userInfoBORepository.findOne(loginUser.getId());
    if (one != null) {
        one.setUserInfo(userInfo1);
    } else {
        one = new UserInfoBO(loginUser.getId(), userInfo1);
    }
    userInfoBORepository.save(one);
    return Result.success();
}
Also used : UserInfo(com.ch999.haha.admin.entity.UserInfo) UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 8 with UserInfo

use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.

the class UserComponent method userRegister.

/**
 * 用户注册
 * @param registerVO
 * @return
 */
public Integer userRegister(RegisterVO registerVO) {
    if (!registerVO.getPwd1().equals(registerVO.getPwd2())) {
        return null;
    }
    UserInfo userInfo = new UserInfo();
    userInfo.setUsername(registerVO.getUserName());
    userInfo.setMobile(registerVO.getMobile());
    userInfo.setPwd(registerVO.getPwd1());
    userInfoService.insert(userInfo);
    // 注册的时候就给用户一个初始信用积分
    UserInfoBO userInfoBO = new UserInfoBO(userInfo.getId(), userInfo);
    userInfoBORepository.save(userInfoBO);
    return userInfo.getId();
}
Also used : UserInfo(com.ch999.haha.admin.entity.UserInfo) UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 9 with UserInfo

use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.

the class UserComponent method getLoginUser.

/**
 * 获取当前用户信息
 *
 * @return
 */
public UserInfoBO getLoginUser() {
    Integer userId = getUserId();
    if (userId == -1) {
        return new UserInfoBO();
    } else {
        UserInfoBO one = userInfoBORepository.findOne(userId);
        if (one == null) {
            UserInfo userInfo = userInfoService.selectById(userId);
            UserInfoBO userInfoBO = new UserInfoBO(userId, userInfo);
            userInfoBORepository.save(userInfoBO);
            return userInfo != null ? userInfoBO : new UserInfoBO();
        } else {
            return one;
        }
    }
}
Also used : UserInfo(com.ch999.haha.admin.entity.UserInfo) UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Example 10 with UserInfo

use of com.ch999.haha.admin.entity.UserInfo in project haha by hahafreeasair666.

the class NewsCommentServiceImpl method getCommentReplies.

@Override
public CommentReplyVO getCommentReplies(String commentId, PageableVo pageable, Integer userId) {
    StopWatch stopWatch = new StopWatch("mongo");
    stopWatch.start("查询");
    CommentReplyVO commentReplyVO = new CommentReplyVO(newsCommentRepository.findOne(commentId), pageable);
    stopWatch.stop();
    if (commentReplyVO.getNewsCommentAndReply() != null) {
        stopWatch.start("评论处理");
        UserInfo userInfo = userInfoService.selectById(commentReplyVO.getNewsCommentAndReply().getUserId());
        commentReplyVO.getNewsCommentAndReply().setAvatar(userInfo.getPicPath());
        commentReplyVO.getNewsCommentAndReply().setUserName(userInfo.getUsername());
        if (commentReplyVO.getNewsCommentAndReply().getZan() > 0 && userId != null) {
            CommentZanBO one = commentZanRepository.findOne(commentReplyVO.getNewsCommentAndReply().getId());
            if (one != null) {
                commentReplyVO.getNewsCommentAndReply().setIsPraised(one.getZanUserList().parallelStream().anyMatch(li -> li.equals(userId)));
            } else {
                commentReplyVO.getNewsCommentAndReply().setIsPraised(false);
            }
        } else {
            commentReplyVO.getNewsCommentAndReply().setIsPraised(false);
        }
        // 设置能否删除该评论字段
        if (commentReplyVO.getNewsCommentAndReply().getUserId().equals(userId)) {
            commentReplyVO.getNewsCommentAndReply().setIsCanDel(true);
        } else {
            commentReplyVO.getNewsCommentAndReply().setIsCanDel(false);
        }
        stopWatch.stop();
        if (CollectionUtils.isNotEmpty(commentReplyVO.getNewsCommentAndReply().getReplies())) {
            stopWatch.start("回复分页处理");
            commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().stream().filter(li -> !li.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()));
            Integer replySize = commentReplyVO.getNewsCommentAndReply().getReplies().size();
            if (replySize >= pageable.getPage() * pageable.getSize() - pageable.getSize()) {
                if (pageable.getPage() == 1) {
                    commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().subList(0, pageable.getSize() > replySize ? replySize : pageable.getSize()));
                } else {
                    commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().subList(pageable.getPage() * pageable.getSize() - pageable.getSize(), replySize > pageable.getPage() * pageable.getSize() ? pageable.getPage() * pageable.getSize() : replySize));
                }
            } else {
                commentReplyVO.getNewsCommentAndReply().setReplies(new ArrayList<>());
            }
            stopWatch.stop();
            stopWatch.start("数据库查询操作");
            commentReplyVO.getNewsCommentAndReply().getReplies().forEach(li -> handleReplies(li, userId));
            stopWatch.stop();
        }
    }
    System.out.println(stopWatch.prettyPrint());
    return commentReplyVO;
}
Also used : java.util(java.util) CommentZanRepository(com.ch999.haha.admin.repository.redis.CommentZanRepository) PageVO(com.ch999.haha.admin.vo.PageVO) Resource(javax.annotation.Resource) NewsCommentService(com.ch999.haha.admin.service.NewsCommentService) StopWatch(org.springframework.util.StopWatch) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) UserInfoService(com.ch999.haha.admin.service.UserInfoService) CommentReplyVO(com.ch999.haha.admin.vo.CommentReplyVO) CollectionUtils(org.apache.commons.collections.CollectionUtils) PageableVo(com.ch999.haha.common.PageableVo) Service(org.springframework.stereotype.Service) UserInfo(com.ch999.haha.admin.entity.UserInfo) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO) NewsCommentRepository(com.ch999.haha.admin.repository.mongo.NewsCommentRepository) Pageable(org.springframework.data.domain.Pageable) CommentReplyVO(com.ch999.haha.admin.vo.CommentReplyVO) UserInfo(com.ch999.haha.admin.entity.UserInfo) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO) StopWatch(org.springframework.util.StopWatch)

Aggregations

UserInfo (com.ch999.haha.admin.entity.UserInfo)9 UserInfoBO (com.ch999.haha.admin.document.redis.UserInfoBO)4 NewsCommentBO (com.ch999.haha.admin.document.mongo.NewsCommentBO)3 CommentZanBO (com.ch999.haha.admin.document.redis.CommentZanBO)3 NewsCommentRepository (com.ch999.haha.admin.repository.mongo.NewsCommentRepository)3 CommentZanRepository (com.ch999.haha.admin.repository.redis.CommentZanRepository)3 NewsCommentService (com.ch999.haha.admin.service.NewsCommentService)3 UserInfoService (com.ch999.haha.admin.service.UserInfoService)3 CommentReplyVO (com.ch999.haha.admin.vo.CommentReplyVO)3 PageVO (com.ch999.haha.admin.vo.PageVO)3 PageableVo (com.ch999.haha.common.PageableVo)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Resource (javax.annotation.Resource)3 CollectionUtils (org.apache.commons.collections.CollectionUtils)3 Page (org.springframework.data.domain.Page)3 Pageable (org.springframework.data.domain.Pageable)3 Service (org.springframework.stereotype.Service)3 StopWatch (org.springframework.util.StopWatch)3 EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)1