use of com.duan.blogos.enums.BlogStatusEnum in project BlogSystem by DuanJiaNing.
the class BloggerBlogServiceImpl method updateBlog.
@Override
public boolean updateBlog(int bloggerId, int blogId, int[] newCategories, int[] newLabels, BlogStatusEnum newStatus, String newTitle, String newContent, String newContentMd, String newSummary, String[] newKeyWords) {
// 1 更新博文中引用的本地图片(取消引用的useCount--,新增的useCount++)
Blog oldBlog = blogDao.getBlogById(blogId);
if (newContent != null) {
if (!oldBlog.getContent().equals(newContent)) {
// 1 2 3 4
final int[] oldIids = parseContentForImageIds(oldBlog.getContent(), bloggerId);
// 1 3 4 6
final int[] newIids = parseContentForImageIds(newContent, bloggerId);
// 求交集 1 3 4
int[] array = IntStream.of(oldIids).filter(value -> {
for (int id : newIids) if (id == value)
return true;
return false;
}).toArray();
// -- 2
int[] allM = new int[oldIids.length + array.length];
System.arraycopy(oldIids, 0, allM, 0, oldIids.length);
System.arraycopy(array, 0, allM, oldIids.length, array.length);
IntStream.of(allM).distinct().forEach(pictureDao::updateUseCountMinus);
// ++ 6
int[] allP = new int[newIids.length + array.length];
System.arraycopy(newIids, 0, allP, 0, newIids.length);
System.arraycopy(array, 0, allP, newIids.length, array.length);
IntStream.of(allP).distinct().forEach(id -> {
pictureDao.updateUseCountPlus(id);
// 将用到的图片修改为public(有必要的话)
try {
imageManager.moveImageAndUpdateDbIfNecessary(bloggerId, id, BloggerPictureCategoryEnum.PUBLIC);
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
// 2 更新博文
String ch = dbProperties.getStringFiledSplitCharacterForNumber();
String chs = dbProperties.getStringFiledSplitCharacterForString();
Blog blog = new Blog();
blog.setId(blogId);
if (newCategories != null)
blog.setCategoryIds(StringUtils.intArrayToString(newCategories, ch));
if (newLabels != null)
blog.setLabelIds(StringUtils.intArrayToString(newLabels, ch));
// 博文未通过审核时不能修改状态
if (newStatus != null && !oldBlog.getState().equals(BlogStatusEnum.VERIFY.getCode()))
blog.setState(newStatus.getCode());
if (newTitle != null)
blog.setTitle(newTitle);
if (newContent != null)
blog.setContent(newContent);
if (newSummary != null)
blog.setSummary(newSummary);
if (newContentMd != null)
blog.setContentMd(newContentMd);
if (newKeyWords != null)
blog.setKeyWords(StringUtils.arrayToString(newKeyWords, chs));
int effect = blogDao.update(blog);
if (effect <= 0)
throw new SQLException();
// 3 更新lucene
try {
luceneIndexManager.update(blog);
} catch (IOException e) {
e.printStackTrace();
throw new LuceneException(e);
}
return true;
}
use of com.duan.blogos.enums.BlogStatusEnum in project BlogSystem by DuanJiaNing.
the class BloggerBlogController method list.
/**
* 检索博文
*/
@RequestMapping(method = RequestMethod.GET)
public ResultBean<List<BlogListItemDTO>> list(HttpServletRequest request, @PathVariable Integer bloggerId, @RequestParam(value = "cids", required = false) String categoryIds, @RequestParam(value = "lids", required = false) String labelIds, @RequestParam(value = "kword", required = false) String keyWord, @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "rows", required = false) Integer rows, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "order", required = false) String order, @RequestParam(value = "status", required = false) Integer status) {
handleBloggerSignInCheck(request, bloggerId);
// 检查排序规则
String sor = sort == null ? Rule.VIEW_COUNT.name() : sort.toUpperCase();
String ord = order == null ? Order.DESC.name() : order.toUpperCase();
handleSortRuleCheck(request, sor, ord);
String sp = websiteProperties.getUrlConditionSplitCharacter();
int[] cids = StringUtils.intStringDistinctToArray(categoryIds, sp);
int[] lids = StringUtils.intStringDistinctToArray(labelIds, sp);
// 检查博文类别和标签
handleCategoryAndLabelCheck(request, bloggerId, cids, lids);
BlogStatusEnum stat = null;
if (status != null)
stat = BlogStatusEnum.valueOf(status);
// status传参错误
if (stat == null)
stat = BlogStatusEnum.PUBLIC;
// 执行数据查询
BlogSortRule rule = new BlogSortRule(Rule.valueOf(sor), Order.valueOf(ord));
int os = offset == null || offset < 0 ? 0 : offset;
int rs = rows == null || rows < 0 ? bloggerProperties.getRequestBlogListCount() : rows;
ResultBean<List<BlogListItemDTO>> listResultBean = bloggerBlogService.listFilterAll(cids, lids, keyWord, bloggerId, os, rs, rule, stat);
if (listResultBean == null)
handlerEmptyResult(request);
return listResultBean;
}
use of com.duan.blogos.enums.BlogStatusEnum in project BlogSystem by DuanJiaNing.
the class BlogValidateManager method isBlogStatusAllow.
/**
* 检查目标博文状态是否允许,一般用户只允许在“公开”,“私有”,“回收站”之间切换。
*
* @param status 状态值
* @return 允许返回true
*/
public boolean isBlogStatusAllow(int status) {
List<BlogStatusEnum> list = Arrays.asList(BlogStatusEnum.PUBLIC, BlogStatusEnum.PRIVATE, BlogStatusEnum.DELETED);
int contain = 0;
for (BlogStatusEnum s : list) {
if (s.getCode() == status)
contain++;
}
return contain > 0;
}
use of com.duan.blogos.enums.BlogStatusEnum in project BlogSystem by DuanJiaNing.
the class BloggerBlogController method update.
/**
* 更新博文
*/
@RequestMapping(value = "/{blogId}", method = RequestMethod.PUT)
public ResultBean update(HttpServletRequest request, @PathVariable Integer bloggerId, @PathVariable Integer blogId, @RequestParam(value = "title", required = false) String newTitle, @RequestParam(value = "content", required = false) String newContent, @RequestParam(value = "contentMd", required = false) String newContentMd, @RequestParam(value = "summary", required = false) String newSummary, @RequestParam(value = "cids", required = false) String newCategoryIds, @RequestParam(value = "lids", required = false) String newLabelIds, @RequestParam(value = "kword", required = false) String newKeyWord, @RequestParam(value = "status", required = false) Integer newStatus) {
// 所有参数都为null,则不更新。
if (Stream.of(newTitle, newContent, newSummary, newCategoryIds, newLabelIds, newKeyWord, newStatus).filter(Objects::nonNull).count() <= 0)
throw exceptionManager.getParameterIllegalException(new RequestContext(request));
// 检查修改到的博文状态是否允许
if (newStatus != null && !blogValidateManager.isBlogStatusAllow(newStatus))
throw exceptionManager.getParameterIllegalException(new RequestContext(request));
handleBloggerSignInCheck(request, bloggerId);
handleBlogExistAndCreatorCheck(request, bloggerId, blogId);
// 将 Unicode 解码
newContent = StringUtils.unicodeToString(newContent);
newContentMd = StringUtils.unicodeToString(newContentMd);
handleBlogContentCheck(request, newTitle, newContent, newContentMd, newSummary, newKeyWord);
String sp = websiteProperties.getUrlConditionSplitCharacter();
int[] cids = newCategoryIds == null ? null : StringUtils.intStringDistinctToArray(newCategoryIds, sp);
int[] lids = newLabelIds == null ? null : StringUtils.intStringDistinctToArray(newLabelIds, sp);
// 检查博文类别和标签
handleCategoryAndLabelCheck(request, bloggerId, cids, lids);
String[] kw = newKeyWord == null ? null : StringUtils.stringArrayToArray(newKeyWord, sp);
BlogStatusEnum stat = newStatus == null ? null : BlogStatusEnum.valueOf(newStatus);
// 执行更新
if (!bloggerBlogService.updateBlog(bloggerId, blogId, cids, lids, stat, newTitle, newContent, newContentMd, newSummary, kw))
handlerOperateFail(request);
return new ResultBean<>("");
}
Aggregations