Search in sources :

Example 1 with BlogStatistics

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);
}
Also used : BlogCategory(com.duan.blogos.entity.blog.BlogCategory) BlogStatistics(com.duan.blogos.entity.blog.BlogStatistics) BlogListItemDTO(com.duan.blogos.dto.blogger.BlogListItemDTO) Blog(com.duan.blogos.entity.blog.Blog) ResultBean(com.duan.blogos.restful.ResultBean)

Example 2 with BlogStatistics

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);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BlogStatistics(com.duan.blogos.entity.blog.BlogStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlogListItemComparatorFactory(com.duan.blogos.manager.comparator.BlogListItemComparatorFactory) Blog(com.duan.blogos.entity.blog.Blog)

Example 3 with BlogStatistics

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);
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel) BlogCategory(com.duan.blogos.entity.blog.BlogCategory) ArrayList(java.util.ArrayList) BlogStatistics(com.duan.blogos.entity.blog.BlogStatistics) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) Blog(com.duan.blogos.entity.blog.Blog) ResultBean(com.duan.blogos.restful.ResultBean)

Example 4 with BlogStatistics

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;
}
Also used : SQLException(com.duan.blogos.exception.internal.SQLException) BlogStatistics(com.duan.blogos.entity.blog.BlogStatistics) IOException(java.io.IOException) Blog(com.duan.blogos.entity.blog.Blog) LuceneException(com.duan.blogos.exception.internal.LuceneException)

Aggregations

Blog (com.duan.blogos.entity.blog.Blog)4 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)4 BlogCategory (com.duan.blogos.entity.blog.BlogCategory)2 ResultBean (com.duan.blogos.restful.ResultBean)2 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)1 BlogListItemDTO (com.duan.blogos.dto.blogger.BlogListItemDTO)1 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)1 LuceneException (com.duan.blogos.exception.internal.LuceneException)1 SQLException (com.duan.blogos.exception.internal.SQLException)1 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1