Search in sources :

Example 1 with BlogListItemDTO

use of com.duan.blogos.dto.blog.BlogListItemDTO in project BlogSystem by DuanJiaNing.

the class BloggerLikeBlogServiceImpl method listLikeBlog.

@Override
public ResultBean<List<FavouriteBlogListItemDTO>> listLikeBlog(int bloggerId, int offset, int rows, BlogSortRule sortRule) {
    List<BlogLike> likes = likeDao.listLikeBlog(bloggerId, offset, rows);
    if (CollectionUtils.isEmpty(likes))
        return null;
    // 排序
    List<BlogStatistics> temp = new ArrayList<>();
    // 方便排序后的重组
    Map<Integer, BlogLike> blogLikeMap = new HashMap<>();
    for (BlogLike like : likes) {
        int blogId = like.getBlogId();
        BlogStatistics statistics = statisticsDao.getStatistics(blogId);
        temp.add(statistics);
        blogLikeMap.put(blogId, like);
    }
    BlogListItemComparatorFactory factory = new BlogListItemComparatorFactory();
    temp.sort(factory.get(sortRule.getRule(), sortRule.getOrder()));
    // 构造结果
    List<FavouriteBlogListItemDTO> result = new ArrayList<>();
    for (BlogStatistics statistics : temp) {
        int blogId = statistics.getBlogId();
        // BlogListItemDTO
        Blog blog = blogDao.getBlogById(blogId);
        String ch = dbProperties.getStringFiledSplitCharacterForNumber();
        // category
        int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), ch);
        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);
        }
        BlogListItemDTO listItemDTO = fillingManager.blogListItemToDTO(statistics, CollectionUtils.isEmpty(categories) ? null : categories.toArray(new BlogCategory[categories.size()]), CollectionUtils.isEmpty(labels) ? null : labels.toArray(new BlogLabel[labels.size()]), blog, null);
        // BloggerDTO
        int authorId = blog.getBloggerId();
        BloggerAccount account = accountDao.getAccountById(authorId);
        BloggerProfile profile = profileDao.getProfileByBloggerId(authorId);
        BloggerPicture avatar = profile.getAvatarId() == null ? null : pictureDao.getPictureById(profile.getAvatarId());
        // 使使用默认的博主头像
        if (avatar == null) {
            avatar = new BloggerPicture();
            avatar.setCategory(BloggerPictureCategoryEnum.PUBLIC.getCode());
            avatar.setBloggerId(authorId);
            avatar.setId(-1);
        }
        String url = constructorManager.constructPictureUrl(avatar, BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR);
        avatar.setPath(url);
        BloggerDTO bloggerDTO = fillingManager.bloggerAccountToDTO(account, profile, avatar);
        // 结果
        BlogLike like = blogLikeMap.get(blogId);
        FavouriteBlogListItemDTO dto = fillingManager.likeBlogListItemToDTO(bloggerId, like, listItemDTO, bloggerDTO);
        result.add(dto);
    }
    return new ResultBean<>(result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlogListItemComparatorFactory(com.duan.blogos.manager.comparator.BlogListItemComparatorFactory) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 2 with BlogListItemDTO

use of com.duan.blogos.dto.blog.BlogListItemDTO in project BlogSystem by DuanJiaNing.

the class DataFillingManager method blogListItemToDTO.

public BlogListItemDTO blogListItemToDTO(BlogStatistics statistics, BlogCategory[] categories, BlogLabel[] labels, Blog blog, String blogImg) {
    BlogListItemDTO dto = new BlogListItemDTO();
    dto.setCategories(categories);
    dto.setLabels(labels);
    dto.setCollectCount(statistics.getCollectCount());
    dto.setCommentCount(statistics.getCommentCount());
    dto.setId(blog.getId());
    dto.setLikeCount(statistics.getLikeCount());
    dto.setReleaseDate(blog.getReleaseDate());
    dto.setSummary(blog.getSummary());
    dto.setTitle(blog.getTitle());
    dto.setViewCount(statistics.getViewCount());
    dto.setImg(blogImg);
    return dto;
}
Also used : BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO)

Example 3 with BlogListItemDTO

use of com.duan.blogos.dto.blog.BlogListItemDTO 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 BlogListItemDTO

use of com.duan.blogos.dto.blog.BlogListItemDTO in project BlogSystem by DuanJiaNing.

the class BloggerCollectBlogServiceImpl method listCollectBlog.

