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);
}
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);
}
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();
}
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);
}
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;
}
Aggregations