✨ 我的草稿
This commit is contained in:
parent
9d81a82bf1
commit
b3c82d2bdd
@ -33,9 +33,10 @@ public interface ArticleMapper extends Mapper<Article> {
|
|||||||
/**
|
/**
|
||||||
* 根据文章 ID 查询文章
|
* 根据文章 ID 查询文章
|
||||||
* @param id
|
* @param id
|
||||||
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ArticleDTO selectArticleDTOById(@Param("id") Integer id);
|
ArticleDTO selectArticleDTOById(@Param("id") Integer id, @Param("type") int type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存文章内容
|
* 保存文章内容
|
||||||
|
@ -75,6 +75,13 @@ public interface ArticleService extends Service<Article> {
|
|||||||
*/
|
*/
|
||||||
void incrementArticleViewCount(Integer id);
|
void incrementArticleViewCount(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分享链接数据
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map share(Integer id) throws BaseApiException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询草稿文章类别
|
* 查询草稿文章类别
|
||||||
* @return
|
* @return
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.rymcu.vertical.service.impl;
|
package com.rymcu.vertical.service.impl;
|
||||||
|
|
||||||
import com.rymcu.vertical.core.constant.NotificationConstant;
|
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.core.service.AbstractService;
|
||||||
import com.rymcu.vertical.dto.ArticleDTO;
|
import com.rymcu.vertical.dto.ArticleDTO;
|
||||||
import com.rymcu.vertical.dto.ArticleTagDTO;
|
import com.rymcu.vertical.dto.ArticleTagDTO;
|
||||||
@ -53,6 +54,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
private String env;
|
private String env;
|
||||||
|
|
||||||
private static final int MAX_PREVIEW = 200;
|
private static final int MAX_PREVIEW = 200;
|
||||||
|
private static final String defaultStatus = "0";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArticleDTO> findArticles(String searchText, String tag) {
|
public List<ArticleDTO> findArticles(String searchText, String tag) {
|
||||||
@ -65,7 +67,10 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArticleDTO findArticleDTOById(Integer id, int type) {
|
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);
|
articleDTO = genArticle(articleDTO,type);
|
||||||
return articleDTO;
|
return articleDTO;
|
||||||
}
|
}
|
||||||
@ -129,10 +134,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
newArticle.setUpdatedTime(newArticle.getCreatedTime());
|
newArticle.setUpdatedTime(newArticle.getCreatedTime());
|
||||||
newArticle.setArticleStatus(article.getArticleStatus());
|
newArticle.setArticleStatus(article.getArticleStatus());
|
||||||
articleMapper.insertSelective(newArticle);
|
articleMapper.insertSelective(newArticle);
|
||||||
newArticle.setArticlePermalink(domain + "/article/"+newArticle.getIdArticle());
|
|
||||||
newArticle.setArticleLink("/article/"+newArticle.getIdArticle());
|
|
||||||
articleMapper.insertArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
articleMapper.insertArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
||||||
if (!"dev".equals(env)) {
|
if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) {
|
||||||
BaiDuUtils.sendSEOData(newArticle.getArticlePermalink());
|
BaiDuUtils.sendSEOData(newArticle.getArticlePermalink());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -151,18 +154,27 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
String articlePreviewContent = articleContentHtml.substring(0,length);
|
String articlePreviewContent = articleContentHtml.substring(0,length);
|
||||||
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
||||||
}
|
}
|
||||||
|
newArticle.setArticleStatus(article.getArticleStatus());
|
||||||
newArticle.setUpdatedTime(new Date());
|
newArticle.setUpdatedTime(new Date());
|
||||||
articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
||||||
if (!"dev".equals(env)) {
|
if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) {
|
||||||
BaiDuUtils.updateSEOData(newArticle.getArticlePermalink());
|
BaiDuUtils.updateSEOData(newArticle.getArticlePermalink());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification) {
|
if (notification && defaultStatus.equals(newArticle.getArticleStatus())) {
|
||||||
NotificationUtils.sendAnnouncement(newArticle.getIdArticle(), NotificationConstant.Article, newArticle.getArticleTitle());
|
NotificationUtils.sendAnnouncement(newArticle.getIdArticle(), NotificationConstant.Article, newArticle.getArticleTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
tagService.saveTagArticle(newArticle);
|
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);
|
articleMapper.updateByPrimaryKeySelective(newArticle);
|
||||||
|
|
||||||
map.put("id", newArticle.getIdArticle());
|
map.put("id", newArticle.getIdArticle());
|
||||||
@ -227,6 +239,17 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
articleMapper.updateArticleViewCount(article.getIdArticle(), articleViewCount);
|
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
|
@Override
|
||||||
public List<ArticleDTO> findDrafts() throws BaseApiException {
|
public List<ArticleDTO> findDrafts() throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getWxCurrentUser();
|
||||||
|
@ -76,4 +76,10 @@ public class ArticleController {
|
|||||||
return GlobalResultGenerator.genSuccessResult(map);
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/share")
|
||||||
|
public GlobalResult share(@PathVariable Integer id) throws BaseApiException {
|
||||||
|
Map map = articleService.share(id);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,9 @@
|
|||||||
</select>
|
</select>
|
||||||
<select id="selectArticleDTOById" resultMap="DTOResultMap">
|
<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}
|
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>
|
||||||
<select id="selectArticleContent" resultMap="ArticleContentResultMap">
|
<select id="selectArticleContent" resultMap="ArticleContentResultMap">
|
||||||
select article_content,article_content_html from vertical_article_content where id_article = #{idArticle}
|
select article_content,article_content_html from vertical_article_content where id_article = #{idArticle}
|
||||||
|
Loading…
Reference in New Issue
Block a user