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