From afd0b2caf7656b423e0b487b70ab2030585e8bc4 Mon Sep 17 00:00:00 2001 From: ronger Date: Sat, 7 Mar 2020 21:18:22 +0800 Subject: [PATCH 01/16] =?UTF-8?q?:sparkles:=20=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/constant/NotificationConstant.java | 2 + .../com/rymcu/vertical/dto/ArticleDTO.java | 2 + .../com/rymcu/vertical/dto/CommentDTO.java | 40 ++++++++ .../com/rymcu/vertical/entity/Comment.java | 2 +- .../rymcu/vertical/mapper/CommentMapper.java | 36 +++++++ .../vertical/service/CommentService.java | 16 +++ .../service/impl/ArticleServiceImpl.java | 18 +++- .../service/impl/CommentServiceImpl.java | 97 +++++++++++++++++++ .../vertical/service/impl/TagServiceImpl.java | 5 + .../vertical/util/NotificationUtils.java | 2 +- .../web/api/article/ArticleController.java | 13 +++ .../web/api/comment/CommentController.java | 34 +++++++ 12 files changed, 262 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/rymcu/vertical/dto/CommentDTO.java create mode 100644 src/main/java/com/rymcu/vertical/mapper/CommentMapper.java create mode 100644 src/main/java/com/rymcu/vertical/service/CommentService.java create mode 100644 src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java create mode 100644 src/main/java/com/rymcu/vertical/web/api/comment/CommentController.java diff --git a/src/main/java/com/rymcu/vertical/core/constant/NotificationConstant.java b/src/main/java/com/rymcu/vertical/core/constant/NotificationConstant.java index 41e53a1..19bbb61 100644 --- a/src/main/java/com/rymcu/vertical/core/constant/NotificationConstant.java +++ b/src/main/java/com/rymcu/vertical/core/constant/NotificationConstant.java @@ -10,4 +10,6 @@ public class NotificationConstant { public static String Follow = "1"; + public static String Comment = "2"; + } diff --git a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java index ce315ea..ea40f7f 100644 --- a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java @@ -47,4 +47,6 @@ public class ArticleDTO { private Author articleAuthor; private List tags; + + private List articleComments; } diff --git a/src/main/java/com/rymcu/vertical/dto/CommentDTO.java b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java new file mode 100644 index 0000000..0375d6c --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java @@ -0,0 +1,40 @@ +package com.rymcu.vertical.dto; + +import lombok.Data; + +import javax.persistence.Column; +import java.util.Date; + +/** + * @author ronger + */ +@Data +public class CommentDTO { + private Integer idComment; + /** 评论内容 */ + private String commentContent; + /** 作者 id */ + private Integer commentAuthorId; + /** 文章 id */ + private Integer commentArticleId; + /** 锚点 url */ + private String commentSharpUrl; + /** 父评论 id */ + private Integer commentOriginalCommentId; + /** 父评论作者头像 */ + private String commentOriginalAuthorThumbnailURL; + /** 状态 */ + private String commentStatus; + /** 0:公开回帖,1:匿名回帖 */ + private String commentAnonymous; + /** 回帖计数 */ + private Integer commentReplyCount; + /** 0:所有人可见,1:仅楼主和自己可见 */ + private String commentVisible; + /** 创建时间 */ + private Date createdTime; + + private Author commenter; + + private String timeAgo; +} diff --git a/src/main/java/com/rymcu/vertical/entity/Comment.java b/src/main/java/com/rymcu/vertical/entity/Comment.java index e8fb312..d9b71cc 100644 --- a/src/main/java/com/rymcu/vertical/entity/Comment.java +++ b/src/main/java/com/rymcu/vertical/entity/Comment.java @@ -19,7 +19,7 @@ public class Comment implements Serializable,Cloneable { @Id @GeneratedValue(generator = "JDBC") @Column(name = "id") - private Integer id; + private Integer idComment; /** 评论内容 */ @Column(name = "comment_content") private String commentContent; diff --git a/src/main/java/com/rymcu/vertical/mapper/CommentMapper.java b/src/main/java/com/rymcu/vertical/mapper/CommentMapper.java new file mode 100644 index 0000000..fba4a79 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/mapper/CommentMapper.java @@ -0,0 +1,36 @@ +package com.rymcu.vertical.mapper; + +import com.rymcu.vertical.core.mapper.Mapper; +import com.rymcu.vertical.dto.Author; +import com.rymcu.vertical.dto.CommentDTO; +import com.rymcu.vertical.entity.Comment; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface CommentMapper extends Mapper { + /** + * @param idArticle + * @return + */ + List selectArticleComments(@Param("idArticle") Integer idArticle); + + /** + * @param commentAuthorId + * @return + */ + Author selectAuthor(@Param("commentAuthorId") Integer commentAuthorId); + + /** + * @param commentOriginalCommentId + * @return + */ + Author selectCommentOriginalAuthor(@Param("commentOriginalCommentId") Integer commentOriginalCommentId); + + /** + * @param idComment + * @param toString + * @return + */ + Integer updateCommentSharpUrl(@Param("idComment") Integer idComment, @Param("commentSharpUrl") String commentSharpUrl); +} diff --git a/src/main/java/com/rymcu/vertical/service/CommentService.java b/src/main/java/com/rymcu/vertical/service/CommentService.java new file mode 100644 index 0000000..5324a42 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/CommentService.java @@ -0,0 +1,16 @@ +package com.rymcu.vertical.service; + +import com.rymcu.vertical.core.service.Service; +import com.rymcu.vertical.dto.CommentDTO; +import com.rymcu.vertical.entity.Comment; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.Map; + +public interface CommentService extends Service { + + List getArticleComments(Integer idArticle); + + Map postComment(Comment comment, HttpServletRequest request); +} diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java index 1178ab0..4b7ada1 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -5,12 +5,14 @@ import com.rymcu.vertical.core.service.AbstractService; import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.ArticleTagDTO; import com.rymcu.vertical.dto.Author; +import com.rymcu.vertical.dto.CommentDTO; import com.rymcu.vertical.entity.Article; import com.rymcu.vertical.entity.ArticleContent; import com.rymcu.vertical.entity.Tag; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.ArticleMapper; import com.rymcu.vertical.service.ArticleService; +import com.rymcu.vertical.service.CommentService; import com.rymcu.vertical.service.TagService; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.*; @@ -42,9 +44,13 @@ public class ArticleServiceImpl extends AbstractService
implements Arti private TagService tagService; @Resource private UserService userService; + @Resource + private CommentService commentService; @Value("${resource.domain}") - private static String domain; + private String domain; + @Value("${env}") + private String env; private static final int MAX_PREVIEW = 200; @@ -125,7 +131,9 @@ public class ArticleServiceImpl extends AbstractService
implements Arti newArticle.setArticlePermalink(domain + "/article/"+newArticle.getIdArticle()); newArticle.setArticleLink("/article/"+newArticle.getIdArticle()); articleMapper.insertArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml); - BaiDuUtils.sendSEOData(newArticle.getArticlePermalink()); + if (!"dev".equals(env)) { + BaiDuUtils.sendSEOData(newArticle.getArticlePermalink()); + } } else { newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle()); if(!user.getIdUser().equals(newArticle.getArticleAuthorId())){ @@ -144,7 +152,9 @@ public class ArticleServiceImpl extends AbstractService
implements Arti } newArticle.setUpdatedTime(new Date()); articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml); - BaiDuUtils.updateSEOData(newArticle.getArticlePermalink()); + if (!"dev".equals(env)) { + BaiDuUtils.updateSEOData(newArticle.getArticlePermalink()); + } } if (notification) { @@ -239,6 +249,8 @@ public class ArticleServiceImpl extends AbstractService
implements Arti String articlePreviewContent = articleContent.getArticleContentHtml().substring(0,length); article.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent)); } + List commentDTOList = commentService.getArticleComments(article.getIdArticle()); + article.setArticleComments(commentDTOList); return article; } } diff --git a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java new file mode 100644 index 0000000..2aef75d --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -0,0 +1,97 @@ +package com.rymcu.vertical.service.impl; + +import com.rymcu.vertical.core.constant.NotificationConstant; +import com.rymcu.vertical.core.service.AbstractService; +import com.rymcu.vertical.dto.Author; +import com.rymcu.vertical.dto.CommentDTO; +import com.rymcu.vertical.entity.Article; +import com.rymcu.vertical.entity.Comment; +import com.rymcu.vertical.mapper.CommentMapper; +import com.rymcu.vertical.service.ArticleService; +import com.rymcu.vertical.service.CommentService; +import com.rymcu.vertical.util.Html2TextUtil; +import com.rymcu.vertical.util.NotificationUtils; +import com.rymcu.vertical.util.Utils; +import org.apache.commons.lang.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.*; + +@Service +public class CommentServiceImpl extends AbstractService implements CommentService { + + @Resource + private CommentMapper commentMapper; + @Resource + private ArticleService articleService; + + private static final int MAX_PREVIEW = 200; + + @Override + public List getArticleComments(Integer idArticle) { + List commentDTOList = commentMapper.selectArticleComments(idArticle); + commentDTOList.forEach(commentDTO -> { + commentDTO.setTimeAgo(Utils.getTimeAgo(commentDTO.getCreatedTime())); + if (commentDTO.getCommentAuthorId() != null) { + Author author = commentMapper.selectAuthor(commentDTO.getCommentAuthorId()); + if (author != null) { + commentDTO.setCommenter(author); + } + } + if (commentDTO.getCommentOriginalCommentId() != null) { + Author commentOriginalAuthor = commentMapper.selectCommentOriginalAuthor(commentDTO.getCommentOriginalCommentId()); + if (commentOriginalAuthor != null) { + commentDTO.setCommentOriginalAuthorThumbnailURL(commentOriginalAuthor.getUserAvatarURL()); + } + } + }); + return commentDTOList; + } + + @Override + public Map postComment(Comment comment, HttpServletRequest request) { + Map map = new HashMap(1); + if(comment.getCommentArticleId() == null){ + map.put("message","非法访问,文章主键异常!"); + return map; + } + if(comment.getCommentAuthorId() == null){ + map.put("message","非法访问,用户未登录!"); + return map; + } + if(StringUtils.isBlank(comment.getCommentContent())){ + map.put("message","回帖内容不能为空!"); + return map; + } + Article article = articleService.findById(comment.getCommentArticleId().toString()); + if (article == null) { + map.put("message","文章不存在!"); + return map; + } + String ip = Utils.getIpAddress(request); + String ua = request.getHeader("user-agent"); + comment.setCommentIP(ip); + comment.setCommentUA(ua); + comment.setCreatedTime(new Date()); + commentMapper.insertSelective(comment); + StringBuilder commentSharpUrl = new StringBuilder(article.getArticlePermalink()); + commentSharpUrl.append("/comment/").append(comment.getIdComment()); + commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString()); + + String commentContent = comment.getCommentContent(); + if(StringUtils.isNotBlank(commentContent)){ + Integer length = commentContent.length(); + if(length > MAX_PREVIEW){ + length = 200; + } + String commentPreviewContent = commentContent.substring(0,length); + commentContent = Html2TextUtil.getContent(commentPreviewContent); + } + + NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); + + return map; + } +} diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java index 4c02be0..256e56a 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java @@ -1,9 +1,11 @@ package com.rymcu.vertical.service.impl; import com.rymcu.vertical.core.service.AbstractService; +import com.rymcu.vertical.dto.ArticleTagDTO; import com.rymcu.vertical.entity.Article; import com.rymcu.vertical.entity.Tag; import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.mapper.ArticleMapper; import com.rymcu.vertical.mapper.TagMapper; import com.rymcu.vertical.service.TagService; import com.rymcu.vertical.util.UserUtils; @@ -29,6 +31,8 @@ public class TagServiceImpl extends AbstractService implements TagService { @Resource private TagMapper tagMapper; + @Resource + private ArticleMapper articleMapper; @Override @Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class }) @@ -43,6 +47,7 @@ public class TagServiceImpl extends AbstractService implements TagService { Tag tag = new Tag(); tag.setTagTitle(tags[i]); tag = tagMapper.selectOne(tag); + List articleTagDTOList = articleMapper.selectTags(article.getIdArticle()); if(tag == null){ tag = new Tag(); tag.setTagTitle(tags[i]); diff --git a/src/main/java/com/rymcu/vertical/util/NotificationUtils.java b/src/main/java/com/rymcu/vertical/util/NotificationUtils.java index 112f20b..7a42c0c 100644 --- a/src/main/java/com/rymcu/vertical/util/NotificationUtils.java +++ b/src/main/java/com/rymcu/vertical/util/NotificationUtils.java @@ -42,7 +42,7 @@ public class NotificationUtils { },executor); } - private static void saveNotification(Integer idUser, Integer dataId, String dataType, String dataSummary) { + public static void saveNotification(Integer idUser, Integer dataId, String dataType, String dataSummary) { ExecutorService executor= new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); CompletableFuture.supplyAsync(()-> { try { diff --git a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java index 631e1c5..5874af4 100644 --- a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java +++ b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java @@ -3,7 +3,9 @@ package com.rymcu.vertical.web.api.article; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.dto.ArticleDTO; +import com.rymcu.vertical.dto.CommentDTO; import com.rymcu.vertical.service.ArticleService; +import com.rymcu.vertical.service.CommentService; import com.rymcu.vertical.web.api.exception.BaseApiException; import org.springframework.web.bind.annotation.*; @@ -11,6 +13,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -22,6 +25,8 @@ public class ArticleController { @Resource private ArticleService articleService; + @Resource + private CommentService commentService; @@ -51,4 +56,12 @@ public class ArticleController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/{id}/comments") + public GlobalResult> commons(@PathVariable Integer id){ + List commentDTOList = commentService.getArticleComments(id); + Map map = new HashMap<>(1); + map.put("comments", commentDTOList); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/com/rymcu/vertical/web/api/comment/CommentController.java b/src/main/java/com/rymcu/vertical/web/api/comment/CommentController.java new file mode 100644 index 0000000..814b625 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/web/api/comment/CommentController.java @@ -0,0 +1,34 @@ +package com.rymcu.vertical.web.api.comment; + +import com.rymcu.vertical.core.result.GlobalResult; +import com.rymcu.vertical.core.result.GlobalResultGenerator; +import com.rymcu.vertical.dto.ArticleDTO; +import com.rymcu.vertical.entity.Comment; +import com.rymcu.vertical.service.CommentService; +import com.rymcu.vertical.web.api.exception.BaseApiException; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.UnsupportedEncodingException; +import java.util.Map; + +/** + * @author ronger + */ +@RestController +@RequestMapping("/api/v1/comment") +public class CommentController { + + @Resource + private CommentService commentService; + + @PostMapping("/post") + public GlobalResult postComment(@RequestBody Comment comment, HttpServletRequest request) throws BaseApiException, UnsupportedEncodingException { + Map map = commentService.postComment(comment,request); + return GlobalResultGenerator.genSuccessResult(map); + } +} From ea3bc5402a5897c464f79e7e45901b08addc86ff Mon Sep 17 00:00:00 2001 From: ronger Date: Sat, 7 Mar 2020 21:51:58 +0800 Subject: [PATCH 02/16] =?UTF-8?q?:sparkles:=20=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/mapper/CommentMapper.xml | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/mapper/CommentMapper.xml diff --git a/src/main/java/mapper/CommentMapper.xml b/src/main/java/mapper/CommentMapper.xml new file mode 100644 index 0000000..cbc5cbc --- /dev/null +++ b/src/main/java/mapper/CommentMapper.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + update vertical_comment set comment_sharp_url = #{commentSharpUrl} where id = #{idComment} + + + + + \ No newline at end of file From 0e053ef7141f76ece541c929626b4beb7d6c3b80 Mon Sep 17 00:00:00 2001 From: x ronger Date: Sun, 8 Mar 2020 00:13:22 +0800 Subject: [PATCH 03/16] =?UTF-8?q?:sparkles:=20=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/rymcu/vertical/dto/CommentDTO.java | 2 ++ .../com/rymcu/vertical/service/impl/CommentServiceImpl.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/rymcu/vertical/dto/CommentDTO.java b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java index 0375d6c..64b77ee 100644 --- a/src/main/java/com/rymcu/vertical/dto/CommentDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java @@ -23,6 +23,8 @@ public class CommentDTO { private Integer commentOriginalCommentId; /** 父评论作者头像 */ private String commentOriginalAuthorThumbnailURL; + /** 父评论作者昵称 */ + private String commentOriginalAuthorNickname; /** 状态 */ private String commentStatus; /** 0:公开回帖,1:匿名回帖 */ diff --git a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java index 2aef75d..6f4c197 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -44,6 +44,7 @@ public class CommentServiceImpl extends AbstractService implements Comm Author commentOriginalAuthor = commentMapper.selectCommentOriginalAuthor(commentDTO.getCommentOriginalCommentId()); if (commentOriginalAuthor != null) { commentDTO.setCommentOriginalAuthorThumbnailURL(commentOriginalAuthor.getUserAvatarURL()); + commentDTO.setCommentOriginalAuthorNickname(commentOriginalAuthor.getUserNickname()); } } }); From ef56fba8673d76a43bb5da372dff4d09cd982f0a Mon Sep 17 00:00:00 2001 From: x ronger Date: Sun, 8 Mar 2020 00:53:36 +0800 Subject: [PATCH 04/16] =?UTF-8?q?:bug:=20=E8=AF=84=E8=AE=BA=E8=80=85?= =?UTF-8?q?=E4=B8=8D=E6=98=AF=E4=BD=9C=E8=80=85=E6=9C=AC=E4=BA=BA=E6=89=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E6=96=87=E7=AB=A0=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CommentServiceImpl.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java index 6f4c197..2e7b044 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -81,18 +81,20 @@ public class CommentServiceImpl extends AbstractService implements Comm commentSharpUrl.append("/comment/").append(comment.getIdComment()); commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString()); - String commentContent = comment.getCommentContent(); - if(StringUtils.isNotBlank(commentContent)){ - Integer length = commentContent.length(); - if(length > MAX_PREVIEW){ - length = 200; + // 评论者不是作者本人则进行消息通知 + if (!article.getArticleAuthorId().equals(comment.getCommentAuthorId())) { + String commentContent = comment.getCommentContent(); + if(StringUtils.isNotBlank(commentContent)){ + Integer length = commentContent.length(); + if(length > MAX_PREVIEW){ + length = 200; + } + String commentPreviewContent = commentContent.substring(0,length); + commentContent = Html2TextUtil.getContent(commentPreviewContent); + NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); } - String commentPreviewContent = commentContent.substring(0,length); - commentContent = Html2TextUtil.getContent(commentPreviewContent); } - NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); - return map; } } From a21339d68d170766d1d595d9c6b5f653aaaa47ee Mon Sep 17 00:00:00 2001 From: x ronger Date: Sun, 8 Mar 2020 01:00:28 +0800 Subject: [PATCH 05/16] =?UTF-8?q?:sparkles:=20=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CommentServiceImpl.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java index 2e7b044..dfe6232 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -81,20 +81,29 @@ public class CommentServiceImpl extends AbstractService implements Comm commentSharpUrl.append("/comment/").append(comment.getIdComment()); commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString()); - // 评论者不是作者本人则进行消息通知 - if (!article.getArticleAuthorId().equals(comment.getCommentAuthorId())) { - String commentContent = comment.getCommentContent(); - if(StringUtils.isNotBlank(commentContent)){ - Integer length = commentContent.length(); - if(length > MAX_PREVIEW){ - length = 200; - } - String commentPreviewContent = commentContent.substring(0,length); - commentContent = Html2TextUtil.getContent(commentPreviewContent); + String commentContent = comment.getCommentContent(); + if(StringUtils.isNotBlank(commentContent)){ + Integer length = commentContent.length(); + if(length > MAX_PREVIEW){ + length = 200; + } + String commentPreviewContent = commentContent.substring(0,length); + commentContent = Html2TextUtil.getContent(commentPreviewContent); + // 评论者不是作者本人则进行消息通知 + if (article.getArticleAuthorId().equals(comment.getCommentAuthorId())) { NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); } + // 判断是否是回复消息 + if (comment.getCommentOriginalCommentId() != null) { + Comment originalComment = commentMapper.selectByPrimaryKey(comment.getCommentOriginalCommentId()); + // 回复消息时,评论者不是上级评论作者则进行消息通知 + if (!comment.getCommentAuthorId().equals(originalComment.getCommentAuthorId())) { + NotificationUtils.saveNotification(originalComment.getCommentAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); + } + } } + return map; } } From 40cedf40e0105f44db0af20887e81b77a0a87690 Mon Sep 17 00:00:00 2001 From: x ronger Date: Sun, 8 Mar 2020 01:09:42 +0800 Subject: [PATCH 06/16] =?UTF-8?q?:sparkles:=20=E8=AF=84=E8=AE=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/service/impl/CommentServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java index dfe6232..1fcfdbf 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -90,7 +90,7 @@ public class CommentServiceImpl extends AbstractService implements Comm String commentPreviewContent = commentContent.substring(0,length); commentContent = Html2TextUtil.getContent(commentPreviewContent); // 评论者不是作者本人则进行消息通知 - if (article.getArticleAuthorId().equals(comment.getCommentAuthorId())) { + if (!article.getArticleAuthorId().equals(comment.getCommentAuthorId())) { NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); } // 判断是否是回复消息 From b73dbb727ebf3f0b464b754209ede1647c1c2a1c Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 11 Mar 2020 08:56:21 +0800 Subject: [PATCH 07/16] =?UTF-8?q?:sparkles:=20=E6=9B=B4=E6=96=B0=E7=99=BE?= =?UTF-8?q?=E5=BA=A6SEO=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/util/BaiDuUtils.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java b/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java index 5e83cd0..83e015f 100644 --- a/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java +++ b/src/main/java/com/rymcu/vertical/util/BaiDuUtils.java @@ -33,6 +33,29 @@ public class BaiDuUtils { } return 0; },executor); + return; + } + + public static void sendUpdateSEOData(String permalink) { + if (StringUtils.isBlank(permalink) || StringUtils.isBlank(token)) { + return; + } + ExecutorService executor= new ThreadPoolExecutor(1,1,0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + CompletableFuture.supplyAsync(()-> { + try { + HttpResponse response = HttpRequest.post("http://data.zz.baidu.com/update?site=" + site + "&token=" + token). + header("User-Agent", "curl/7.12.1"). + header("Host", "data.zz.baidu.com"). + header("Content-Type", "text/plain"). + header("Connection", "close").body(permalink.getBytes(), "text/plain").timeout(30000).send(); + response.charset("UTF-8"); + System.out.println(response.bodyText()); + } catch (Exception e){ + e.printStackTrace(); + } + return 0; + },executor); + return; } public static void updateSEOData(String permalink) { @@ -77,7 +100,7 @@ public class BaiDuUtils { },executor); } - public static void main(String agrs[]){ - sendSEOData("https://rymcu.com/article/31"); + public static void main(){ + sendUpdateSEOData("https://rymcu.com"); } } From 1d68044df517b4d7097b3f3671f5a4dad544bf8d Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 11 Mar 2020 09:44:39 +0800 Subject: [PATCH 08/16] =?UTF-8?q?:bug:=20=E6=98=AF=E5=90=A6=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E8=AF=84=E8=AE=BA=E5=88=A4=E6=96=AD=20bug=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/service/impl/CommentServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java index 1fcfdbf..b9b3c88 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -14,6 +14,7 @@ import com.rymcu.vertical.util.NotificationUtils; import com.rymcu.vertical.util.Utils; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -52,6 +53,7 @@ public class CommentServiceImpl extends AbstractService implements Comm } @Override + @Transactional(rollbackFor = Exception.class) public Map postComment(Comment comment, HttpServletRequest request) { Map map = new HashMap(1); if(comment.getCommentArticleId() == null){ @@ -94,7 +96,7 @@ public class CommentServiceImpl extends AbstractService implements Comm NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); } // 判断是否是回复消息 - if (comment.getCommentOriginalCommentId() != null) { + if (comment.getCommentOriginalCommentId() != null && comment.getCommentOriginalCommentId() != 0) { Comment originalComment = commentMapper.selectByPrimaryKey(comment.getCommentOriginalCommentId()); // 回复消息时,评论者不是上级评论作者则进行消息通知 if (!comment.getCommentAuthorId().equals(originalComment.getCommentAuthorId())) { From 87918431a998990bd94945a958e67ac4258d3cf1 Mon Sep 17 00:00:00 2001 From: ronger Date: Thu, 12 Mar 2020 11:47:18 +0800 Subject: [PATCH 09/16] =?UTF-8?q?:fire:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E6=95=88=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/rymcu/vertical/dto/CommentDTO.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/rymcu/vertical/dto/CommentDTO.java b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java index 64b77ee..a3d2563 100644 --- a/src/main/java/com/rymcu/vertical/dto/CommentDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java @@ -2,7 +2,6 @@ package com.rymcu.vertical.dto; import lombok.Data; -import javax.persistence.Column; import java.util.Date; /** From 6d13d5e6aff763d4f838a64830111754e03088b2 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 13 Mar 2020 10:38:21 +0800 Subject: [PATCH 10/16] =?UTF-8?q?:bug:=20=E8=A7=92=E8=89=B2=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8A=9F=E8=83=BD=E6=97=A0=E6=B3=95=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/mapper/RoleMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mapper/RoleMapper.xml b/src/main/java/mapper/RoleMapper.xml index 7967a39..95b5c0f 100644 --- a/src/main/java/mapper/RoleMapper.xml +++ b/src/main/java/mapper/RoleMapper.xml @@ -17,7 +17,7 @@ update vertical_role set status = #{status},updated_time = sysdate() where id = #{idRole} - update vertical_role set name = #{name}, input_code = ${inputCode}, weights = #{weights}, updated_time = sysdate() where id = #{idRole} + update vertical_role set name = #{name}, input_code = #{inputCode}, weights = #{weights}, updated_time = sysdate() where id = #{idRole} - select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id order by updated_time desc + select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where article_status = '0' order by updated_time desc select vt.id, vt.tag_title, vt.tag_icon_path, vt.tag_uri, vt.tag_description from vertical_tag vt left join vertical_tag_article vta on vt.id = vta.id_tag where vta.id_article = #{idArticle} + \ No newline at end of file From c2b576a8119e1e480487fb17534c4bf5183eb05a Mon Sep 17 00:00:00 2001 From: x ronger Date: Fri, 13 Mar 2020 23:47:14 +0800 Subject: [PATCH 12/16] =?UTF-8?q?:sparkles:=20=E6=88=91=E7=9A=84=E8=8D=89?= =?UTF-8?q?=E7=A8=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/constant/ProjectConstant.java | 29 ++++++++++++------- .../java/com/rymcu/vertical/dto/Author.java | 3 ++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/core/constant/ProjectConstant.java b/src/main/java/com/rymcu/vertical/core/constant/ProjectConstant.java index 96eb072..db5d098 100644 --- a/src/main/java/com/rymcu/vertical/core/constant/ProjectConstant.java +++ b/src/main/java/com/rymcu/vertical/core/constant/ProjectConstant.java @@ -2,16 +2,25 @@ package com.rymcu.vertical.core.constant; /** * 项目常量 + * @author ronger */ public final class ProjectConstant { - public static final String BASE_PACKAGE = "com.rymcu.vertical";//项目基础包名称,根据自己公司的项目修改 - - public static final String DTO_PACKAGE = BASE_PACKAGE + ".dto";//DTO所在包 - public static final String MODEL_PACKAGE = BASE_PACKAGE + ".entity";//Model所在包 - public static final String MAPPER_PACKAGE = BASE_PACKAGE + ".mapper";//Mapper所在包 - public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".service";//Service所在包 - public static final String SERVICE_IMPL_PACKAGE = SERVICE_PACKAGE + ".impl";//ServiceImpl所在包 - public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".web";//Controller所在包 - - public static final String MAPPER_INTERFACE_REFERENCE = BASE_PACKAGE + ".core.mapper.Mapper";//Mapper插件基础接口的完全限定名 + /**当前环境*/ + public static final String ENV = "dev"; + /**项目基础包名称,根据自己公司的项目修改*/ + public static final String BASE_PACKAGE = "com.rymcu.vertical"; + /**DTO所在包*/ + public static final String DTO_PACKAGE = BASE_PACKAGE + ".dto"; + /**Model所在包*/ + public static final String MODEL_PACKAGE = BASE_PACKAGE + ".entity"; + /**Mapper所在包*/ + public static final String MAPPER_PACKAGE = BASE_PACKAGE + ".mapper"; + /**Service所在包*/ + public static final String SERVICE_PACKAGE = BASE_PACKAGE + ".service"; + /**ServiceImpl所在包*/ + public static final String SERVICE_IMPL_PACKAGE = SERVICE_PACKAGE + ".impl"; + /**Controller所在包*/ + public static final String CONTROLLER_PACKAGE = BASE_PACKAGE + ".web"; + /**Mapper插件基础接口的完全限定名*/ + public static final String MAPPER_INTERFACE_REFERENCE = BASE_PACKAGE + ".core.mapper.Mapper"; } diff --git a/src/main/java/com/rymcu/vertical/dto/Author.java b/src/main/java/com/rymcu/vertical/dto/Author.java index 49105d7..1f6a567 100644 --- a/src/main/java/com/rymcu/vertical/dto/Author.java +++ b/src/main/java/com/rymcu/vertical/dto/Author.java @@ -2,6 +2,9 @@ package com.rymcu.vertical.dto; import lombok.Data; +/** + * @author ronger + */ @Data public class Author { From ee1de2f785857aaf6912e78b25cf18eea7165b2c Mon Sep 17 00:00:00 2001 From: x ronger Date: Sat, 14 Mar 2020 17:21:05 +0800 Subject: [PATCH 13/16] =?UTF-8?q?:bug:=20=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=9C=AA=E4=BD=BF=E7=94=A8=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/dto/ArticleTagDTO.java | 5 +++++ .../rymcu/vertical/mapper/ArticleMapper.java | 7 +++++++ .../vertical/service/impl/TagServiceImpl.java | 10 +++++++++- src/main/java/mapper/ArticleMapper.xml | 17 +++++++++++------ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java b/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java index 7eb15f7..ed69468 100644 --- a/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java @@ -7,8 +7,13 @@ import lombok.Data; */ @Data public class ArticleTagDTO { + + private Integer idArticleTag; + private Integer idTag; + private Integer idArticle; + private String tagTitle; private String tagUri; diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 05bc666..d7408b6 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -111,4 +111,11 @@ public interface ArticleMapper extends Mapper
{ * @return */ List selectDrafts(@Param("idUser") Integer idUser); + + /** + * 删除未使用的文章标签 + * @param idArticleTag + * @return + */ + Integer deleteUnusedArticleTag(@Param("idArticleTag") Integer idArticleTag); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java index 256e56a..1b658cb 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java @@ -41,13 +41,13 @@ public class TagServiceImpl extends AbstractService implements TagService { String articleTags = article.getArticleTags(); if(StringUtils.isNotBlank(articleTags)){ String[] tags = articleTags.split(","); + List articleTagDTOList = articleMapper.selectTags(article.getIdArticle()); for (int i = 0; i < tags.length; i++) { boolean addTagArticle = false; boolean addUserTag = false; Tag tag = new Tag(); tag.setTagTitle(tags[i]); tag = tagMapper.selectOne(tag); - List articleTagDTOList = articleMapper.selectTags(article.getIdArticle()); if(tag == null){ tag = new Tag(); tag.setTagTitle(tags[i]); @@ -59,6 +59,11 @@ public class TagServiceImpl extends AbstractService implements TagService { addTagArticle = true; addUserTag = true; } else { + for(ArticleTagDTO articleTag : articleTagDTOList) { + if (articleTag.getIdTag().equals(tag.getIdTag())) { + articleTagDTOList.remove(articleTag); + } + } Integer count = tagMapper.selectCountTagArticleById(tag.getIdTag(),article.getIdArticle()); if(count == 0){ tag.setTagArticleCount(tag.getTagArticleCount() + 1); @@ -70,6 +75,9 @@ public class TagServiceImpl extends AbstractService implements TagService { addUserTag = true; } } + articleTagDTOList.forEach(articleTagDTO -> { + articleMapper.deleteUnusedArticleTag(articleTagDTO.getIdArticleTag()); + }); if(addTagArticle){ tagMapper.insertTagArticle(tag.getIdTag(),article.getIdArticle()); } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 49335d9..d2426a5 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -51,11 +51,13 @@ - - - - - + + + + + + + insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time) @@ -70,6 +72,9 @@ delete from vertical_tag_article where id_article = #{id} + + delete from vertical_tag_article where id = #{idArticleTag} + @@ -95,7 +100,7 @@ select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on su.id = #{idUser} and art.article_author_id = su.id where article_author_id = #{idUser} order by updated_time desc