Skip to content

Commit

Permalink
修改文章支持同步
Browse files Browse the repository at this point in the history
  • Loading branch information
byteblogs168 committed Feb 18, 2020
1 parent f557727 commit 000b902
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public Result savePosts(PostsVO postsVO) {
posts.setStatus(postsVO.getStatus()).setSummary(PreviewTextUtils.getText(html, 126)).setIsComment(postsVO.getIsComment())
.setAuthorId(userSessionInfo.getId()).setCategoryId(postsVO.getCategoryId()).setWeight(postsVO.getWeight());
postsDao.insert(posts);
postsVO.setId(posts.getId());

postsAttributeDao.insert(new PostsAttribute().setContent(postsVO.getContent()).setPostsId(posts.getId()));
List<TagsVO> tagsList = postsVO.getTagsList();
if (!CollectionUtils.isEmpty(tagsList)) {
Expand All @@ -103,17 +105,30 @@ public Result savePosts(PostsVO postsVO) {
});
}

if (syncByteblogs(postsVO, userSessionInfo)){
return Result.createWithSuccessMessage("文章保存成功,并且同步到ByteBlogs草稿箱,请点击" + Constants.BYTE_BLOGS_URL + "/editor/posts" + "进行编辑");
}

return Result.createWithSuccessMessage();
}

/**
* 同步数据到主站
* @param postsVO
* @param userSessionInfo
* @return
*/
private boolean syncByteblogs(PostsVO postsVO, UserSessionVO userSessionInfo) {
if (postsVO.getIsPublishByteBlogs().equals(Constants.YES)) {
String result = HttpUtil.post(Constants.BYTE_BLOGS_ADD_ARTICLE, JsonUtil.toJsonString(new PostsVO().setTitle(postsVO.getTitle()).setContent(postsVO.getContent()).setSocialId(userSessionInfo.getSocialId())));
Result result1 = JsonUtil.parseObject(result, Result.class);
log.debug("保存到ByteBlogs草稿箱 {}", result);
log.warn("保存到ByteBlogs草稿箱 {}", result);
if (result1.getSuccess() == Constants.YES) {
this.postsDao.update(new Posts().setSyncStatus(Constants.YES), new LambdaUpdateWrapper<Posts>().eq(Posts::getId, posts.getId()));
return Result.createWithSuccessMessage("文章保存成功,并且同步到ByteBlogs草稿箱,请点击" + Constants.BYTE_BLOGS_URL + "/editor/posts" + "进行编辑");
this.postsDao.update(new Posts().setSyncStatus(Constants.YES), new LambdaUpdateWrapper<Posts>().eq(Posts::getId, postsVO.getId()));
return true;
}
}

return Result.createWithSuccessMessage();
return false;
}

@Override
Expand Down Expand Up @@ -171,6 +186,10 @@ public Result updatePosts(PostsVO postsVO) {
postsTagsDao.delete(new LambdaQueryWrapper<PostsTags>().eq(PostsTags::getPostsId, posts1.getId()));
}

if (syncByteblogs(postsVO, userSessionInfo)){
return Result.createWithSuccessMessage("文章修改成功,并且同步到更新ByteBlogs");
}

return Result.createWithSuccessMessage();
}

Expand Down

0 comments on commit 000b902

Please sign in to comment.