🎨 代码结构优化
This commit is contained in:
parent
23bf6780df
commit
e1aa873e33
@ -146,14 +146,6 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
}
|
||||
newArticle.setArticleTitle(articleTitle);
|
||||
newArticle.setArticleTags(articleTags);
|
||||
if(StringUtils.isNotBlank(articleContentHtml)){
|
||||
Integer length = articleContentHtml.length();
|
||||
if(length > MAX_PREVIEW){
|
||||
length = 200;
|
||||
}
|
||||
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);
|
||||
@ -175,6 +167,15 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
newArticle.setArticlePermalink(domain + "/draft/" + newArticle.getIdArticle());
|
||||
newArticle.setArticleLink("/draft/" + newArticle.getIdArticle());
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(articleContentHtml)){
|
||||
Integer length = articleContentHtml.length();
|
||||
if(length > MAX_PREVIEW){
|
||||
length = MAX_PREVIEW;
|
||||
}
|
||||
String articlePreviewContent = articleContentHtml.substring(0,length);
|
||||
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
||||
}
|
||||
articleMapper.updateByPrimaryKeySelective(newArticle);
|
||||
|
||||
map.put("id", newArticle.getIdArticle());
|
||||
@ -279,31 +280,36 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
}
|
||||
|
||||
private ArticleDTO genArticle(ArticleDTO article, Integer type) {
|
||||
Author author = userService.selectAuthor(article.getArticleAuthorId());
|
||||
Integer ARTICLE_LIST = 0;
|
||||
Integer ARTICLE_VIEW = 1;
|
||||
Integer ARTICLE_EDIT = 2;
|
||||
Author author = genAuthor(article);
|
||||
article.setArticleAuthor(author);
|
||||
article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime()));
|
||||
List<ArticleTagDTO> tags = articleMapper.selectTags(article.getIdArticle());
|
||||
article.setTags(tags);
|
||||
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
|
||||
if (type.equals(1) || type.equals(0)){
|
||||
article.setArticleContent(articleContent.getArticleContentHtml());
|
||||
} else if (type.equals(2)) {
|
||||
article.setArticleContent(articleContent.getArticleContent());
|
||||
}
|
||||
|
||||
if(StringUtils.isBlank(article.getArticlePreviewContent())){
|
||||
Integer length = articleContent.getArticleContentHtml().length();
|
||||
if(length > MAX_PREVIEW){
|
||||
length = 200;
|
||||
if (!type.equals(ARTICLE_LIST)) {
|
||||
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
|
||||
if (type.equals(ARTICLE_VIEW)){
|
||||
article.setArticleContent(articleContent.getArticleContentHtml());
|
||||
// 获取评论列表数据
|
||||
List<CommentDTO> commentDTOList = commentService.getArticleComments(article.getIdArticle());
|
||||
article.setArticleComments(commentDTOList);
|
||||
// 获取所属作品集列表数据
|
||||
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
||||
article.setPortfolios(portfolioArticleDTOList);
|
||||
} else if (type.equals(ARTICLE_EDIT)) {
|
||||
article.setArticleContent(articleContent.getArticleContent());
|
||||
}
|
||||
String articlePreviewContent = articleContent.getArticleContentHtml().substring(0,length);
|
||||
article.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
||||
}
|
||||
List<CommentDTO> commentDTOList = commentService.getArticleComments(article.getIdArticle());
|
||||
article.setArticleComments(commentDTOList);
|
||||
|
||||
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
||||
article.setPortfolios(portfolioArticleDTOList);
|
||||
return article;
|
||||
}
|
||||
|
||||
private Author genAuthor(ArticleDTO article) {
|
||||
Author author = new Author();
|
||||
author.setUserNickname(article.getArticleAuthorName());
|
||||
author.setUserAvatarURL(article.getArticleAuthorAvatarUrl());
|
||||
author.setIdUser(article.getArticleAuthorId());
|
||||
return author;
|
||||
}
|
||||
}
|
||||
|
@ -78,10 +78,10 @@
|
||||
delete from vertical_tag_article where id = #{idArticleTag}
|
||||
</delete>
|
||||
<select id="selectArticles" 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 article_status = '0' order by updated_time desc
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on art.article_author_id = su.id where article_status = '0' order by updated_time desc
|
||||
</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}
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art 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>
|
||||
@ -90,30 +90,30 @@
|
||||
select article_content,article_content_html from vertical_article_content where id_article = #{idArticle}
|
||||
</select>
|
||||
<select id="selectArticlesByTopicUri" 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
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on art.article_author_id = su.id
|
||||
where exists(select * from vertical_tag_article vta where vta.id_article = art.id and exists(select * from vertical_topic_tag vtt
|
||||
left join vertical_tag vt on vtt.id_tag = vt.id where vt.id = vta.id_tag and exists(select * from vertical_topic topic
|
||||
join vertical_tag vt on vtt.id_tag = vt.id where vt.id = vta.id_tag and exists(select * from vertical_topic topic
|
||||
where topic.id = vtt.id_topic and topic.topic_uri = #{topicName}))) order by updated_time desc
|
||||
</select>
|
||||
<select id="selectArticlesByTagName" 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 order by updated_time desc
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on art.article_author_id = su.id order by updated_time desc
|
||||
</select>
|
||||
<select id="selectUserArticles" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on su.id = #{idUser}
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on su.id = #{idUser}
|
||||
and art.article_author_id = su.id where article_author_id = #{idUser} and art.article_status = 0 order by updated_time desc
|
||||
</select>
|
||||
<select id="selectTags" resultMap="ArticleTagDTOResultMap">
|
||||
select vta.id, vta.id_tag, vta.id_article, 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}
|
||||
select vta.id, vta.id_tag, vta.id_article, vt.tag_title, vt.tag_icon_path, vt.tag_uri, vt.tag_description from vertical_tag vt join vertical_tag_article vta on vt.id = vta.id_tag where vta.id_article = #{idArticle}
|
||||
</select>
|
||||
<select id="selectDrafts" 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 article_status = '1' and art.article_author_id = #{idUser} order by updated_time desc
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on art.article_author_id = su.id where article_status = '1' and art.article_author_id = #{idUser} order by updated_time desc
|
||||
</select>
|
||||
<select id="selectArticlesByIdPortfolio" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url,vpa.sort_no from vertical_article art join vertical_portfolio_article vpa on vpa.id_vertical_article = art.id and vpa.id_vertical_portfolio = #{idPortfolio}
|
||||
left join vertical_user su on art.article_author_id = su.id where art.article_status = 0 and vpa.id_vertical_portfolio = #{idPortfolio} order by sort_no
|
||||
join vertical_user su on art.article_author_id = su.id where art.article_status = 0 and vpa.id_vertical_portfolio = #{idPortfolio} order by sort_no
|
||||
</select>
|
||||
<select id="selectUnbindArticlesByIdPortfolio" resultMap="DTOResultMap">
|
||||
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 art.article_author_id = #{idUser} and art.article_status = 0
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on su.id = #{idUser} and art.article_author_id = su.id where art.article_author_id = #{idUser} and art.article_status = 0
|
||||
and instr(art.article_title, #{searchText}) > 0 and art.id not in (select id_vertical_article from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio}) order by updated_time desc
|
||||
</select>
|
||||
<select id="selectPortfolioArticles" resultMap="PortfolioArticleResultMap">
|
||||
|
Loading…
Reference in New Issue
Block a user