use of com.duan.blogos.dto.blog.BlogStatisticsDTO in project BlogSystem by DuanJiaNing.
the class BlogStatisticsServiceImpl method getBlogStatistics.
@Override
public ResultBean<BlogStatisticsDTO> getBlogStatistics(int blogId) {
Blog blog = blogDao.getBlogById(blogId);
if (blog == null)
return null;
int bloggerId = blog.getBloggerId();
// 统计信息
BlogStatistics statistics = statisticsDao.getStatistics(blogId);
if (statistics == null)
return null;
// 类别
BlogCategory[] categories = null;
String sn = dbProperties.getStringFiledSplitCharacterForNumber();
int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), sn);
if (!CollectionUtils.isEmpty(cids)) {
categories = categoryDao.listCategoryById(cids).toArray(new BlogCategory[cids.length]);
}
// 标签
BlogLabel[] labels = null;
int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), sn);
if (!CollectionUtils.isEmpty(lids)) {
labels = labelDao.listLabelById(lids).toArray(new BlogLabel[lids.length]);
}
int c = 0;
// 喜欢该篇文章的人
BloggerDTO[] likes = null;
List<BlogLike> likeList = likeDao.listAllLikeByBlogId(blogId);
if (!CollectionUtils.isEmpty(likeList)) {
int[] ids = new int[likeList.size()];
for (BlogLike like : likeList) {
ids[c++] = like.getLikerId();
}
likes = getBlogger(ids, bloggerId);
}
// 收藏了该篇文章的人
BloggerDTO[] collects = null;
c = 0;
List<BlogCollect> collectList = collectDao.listAllCollectByBlogId(blogId);
if (!CollectionUtils.isEmpty(collectList)) {
int[] ids = new int[collectList.size()];
for (BlogCollect collect : collectList) {
ids[c++] = collect.getCollectorId();
}
collects = getBlogger(ids, bloggerId);
}
// 评论过该篇文章的人
BloggerDTO[] commenter = null;
c = 0;
List<BlogComment> commentList = commentDao.listAllCommentByBlogId(blogId);
if (!CollectionUtils.isEmpty(commentList)) {
int[] ids = new int[commentList.size()];
for (BlogComment comment : commentList) {
// 评论者注销,但其评论将保存(匿名)
Integer id = comment.getSpokesmanId();
if (id != null)
ids[c++] = id;
}
// ids 需要去重
commenter = getBlogger(IntStream.of(Arrays.copyOf(ids, c)).distinct().toArray(), bloggerId);
}
BlogStatisticsDTO dto = dataFillingManager.blogStatisticsToDTO(blog, statistics, categories, labels, likes, collects, commenter, dbProperties.getStringFiledSplitCharacterForString());
return new ResultBean<>(dto);
}
Aggregations