Search in sources :

Example 1 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 2 with UserInfo

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

the class NewsCommentServiceImpl method handleReplies.

private void handleReplies(NewsCommentBO.Reply re, Integer userId) {
    UserInfo replyUserInfo = userInfoService.selectById(re.getReplyUserId());
    UserInfo toUserInfo = userInfoService.selectById(re.getToUserId());
    re.setReplyUserAvatar(replyUserInfo.getPicPath());
    re.setReplyUserName(replyUserInfo.getUsername());
    re.setToUserName(toUserInfo.getUsername());
    if (re.getZan() > 0 && userId != null) {
        CommentZanBO toZanInfo = commentZanRepository.findOne(re.getReplyId());
        if (toZanInfo != null) {
            re.setIsPraised(toZanInfo.getZanUserList().parallelStream().anyMatch(z -> z.equals(userId)));
        } else {
            re.setIsPraised(false);
        }
    } else {
        re.setIsPraised(false);
    }
    // 设置能否删除该评论字段
    if (re.getReplyUserId().equals(userId)) {
        re.setIsCanDel(true);
    } else {
        re.setIsCanDel(false);
    }
}
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) UserInfo(com.ch999.haha.admin.entity.UserInfo) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO)

Example 3 with UserInfo

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

the class UserInfoServiceImpl method getMyCenterInfo.

@Override
public MyCenterVO getMyCenterInfo(UserInfoBO userInfo) {
    MyCenterVO userCenterVO = new MyCenterVO();
    UserCenterInfoCountVO userInfoCount = getUserInfoCount(userInfo.getUserInfo().getId());
    userCenterVO.setUserName(userInfo.getUserInfo().getUsername());
    userCenterVO.setFans(userInfoCount.getFans());
    userCenterVO.setFollows(userInfoCount.getFollow());
    userCenterVO.setMyCollection(userInfoCount.getCollections());
    userCenterVO.setMyAdoption(userInfoCount.getMyAdoption());
    userCenterVO.setAdoptionRequest(userInfoCount.getAdoptionRequest());
    userCenterVO.setUserId(userInfoCount.getUserId());
    userCenterVO.setZan(userInfoCount.getZan());
    userCenterVO.setDescription(userInfo.getUserInfo().getAutograph());
    userCenterVO.setMyCredit(userInfo.getCreditInfo().get("creditNum") != null ? (int) userInfo.getCreditInfo().get("creditNum") : 0);
    userCenterVO.setAvatar(userInfo.getUserInfo().getPicPath());
    userCenterVO.setMyRelease(userInfoCount.getReleases());
    userCenterVO.setAdoptionPerson(userInfoCount.getAdoptionPerson());
    return userCenterVO;
}
Also used : MyCenterVO(com.ch999.haha.admin.vo.MyCenterVO) UserCenterInfoCountVO(com.ch999.haha.admin.vo.mappervo.UserCenterInfoCountVO)

Example 4 with UserInfo

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

the class UserInfoServiceImpl method loginByMobileOrUserName.

@Override
public Integer loginByMobileOrUserName(String type, String loginInfo, String pwd) {
    Wrapper<UserInfo> wrapper = new EntityWrapper<>();
    wrapper.eq(type, loginInfo);
    UserInfo userInfo = this.selectOne(wrapper);
    if (userInfo == null || !pwd.equals(userInfo.getPwd())) {
        return null;
    } else {
        return userInfo.getId();
    }
}
Also used : EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) UserInfo(com.ch999.haha.admin.entity.UserInfo)

Example 5 with UserInfo

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

the class UserComponent method updateUserAvatar.

public Boolean updateUserAvatar(Integer userId, MultipartFile file) {
    Imgs imgs = imgService.uploadImg(file);
    if (imgs == null) {
        return false;
    } else {
        UserInfo userInfo = new UserInfo(userId);
        userInfo.setPicPath(imgs.getImgUrl());
        userInfoService.updateById(userInfo);
        UserInfo userInfo1 = userInfoService.selectById(userId);
        UserInfoBO one = userInfoBORepository.findOne(userId);
        one.setUserInfo(userInfo1);
        userInfoBORepository.save(one);
        return true;
    }
}
Also used : Imgs(com.ch999.haha.admin.entity.Imgs) UserInfo(com.ch999.haha.admin.entity.UserInfo) UserInfoBO(com.ch999.haha.admin.document.redis.UserInfoBO)

Aggregations

UserInfo (com.ch999.haha.admin.entity.UserInfo)10 UserInfoBO (com.ch999.haha.admin.document.redis.UserInfoBO)5 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