Skip to content

Commit

Permalink
Merge pull request otale#474 from zaoangod/develop
Browse files Browse the repository at this point in the history
添加文章评论统计查询功能
  • Loading branch information
hellokaton authored Oct 25, 2018
2 parents 11fcebd + 8fcabc0 commit e432013
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/tale/extension/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,19 @@ public static Page<Comment> comments(int limit) {
return comments;
}

/**
* 获取当前文章/页面的评论数量
*
* @return 当前页面的评论数量
*/
public static long commentsCount() {
Contents contents = current_article();
if (null == contents) {
return 0;
}
return siteService.getCommentCount(contents.getCid());
}

/**
* 分页
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/tale/service/CommentsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ public Page<Comment> getComments(Integer cid, int page, int limit) {
return commentsPage.map(this::apply);
}

/**
* 获取文章下的评论统计
*
* @param cid 文章ID
*/
public long getCommentCount(Integer cid) {
if (null == cid) {
return 0;
}
return select().from(Comments.class).where(Comments::getCid, cid).count();
}

/**
* 获取该评论下的追加评论
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/tale/service/SiteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ public Page<Comment> getComments(Integer cid, int page, int limit) {
return commentsService.getComments(cid, page, limit);
}

/**
* 获取文章的评论总数
*
* @param cid 文章id
*/
public long getCommentCount(Integer cid) {
return commentsService.getCommentCount(cid);
}

/**
* 清楚缓存
*
Expand Down

0 comments on commit e432013

Please sign in to comment.