Search in sources :

Example 1 with ECommentSource

use of com.moxi.mougblog.base.enums.ECommentSource in project mogu_blog_v2 by moxi624.

the class CommentServiceImpl method getPageList.

@Override
public IPage<Comment> getPageList(CommentVO commentVO) {
    QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
    if (StringUtils.isNotEmpty(commentVO.getKeyword()) && !StringUtils.isEmpty(commentVO.getKeyword().trim())) {
        queryWrapper.like(SQLConf.CONTENT, commentVO.getKeyword().trim());
    }
    if (commentVO.getType() != null) {
        queryWrapper.eq(SQLConf.TYPE, commentVO.getType());
    }
    if (StringUtils.isNotEmpty(commentVO.getSource()) && !SysConf.ALL.equals(commentVO.getSource())) {
        queryWrapper.eq(SQLConf.SOURCE, commentVO.getSource());
    }
    if (StringUtils.isNotEmpty(commentVO.getUserName())) {
        String userName = commentVO.getUserName();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.like(SQLConf.NICK_NAME, userName);
        userQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        List<User> list = userService.list(userQueryWrapper);
        if (list.size() > 0) {
            List<String> userUid = new ArrayList<>();
            list.forEach(item -> {
                userUid.add(item.getUid());
            });
            queryWrapper.in(SQLConf.USER_UID, userUid);
        } else {
            // 当没有查询到用户时,默认UID
            queryWrapper.in(SQLConf.USER_UID, SysConf.DEFAULT_UID);
        }
    }
    Page<Comment> page = new Page<>();
    page.setCurrent(commentVO.getCurrentPage());
    page.setSize(commentVO.getPageSize());
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
    IPage<Comment> pageList = commentService.page(page, queryWrapper);
    List<Comment> commentList = pageList.getRecords();
    Set<String> userUidSet = new HashSet<>();
    Set<String> blogUidSet = new HashSet<>();
    commentList.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            userUidSet.add(item.getUserUid());
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            userUidSet.add(item.getToUserUid());
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            blogUidSet.add(item.getBlogUid());
        }
    });
    // 获取博客
    Collection<Blog> blogList = new ArrayList<>();
    if (blogUidSet.size() > 0) {
        blogList = blogService.listByIds(blogUidSet);
    }
    Map<String, Blog> blogMap = new HashMap<>();
    blogList.forEach(item -> {
        // 评论管理并不需要查看博客内容,因此将其排除
        item.setContent("");
        blogMap.put(item.getUid(), item);
    });
    // 获取头像
    Collection<User> userCollection = new ArrayList<>();
    if (userUidSet.size() > 0) {
        userCollection = userService.listByIds(userUidSet);
    }
    final StringBuffer fileUids = new StringBuffer();
    userCollection.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getAvatar())) {
            fileUids.append(item.getAvatar() + SysConf.FILE_SEGMENTATION);
        }
    });
    String pictureList = null;
    if (fileUids != null) {
        pictureList = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    Map<String, String> pictureMap = new HashMap<>();
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    Map<String, User> userMap = new HashMap<>();
    userCollection.forEach(item -> {
        // 判断头像是否为空
        if (pictureMap.get(item.getAvatar()) != null) {
            item.setPhotoUrl(pictureMap.get(item.getAvatar()));
        }
        userMap.put(item.getUid(), item);
    });
    for (Comment item : commentList) {
        try {
            ECommentSource commentSource = ECommentSource.valueOf(item.getSource());
            item.setSourceName(commentSource.getName());
        } catch (Exception e) {
            log.error("ECommentSource 转换异常");
        }
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            item.setUser(userMap.get(item.getUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            item.setToUser(userMap.get(item.getToUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            item.setBlog(blogMap.get(item.getBlogUid()));
        }
    }
    pageList.setRecords(commentList);
    return pageList;
}
Also used : User(com.moxi.mogublog.commons.entity.User) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ECommentSource(com.moxi.mougblog.base.enums.ECommentSource) Blog(com.moxi.mogublog.commons.entity.Blog) Comment(com.moxi.mogublog.commons.entity.Comment) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DeleteException(com.moxi.mougblog.base.exception.exceptionType.DeleteException)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 Blog (com.moxi.mogublog.commons.entity.Blog)1 Comment (com.moxi.mogublog.commons.entity.Comment)1 User (com.moxi.mogublog.commons.entity.User)1 ECommentSource (com.moxi.mougblog.base.enums.ECommentSource)1 DeleteException (com.moxi.mougblog.base.exception.exceptionType.DeleteException)1