use of com.duan.blogos.entity.blog.BlogStatistics in project BlogSystem by DuanJiaNing.
the class BloggerBlogServiceImpl method constructResult.
@Override
protected ResultBean<List<BlogListItemDTO>> constructResult(Map<Integer, Blog> blogHashMap, List<BlogStatistics> statistics, Map<Integer, int[]> blogIdMapCategoryIds, Map<Integer, String> blogImgs) {
// 重组结果
List<BlogListItemDTO> result = new ArrayList<>();
for (BlogStatistics s : statistics) {
Integer blogId = s.getBlogId();
int[] ids = blogIdMapCategoryIds.get(blogId);
List<BlogCategory> categories = CollectionUtils.isEmpty(ids) ? null : categoryDao.listCategoryById(ids);
Blog blog = blogHashMap.get(blogId);
BlogListItemDTO dto = dataFillingManager.bloggerBlogListItemToDTO(blog, s, categories);
result.add(dto);
}
return new ResultBean<>(result);
}
use of com.duan.blogos.entity.blog.BlogStatistics in project BlogSystem by DuanJiaNing.
the class BlogFilterAbstract method sortAndConstructResult.
// 对筛选出的博文进行排序并重组结果集
private T sortAndConstructResult(List<Blog> blogs, BlogSortRule sortRule, Map<Integer, int[]> map) {
// 用于排序
List<BlogStatistics> temp = new ArrayList<>();
// 方便排序后的重组
Map<Integer, Blog> blogHashMap = new HashMap<>();
// 从 html 中获得图片
Map<Integer, String> blogImgs = new HashMap<>();
for (Blog blog : blogs) {
int blogId = blog.getId();
BlogStatistics statistics = statisticsDao.getStatistics(blogId);
temp.add(statistics);
blogHashMap.put(blogId, blog);
String content = blog.getContent();
Pattern pattern = Pattern.compile("<img src=\"(.*)\" .*>");
Matcher matcher = pattern.matcher(content);
if (matcher.find())
blogImgs.put(blogId, matcher.group(1));
}
BlogListItemComparatorFactory factory = new BlogListItemComparatorFactory();
temp.sort(factory.get(sortRule.getRule(), sortRule.getOrder()));
return constructResult(blogHashMap, temp, map, blogImgs);
}
use of com.duan.blogos.entity.blog.BlogStatistics in project BlogSystem by DuanJiaNing.
the class BlogRetrievalServiceImpl method constructResult.
@Override
protected ResultBean<List<BlogListItemDTO>> constructResult(Map<Integer, Blog> blogHashMap, List<BlogStatistics> statistics, Map<Integer, int[]> blogIdMapCategoryIds, Map<Integer, String> blogImgs) {
// 重组结果
List<BlogListItemDTO> result = new ArrayList<>();
String ch = dbProperties.getStringFiledSplitCharacterForNumber();
for (BlogStatistics ss : statistics) {
Integer blogId = ss.getBlogId();
Blog blog = blogHashMap.get(blogId);
// category
int[] cids = blogIdMapCategoryIds.get(blogId);
List<BlogCategory> categories = null;
if (!CollectionUtils.isEmpty(cids)) {
categories = categoryDao.listCategoryById(cids);
}
// label
int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
List<BlogLabel> labels = null;
if (!CollectionUtils.isEmpty(lids)) {
labels = labelDao.listLabelById(lids);
}
String blogImg = blogImgs.get(blogId);
BlogListItemDTO dto = dataFillingManager.blogListItemToDTO(ss, CollectionUtils.isEmpty(categories) ? null : categories.toArray(new BlogCategory[categories.size()]), CollectionUtils.isEmpty(labels) ? null : labels.toArray(new BlogLabel[labels.size()]), blog, blogImg);
result.add(dto);
}
return new ResultBean<>(result);
}
use of com.duan.blogos.entity.blog.BlogStatistics in project BlogSystem by DuanJiaNing.
the class BloggerBlogServiceImpl method insertBlog.
@Override
public int insertBlog(int bloggerId, int[] categories, int[] labels, BlogStatusEnum status, String title, String content, String contentMd, String summary, String[] keyWords) {
// 1 插入数据到bolg表
String ch = dbProperties.getStringFiledSplitCharacterForNumber();
String chs = dbProperties.getStringFiledSplitCharacterForString();
Blog blog = new Blog();
blog.setBloggerId(bloggerId);
blog.setCategoryIds(StringUtils.intArrayToString(categories, ch));
blog.setLabelIds(StringUtils.intArrayToString(labels, ch));
blog.setState(status.getCode());
blog.setTitle(title);
blog.setContent(content);
blog.setContentMd(contentMd);
blog.setSummary(summary);
blog.setKeyWords(StringUtils.arrayToString(keyWords, chs));
blog.setWordCount(content.length());
int effect = blogDao.insert(blog);
if (effect <= 0)
return -1;
int blogId = blog.getId();
// 2 插入数据到blog_statistics表(生成博文信息记录)
BlogStatistics statistics = new BlogStatistics();
statistics.setBlogId(blogId);
effect = statisticsDao.insert(statistics);
if (effect <= 0)
throw new SQLException();
// 3 解析本地图片引用并使自增
int[] imids = parseContentForImageIds(content, bloggerId);
// UPDATE: 2018/1/19 更新 自增并没有实际作用
if (!CollectionUtils.isEmpty(imids)) {
// 修改图片可见性,引用次数
Arrays.stream(imids).forEach(id -> imageManager.imageInsertHandle(bloggerId, id));
}
// 4 lucene创建索引
try {
luceneIndexManager.add(blog);
} catch (IOException e) {
e.printStackTrace();
throw new LuceneException(e);
}
return blogId;
}
Aggregations