use of com.tale.dto.Comment in project tale by otale.
the class CommentsServiceImpl method getComments.
@Override
public Paginator<Comment> getComments(Integer cid, int page, int limit) {
if (null != cid) {
Take take = new Take(Comments.class);
take.eq("cid", cid).eq("parent", 0);
take.page(page, limit, "coid desc");
Paginator<Comments> cp = activeRecord.page(take);
Paginator<Comment> commentPaginator = new Paginator<>(cp.getTotal(), page, limit);
if (null != cp.getList()) {
List<Comments> parents = cp.getList();
List<Comment> comments = new ArrayList<>(parents.size());
parents.forEach(parent -> {
Comment comment = new Comment(parent);
List<Comments> children = new ArrayList<>();
getChildren(children, comment.getCoid());
comment.setChildren(children);
if (CollectionKit.isNotEmpty(children)) {
comment.setLevels(1);
}
comments.add(comment);
});
commentPaginator.setList(comments);
}
return commentPaginator;
}
return null;
}