我的草稿

This commit is contained in:
x ronger 2020-03-15 19:21:44 +08:00
parent 9d81a82bf1
commit b3c82d2bdd
5 changed files with 47 additions and 7 deletions

View File

@ -33,9 +33,10 @@ public interface ArticleMapper extends Mapper<Article> {
/**
* 根据文章 ID 查询文章
* @param id
* @param type
* @return
*/
ArticleDTO selectArticleDTOById(@Param("id") Integer id);
ArticleDTO selectArticleDTOById(@Param("id") Integer id, @Param("type") int type);
/**
* 保存文章内容

View File

@ -75,6 +75,13 @@ public interface ArticleService extends Service<Article> {
*/
void incrementArticleViewCount(Integer id);
/**
* 获取分享链接数据
* @param id
* @return
*/
Map share(Integer id) throws BaseApiException;
/**
* 查询草稿文章类别
* @return

View File

@ -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<Article> implements Arti
private String env;
private static final int MAX_PREVIEW = 200;
private static final String defaultStatus = "0";
@Override
public List<ArticleDTO> findArticles(String searchText, String tag) {
@ -65,7 +67,10 @@ public class ArticleServiceImpl extends AbstractService<Article> 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<Article> 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<Article> 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<Article> 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<ArticleDTO> findDrafts() throws BaseApiException {
User user = UserUtils.getWxCurrentUser();

View File

@ -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);
}
}

View File

@ -83,6 +83,9 @@
</select>
<select id="selectArticleDTOById" resultMap="DTOResultMap">
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where art.id = #{id}
<if test="type == 1">
and art.article_status = 0
</if>
</select>
<select id="selectArticleContent" resultMap="ArticleContentResultMap">
select article_content,article_content_html from vertical_article_content where id_article = #{idArticle}