Search in sources :

Example 1 with BlogLabel

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

the class BloggerLabelServiceImpl method insertLabel.

@Override
public int insertLabel(int bloggerId, String title) {
    BlogLabel label = new BlogLabel();
    label.setBloggerId(bloggerId);
    label.setTitle(title);
    int effect = labelDao.insert(label);
    if (effect <= 0)
        return -1;
    return label.getId();
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel)

Example 2 with BlogLabel

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

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

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

the class BloggerLabelServiceImpl method deleteLabel.

@Override
public boolean deleteLabel(int bloggerId, int labelId) {
    // 检查标签存在及标签创建者是否为当前博主
    BlogLabel label = labelDao.getLabel(labelId);
    if (label == null || label.getBloggerId() != bloggerId)
        return false;
    // 删除数据库记录
    int effect = labelDao.delete(labelId);
    if (effect <= 0)
        return false;
    // 将所有拥有该标签的博文修改(j将标签移除)
    List<Blog> blogs = blogDao.listAllLabelByBloggerId(bloggerId);
    String ch = dbProperties.getStringFiledSplitCharacterForNumber();
    for (Blog blog : blogs) {
        int[] lids = StringUtils.intStringDistinctToArray(blog.getLabelIds(), ch);
        if (CollectionUtils.isEmpty(lids))
            continue;
        if (CollectionUtils.intArrayContain(lids, labelId)) {
            int[] ids = ArrayUtils.removeFromArray(lids, labelId);
            blog.setLabelIds(StringUtils.intArrayToString(ids, ch));
            if (blogDao.update(blog) <= 0)
                throw new SQLException();
        }
    }
    return true;
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel) SQLException(com.duan.blogos.exception.internal.SQLException) Blog(com.duan.blogos.entity.blog.Blog)

Example 5 with BlogLabel

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

the class BloggerLabelServiceImpl method updateLabel.

@Override
public boolean updateLabel(int labelId, int bloggerId, String newTitle) {
    // 检查标签存在及标签创建者是否为当前博主
    BlogLabel label = labelDao.getLabel(labelId);
    if (label == null || label.getBloggerId() != bloggerId)
        return false;
    BlogLabel la = new BlogLabel();
    la.setTitle(newTitle);
    la.setId(labelId);
    int effect = labelDao.update(la);
    if (effect <= 0)
        return false;
    return true;
}
Also used : BlogLabel(com.duan.blogos.entity.blog.BlogLabel)

Aggregations

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