Search in sources :

Example 1 with BlogCategory

use of com.duan.blogos.entity.blog.BlogCategory in project BlogSystem by DuanJiaNing.

the class BlogBrowseServiceImpl method getBlogMainContent.

@Override
public ResultBean<BlogMainContentDTO> getBlogMainContent(int blogId) {
    // 查询数据
    Blog blog = blogDao.getBlogById(blogId);
    if (blog == null)
        return null;
    String ch = dbProperties.getStringFiledSplitCharacterForNumber();
    int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), ch);
    int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
    List<BlogCategory> categories = cids == null ? null : categoryDao.listCategoryById(cids);
    List<BlogLabel> labels = lids == null ? null : labelDao.listLabelById(lids);
    // 填充数据
    String sc = dbProperties.getStringFiledSplitCharacterForString();
    BlogMainContentDTO dto = dataFillingManager.blogMainContentToDTO(blog, categories, labels, sc);
    return new ResultBean<>(dto);
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel) BlogCategory(com.duan.blogos.entity.blog.BlogCategory) Blog(com.duan.blogos.entity.blog.Blog) BlogMainContentDTO(com.duan.blogos.dto.blog.BlogMainContentDTO) ResultBean(com.duan.blogos.restful.ResultBean)

Example 2 with BlogCategory

use of com.duan.blogos.entity.blog.BlogCategory 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 3 with BlogCategory

use of com.duan.blogos.entity.blog.BlogCategory in project BlogSystem by DuanJiaNing.

the class BloggerCategoryServiceImpl method insertBlogCategory.

@Override
public int insertBlogCategory(int bloggerId, int iconId, String title, String bewrite) {
    BlogCategory category = new BlogCategory();
    category.setBewrite(bewrite);
    if (iconId > 0)
        category.setIconId(iconId);
    category.setBloggerId(bloggerId);
    category.setTitle(title);
    int effect = categoryDao.insert(category);
    if (effect <= 0)
        return -1;
    // 修改图片可见性,引用次数
    imageManager.imageInsertHandle(bloggerId, iconId);
    return category.getId();
}
Also used : BlogCategory(com.duan.blogos.entity.blog.BlogCategory)

Example 4 with BlogCategory

use of com.duan.blogos.entity.blog.BlogCategory 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 5 with BlogCategory

use of com.duan.blogos.entity.blog.BlogCategory in project BlogSystem by DuanJiaNing.

the class BloggerCategoryServiceImpl method deleteCategoryAndMoveBlogsTo.

@Override
public boolean deleteCategoryAndMoveBlogsTo(int bloggerId, int categoryId, int newCategoryId) {
    BlogCategory category = categoryDao.getCategory(bloggerId, categoryId);
    if (category == null)
        return false;
    // 图片引用次数--
    Integer iconId;
    if ((iconId = category.getIconId()) != null && pictureDao.getUseCount(iconId) > 0) {
        pictureDao.updateUseCountMinus(iconId);
    }
    // 删除数据库类别记录
    int effectDelete = categoryDao.delete(categoryId);
    if (effectDelete <= 0)
        throw new SQLException();
    // 修改博文类别
    List<Blog> blogs = blogDao.listAllCategoryByBloggerId(bloggerId);
    String sp = dbProperties.getStringFiledSplitCharacterForNumber();
    // 移除类别即可
    if (newCategoryId <= 0) {
        blogs.forEach(blog -> {
            int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), sp);
            if (CollectionUtils.intArrayContain(cids, categoryId)) {
                int[] ar = ArrayUtils.removeFromArray(cids, categoryId);
                blog.setCategoryIds(StringUtils.intArrayToString(ar, sp));
                int effectUpdate = blogDao.update(blog);
                if (effectUpdate <= 0)
                    throw new SQLException();
            }
        });
    } else {
        // 替换类别
        blogs.forEach(blog -> {
            int[] cids = StringUtils.intStringDistinctToArray(blog.getCategoryIds(), sp);
            if (CollectionUtils.intArrayContain(cids, categoryId)) {
                ArrayUtils.replace(cids, categoryId, newCategoryId);
                blog.setCategoryIds(StringUtils.intArrayToString(cids, sp));
                int effectUpdate = blogDao.update(blog);
                if (effectUpdate <= 0)
                    throw new SQLException();
            }
        });
    }
    return true;
}
Also used : BlogCategory(com.duan.blogos.entity.blog.BlogCategory) SQLException(com.duan.blogos.exception.internal.SQLException) Blog(com.duan.blogos.entity.blog.Blog)

Aggregations

BlogCategory (com.duan.blogos.entity.blog.BlogCategory)7 Blog (com.duan.blogos.entity.blog.Blog)4 ResultBean (com.duan.blogos.restful.ResultBean)4 BlogLabel (com.duan.blogos.entity.blog.BlogLabel)2 BlogStatistics (com.duan.blogos.entity.blog.BlogStatistics)2 ArrayList (java.util.ArrayList)2 BlogListItemDTO (com.duan.blogos.dto.blog.BlogListItemDTO)1 BlogMainContentDTO (com.duan.blogos.dto.blog.BlogMainContentDTO)1 BlogListItemDTO (com.duan.blogos.dto.blogger.BlogListItemDTO)1 BloggerCategoryDTO (com.duan.blogos.dto.blogger.BloggerCategoryDTO)1 SQLException (com.duan.blogos.exception.internal.SQLException)1