Commit 3a8be1ee authored by Liang Ding's avatar Liang Ding

#12633

parent 3617d372
......@@ -360,6 +360,24 @@ public final class Option {
*/
public static final String CATEGORY_C_OAUTH = "oauth";
//// Transient ////
/**
* Key of statistic blog published article count.
*/
public static final String ID_T_STATISTIC_PUBLISHED_ARTICLE_COUNT = "statisticPublishedBlogArticleCount";
/**
* Key of statistic blog comment(published article) count.
*/
public static final String ID_T_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT = "statisticPublishedBlogCommentCount";
/**
* Gets oauth pair str from the specified oauth pairs with the specified open id.
*
* @param oauthPairs the specified oauth pairs
* @param openIdOrUserId the specified open id
* @return oauth pair str, returns {@code null} if not found
*/
public static String getOAuthPair(final Set<String> oauthPairs, final String openIdOrUserId) {
for (final String pair : oauthPairs) {
if (StringUtils.containsIgnoreCase(pair, openIdOrUserId)) {
......
......@@ -20,8 +20,14 @@ package org.b3log.solo.service;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.FilterOperator;
import org.b3log.latke.repository.PropertyFilter;
import org.b3log.latke.repository.Query;
import org.b3log.latke.service.annotation.Service;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Option;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository;
import org.json.JSONObject;
/**
......@@ -45,6 +51,18 @@ public class StatisticQueryService {
@Inject
private OptionQueryService optionQueryService;
/**
* Article repository.
*/
@Inject
private ArticleRepository articleRepository;
/**
* Comment repository.
*/
@Inject
private CommentRepository commentRepository;
/**
* Gets the online visitor count.
*
......@@ -61,7 +79,13 @@ public class StatisticQueryService {
*/
public JSONObject getStatistic() {
try {
return optionQueryService.getOptions(Option.CATEGORY_C_STATISTIC);
final JSONObject ret = optionQueryService.getOptions(Option.CATEGORY_C_STATISTIC);
final long publishedArticleCount = articleRepository.count(new Query().setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true)));
ret.put(Option.ID_T_STATISTIC_PUBLISHED_ARTICLE_COUNT, publishedArticleCount);
final long commentCount = commentRepository.count(new Query());
ret.put(Option.ID_T_STATISTIC_PUBLISHED_BLOG_COMMENT_COUNT, commentCount);
return ret;
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets statistic failed", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment