Search in sources :

Example 1 with PageableVo

use of com.ch999.haha.common.PageableVo in project haha by hahafreeasair666.

the class ApiTests method test.

@Test
public void test() {
    /*UserCenterInfoCountVO userInfoCount = userInfoService.getUserInfoCount(1);
        System.out.println(userInfoCount);*/
    /* userInfoBORepository.deleteAll();
        userBORepository.deleteAll();*/
    PageableVo pageableVo = new PageableVo();
    // pageableVo.setSize(1);
    // pageableVo.setPage(3);
    pageableVo.setSort(new Sort(Sort.Direction.DESC, "createTime"));
    newsCommentService.getNewsCommentList(5, pageableVo, null);
}
Also used : Sort(org.springframework.data.domain.Sort) PageableVo(com.ch999.haha.common.PageableVo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PageableVo

use of com.ch999.haha.common.PageableVo 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

PageableVo (com.ch999.haha.common.PageableVo)2 NewsCommentBO (com.ch999.haha.admin.document.mongo.NewsCommentBO)1 CommentZanBO (com.ch999.haha.admin.document.redis.CommentZanBO)1 UserInfo (com.ch999.haha.admin.entity.UserInfo)1 NewsCommentRepository (com.ch999.haha.admin.repository.mongo.NewsCommentRepository)1 CommentZanRepository (com.ch999.haha.admin.repository.redis.CommentZanRepository)1 NewsCommentService (com.ch999.haha.admin.service.NewsCommentService)1 UserInfoService (com.ch999.haha.admin.service.UserInfoService)1 CommentReplyVO (com.ch999.haha.admin.vo.CommentReplyVO)1 PageVO (com.ch999.haha.admin.vo.PageVO)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Page (org.springframework.data.domain.Page)1 Pageable (org.springframework.data.domain.Pageable)1 Sort (org.springframework.data.domain.Sort)1 Service (org.springframework.stereotype.Service)1