use of com.duan.blogos.entity.blog.Blog 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.Blog 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;
}
use of com.duan.blogos.entity.blog.Blog in project BlogSystem by DuanJiaNing.
the class BloggerBlogServiceImpl method getBlog.
@Override
public ResultBean<Blog> getBlog(int bloggerId, int blogId) {
Blog blog = blogDao.getBlogById(blogId);
String ch = dbProperties.getStringFiledSplitCharacterForNumber();
String chs = dbProperties.getStringFiledSplitCharacterForString();
String whs = websiteProperties.getUrlConditionSplitCharacter();
if (blog != null && blog.getBloggerId().equals(bloggerId)) {
String cids = blog.getCategoryIds();
String lids = blog.getLabelIds();
String keyWords = blog.getKeyWords();
if (!StringUtils.isEmpty(cids))
blog.setCategoryIds(cids.replace(ch, whs));
if (!StringUtils.isEmpty(lids))
blog.setLabelIds(lids.replace(ch, whs));
if (!StringUtils.isEmpty_(keyWords))
blog.setKeyWords(keyWords.replace(chs, whs));
return new ResultBean<>(blog);
}
return null;
}
use of com.duan.blogos.entity.blog.Blog 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;
}
use of com.duan.blogos.entity.blog.Blog 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;
}
Aggregations