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/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/ArticleDTO.java b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java index ce315ea..60aa8c2 100644 --- a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java @@ -41,10 +41,14 @@ public class ArticleDTO { private String articlePermalink; /** 站内链接 */ private String articleLink; + /** 文章状态 */ + private String articleStatus; /** 更新时间 */ private Date updatedTime; private Author articleAuthor; private List tags; + + private List articleComments; } 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/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 { 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..a3d2563 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/CommentDTO.java @@ -0,0 +1,41 @@ +package com.rymcu.vertical.dto; + +import lombok.Data; + +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 commentOriginalAuthorNickname; + /** 状态 */ + 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/Article.java b/src/main/java/com/rymcu/vertical/entity/Article.java index e389d2c..6aefb49 100644 --- a/src/main/java/com/rymcu/vertical/entity/Article.java +++ b/src/main/java/com/rymcu/vertical/entity/Article.java @@ -46,4 +46,6 @@ public class Article implements Serializable,Cloneable { private Date createdTime; /** 更新时间 */ private Date updatedTime; + /** 文章状态 */ + private String articleStatus; } 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/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 71b036c..959525f 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -10,34 +10,113 @@ import org.apache.ibatis.annotations.Param; import java.util.List; +/** + * @author ronger + */ public interface ArticleMapper extends Mapper
{ + + /** + * 获取文章列表 + * @param searchText + * @param tag + * @return + */ List selectArticles(@Param("searchText") String searchText, @Param("tag") String tag); + /** + * 根据用户 ID 获取作者信息 + * @param id + * @return + */ Author selectAuthor(@Param("id") Integer id); - ArticleDTO selectArticleDTOById(@Param("id") Integer id); + /** + * 根据文章 ID 查询文章 + * @param id + * @param type + * @return + */ + ArticleDTO selectArticleDTOById(@Param("id") Integer id, @Param("type") int type); + /** + * 保存文章内容 + * @param idArticle + * @param articleContent + * @param articleContentHtml + * @return + */ Integer insertArticleContent(@Param("idArticle") Integer idArticle, @Param("articleContent") String articleContent, @Param("articleContentHtml") String articleContentHtml); + /** + * 更新文章内容 + * @param idArticle + * @param articleContent + * @param articleContentHtml + * @return + */ Integer updateArticleContent(@Param("idArticle") Integer idArticle, @Param("articleContent") String articleContent, @Param("articleContentHtml") String articleContentHtml); + /** + * 获取文章正文内容 + * @param idArticle + * @return + */ ArticleContent selectArticleContent(@Param("idArticle") Integer idArticle); + /** + * 获取主题下文章列表 + * @param topicName + * @return + */ List selectArticlesByTopicUri(@Param("topicName") String topicName); + /** + * 获取标签下文章列表 + * @param tagName + * @return + */ List selectArticlesByTagName(@Param("tagName") String tagName); + /** + * 获取用户文章列表 + * @param idUser + * @return + */ List selectUserArticles(@Param("idUser") Integer idUser); + /** + * 删除文章标签 + * @param id + * @return + */ Integer deleteTagArticle(@Param("id") Integer id); + /** + * 获取文章标签列表 + * @param idArticle + * @return + */ List selectTags(@Param("idArticle") Integer idArticle); /** - * + * 更新文章浏览数 * @param id * @param articleViewCount * @return */ Integer updateArticleViewCount(@Param("id") Integer id, @Param("articleViewCount") Integer articleViewCount); + + /** + * 获取草稿列表 + * @param idUser + * @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/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/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index a901362..541bf57 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -74,4 +74,17 @@ public interface ArticleService extends Service
{ * @param id */ void incrementArticleViewCount(Integer id); + + /** + * 获取分享链接数据 + * @param id + * @return + */ + Map share(Integer id) throws BaseApiException; + + /** + * 查询草稿文章类别 + * @return + */ + List findDrafts() throws BaseApiException; } 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..f451556 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -1,16 +1,19 @@ package com.rymcu.vertical.service.impl; import com.rymcu.vertical.core.constant.NotificationConstant; +import com.rymcu.vertical.core.constant.ProjectConstant; 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,11 +45,16 @@ 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; + private static final String defaultStatus = "0"; @Override public List findArticles(String searchText, String tag) { @@ -59,7 +67,10 @@ public class ArticleServiceImpl extends AbstractService
implements Arti @Override public ArticleDTO findArticleDTOById(Integer id, int type) { - ArticleDTO articleDTO = articleMapper.selectArticleDTOById(id); + ArticleDTO articleDTO = articleMapper.selectArticleDTOById(id,type); + if (articleDTO == null) { + return null; + } articleDTO = genArticle(articleDTO,type); return articleDTO; } @@ -121,11 +132,12 @@ public class ArticleServiceImpl extends AbstractService
implements Arti newArticle.setArticleTags(articleTags); newArticle.setCreatedTime(new Date()); newArticle.setUpdatedTime(newArticle.getCreatedTime()); + newArticle.setArticleStatus(article.getArticleStatus()); articleMapper.insertSelective(newArticle); - newArticle.setArticlePermalink(domain + "/article/"+newArticle.getIdArticle()); - newArticle.setArticleLink("/article/"+newArticle.getIdArticle()); articleMapper.insertArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml); - BaiDuUtils.sendSEOData(newArticle.getArticlePermalink()); + if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) { + BaiDuUtils.sendSEOData(newArticle.getArticlePermalink()); + } } else { newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle()); if(!user.getIdUser().equals(newArticle.getArticleAuthorId())){ @@ -142,16 +154,27 @@ public class ArticleServiceImpl extends AbstractService
implements Arti String articlePreviewContent = articleContentHtml.substring(0,length); newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent)); } + newArticle.setArticleStatus(article.getArticleStatus()); newArticle.setUpdatedTime(new Date()); articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml); - BaiDuUtils.updateSEOData(newArticle.getArticlePermalink()); + if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) { + BaiDuUtils.updateSEOData(newArticle.getArticlePermalink()); + } } - if (notification) { + if (notification && defaultStatus.equals(newArticle.getArticleStatus())) { NotificationUtils.sendAnnouncement(newArticle.getIdArticle(), NotificationConstant.Article, newArticle.getArticleTitle()); } tagService.saveTagArticle(newArticle); + + if (defaultStatus.equals(newArticle.getArticleStatus())) { + newArticle.setArticlePermalink(domain + "/article/" + newArticle.getIdArticle()); + newArticle.setArticleLink("/article/" + newArticle.getIdArticle()); + } else { + newArticle.setArticlePermalink(domain + "/draft/" + newArticle.getIdArticle()); + newArticle.setArticleLink("/draft/" + newArticle.getIdArticle()); + } articleMapper.updateByPrimaryKeySelective(newArticle); map.put("id", newArticle.getIdArticle()); @@ -216,6 +239,27 @@ public class ArticleServiceImpl extends AbstractService
implements Arti articleMapper.updateArticleViewCount(article.getIdArticle(), articleViewCount); } + @Override + public Map share(Integer id) throws BaseApiException { + Article article = articleMapper.selectByPrimaryKey(id); + User user = UserUtils.getWxCurrentUser(); + StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink()); + shareUrl.append("?s=").append(user.getNickname()); + Map map = new HashMap(1); + map.put("shareUrl", shareUrl); + return map; + } + + @Override + public List findDrafts() throws BaseApiException { + User user = UserUtils.getWxCurrentUser(); + List list = articleMapper.selectDrafts(user.getIdUser()); + list.forEach(article->{ + genArticle(article,0); + }); + return list; + } + private ArticleDTO genArticle(ArticleDTO article,Integer type) { Author author = articleMapper.selectAuthor(article.getArticleAuthorId()); article.setArticleAuthor(author); @@ -239,6 +283,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..f7268e1 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/impl/CommentServiceImpl.java @@ -0,0 +1,114 @@ +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 org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.*; + +/** + * @author ronger + */ +@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()); + commentDTO.setCommentOriginalAuthorNickname(commentOriginalAuthor.getUserNickname()); + } + } + }); + return commentDTOList; + } + + @Override + @Transactional(rollbackFor = Exception.class) + 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); + // 评论者不是作者本人则进行消息通知 + if (!article.getArticleAuthorId().equals(comment.getCommentAuthorId())) { + NotificationUtils.saveNotification(article.getArticleAuthorId(),comment.getIdComment(), NotificationConstant.Comment, commentContent); + } + // 判断是否是回复消息 + if (comment.getCommentOriginalCommentId() != null && comment.getCommentOriginalCommentId() != 0) { + Comment originalComment = commentMapper.selectByPrimaryKey(comment.getCommentOriginalCommentId()); + // 回复消息时,评论者不是上级评论作者则进行消息通知 + if (!comment.getCommentAuthorId().equals(originalComment.getCommentAuthorId())) { + NotificationUtils.saveNotification(originalComment.getCommentAuthorId(),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..d58eed3 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 }) @@ -37,6 +41,7 @@ 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; @@ -54,6 +59,12 @@ public class TagServiceImpl extends AbstractService implements TagService { addTagArticle = true; addUserTag = true; } else { + for(int m=0,n=articleTagDTOList.size()-1;m 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/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"); } } 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..8fa3f41 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 @@ -1,9 +1,14 @@ package com.rymcu.vertical.web.api.article; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; 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.util.Utils; import com.rymcu.vertical.web.api.exception.BaseApiException; import org.springframework.web.bind.annotation.*; @@ -11,6 +16,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 +28,8 @@ public class ArticleController { @Resource private ArticleService articleService; + @Resource + private CommentService commentService; @@ -51,4 +59,27 @@ 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); + } + + @GetMapping("/drafts") + public GlobalResult drafts(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException { + PageHelper.startPage(page, rows); + List list = articleService.findDrafts(); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getArticlesGlobalResult(pageInfo); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/{id}/share") + public GlobalResult share(@PathVariable Integer id) throws BaseApiException { + Map map = articleService.share(id); + 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); + } +} diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 65d0423..e315b78 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -35,6 +35,7 @@ + @@ -50,11 +51,13 @@ - - - - - + + + + + + + insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time) @@ -69,14 +72,20 @@ delete from vertical_tag_article where id_article = #{id} + + delete from vertical_tag_article where id = #{idArticleTag} + + \ No newline at end of file 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 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}