@Override
public ResultBean<List<FavouriteBlogListItemDTO>> listCollectBlog(int bloggerId, int categoryId, int offset, int rows, BlogSortRule sortRule) {
    List<BlogCollect> collects = collectDao.listCollectBlog(bloggerId, categoryId, offset, rows);
    if (CollectionUtils.isEmpty(collects))
        return null;
    // 排序
    List<BlogStatistics> temp = new ArrayList<>();
    // 方便排序后的重组
    Map<Integer, BlogCollect> blogCollectMap = new HashMap<>();
    for (BlogCollect collect : collects) {
        int blogId = collect.getBlogId();
        BlogStatistics statistics = statisticsDao.getStatistics(blogId);
        temp.add(statistics);
        blogCollectMap.put(blogId, collect);
    }
    BlogListItemComparatorFactory factory = new BlogListItemComparatorFactory();
    temp.sort(factory.get(sortRule.getRule(), sortRule.getOrder()));
    // 构造结果
    List<FavouriteBlogListItemDTO> result = new ArrayList<>();
    for (BlogStatistics statistics : temp) {
        int blogId = statistics.getBlogId();
        // BlogListItemDTO
        Blog blog = blogDao.getBlogById(blogId);
        String ch = dbProperties.getStringFiledSplitCharacterForNumber();
        // category
        int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), ch);
        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);
        }
        BlogListItemDTO listItemDTO = fillingManager.blogListItemToDTO(statistics, CollectionUtils.isEmpty(categories) ? null : categories.toArray(new BlogCategory[categories.size()]), CollectionUtils.isEmpty(labels) ? null : labels.toArray(new BlogLabel[labels.size()]), blog, null);
        // BloggerDTO
        int authorId = blog.getBloggerId();
        BloggerAccount account = accountDao.getAccountById(authorId);
        BloggerProfile profile = profileDao.getProfileByBloggerId(authorId);
        BloggerPicture avatar = profile.getAvatarId() == null ? null : pictureDao.getPictureById(profile.getAvatarId());
        // 使使用默认的博主头像
        if (avatar == null) {
            avatar = new BloggerPicture();
            avatar.setCategory(BloggerPictureCategoryEnum.PUBLIC.getCode());
            avatar.setBloggerId(authorId);
            avatar.setId(-1);
        }
        String url = constructorManager.constructPictureUrl(avatar, BloggerPictureCategoryEnum.DEFAULT_BLOGGER_AVATAR);
        avatar.setPath(url);
        BloggerDTO bloggerDTO = fillingManager.bloggerAccountToDTO(account, profile, avatar);
        // 结果
        BlogCollect collect = blogCollectMap.get(blogId);
        FavouriteBlogListItemDTO dto = fillingManager.collectBlogListItemToDTO(bloggerId, collect, listItemDTO, bloggerDTO);
        result.add(dto);
    }
    return new ResultBean<>(result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlogListItemComparatorFactory(com.duan.blogos.manager.comparator.BlogListItemComparatorFactory) BloggerPicture(com.duan.blogos.entity.blogger.BloggerPicture) BloggerAccount(com.duan.blogos.entity.blogger.BloggerAccount) BloggerProfile(com.duan.blogos.entity.blogger.BloggerProfile) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BloggerDTO(com.duan.blogos.dto.blogger.BloggerDTO) FavouriteBlogListItemDTO(com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO) BlogListItemDTO(com.duan.blogos.dto.blog.BlogListItemDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Aggregations

BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)4 ResultBean (com.duan.blogos.restful.ResultBean)3 ArrayList (java.util.ArrayList)3 BloggerDTO (com.duan.blogos.dto.blogger.BloggerDTO)2 FavouriteBlogListItemDTO (com.duan.blogos.dto.blogger.FavouriteBlogListItemDTO)2 BloggerAccount (com.duan.blogos.entity.blogger.BloggerAccount)2 BloggerPicture (com.duan.blogos.entity.blogger.BloggerPicture)2 BloggerProfile (com.duan.blogos.entity.blogger.BloggerProfile)2 BlogListItemComparatorFactory (com.duan.blogos.manager.comparator.BlogListItemComparatorFactory)2 HashMap (java.util.HashMap)2 Blog (com.duan.blogos.entity.blog.Blog)1 BlogCategory (com.duan.blogos.entity.blog.BlogCategory)1 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)1 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)1