diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index d7408b6..959525f 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -33,9 +33,10 @@ public interface ArticleMapper extends Mapper
{ /** * 根据文章 ID 查询文章 * @param id + * @param type * @return */ - ArticleDTO selectArticleDTOById(@Param("id") Integer id); + ArticleDTO selectArticleDTOById(@Param("id") Integer id, @Param("type") int type); /** * 保存文章内容 diff --git a/src/main/java/com/rymcu/vertical/service/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index 48ff943..541bf57 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -75,6 +75,13 @@ public interface ArticleService extends Service
{ */ void incrementArticleViewCount(Integer id); + /** + * 获取分享链接数据 + * @param id + * @return + */ + Map share(Integer id) throws BaseApiException; + /** * 查询草稿文章类别 * @return 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 4ca16f9..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,6 +1,7 @@ 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; @@ -53,6 +54,7 @@ public class ArticleServiceImpl extends AbstractService
implements Arti private String env; private static final int MAX_PREVIEW = 200; + private static final String defaultStatus = "0"; @Override public List findArticles(String searchText, String tag) { @@ -65,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; } @@ -129,10 +134,8 @@ public class ArticleServiceImpl extends AbstractService
implements Arti 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); - if (!"dev".equals(env)) { + if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) { BaiDuUtils.sendSEOData(newArticle.getArticlePermalink()); } } else { @@ -151,18 +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); - if (!"dev".equals(env)) { + 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()); @@ -227,6 +239,17 @@ 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(); 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 d3e6b91..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 @@ -76,4 +76,10 @@ public class ArticleController { 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/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index d2426a5..e315b78 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -83,6 +83,9 @@