🎨 代码结构优化

This commit is contained in:
ronger 2020-05-06 19:03:30 +08:00
parent 23bf6780df
commit e1aa873e33
2 changed files with 43 additions and 37 deletions

View File

@ -146,14 +146,6 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
} }
newArticle.setArticleTitle(articleTitle); newArticle.setArticleTitle(articleTitle);
newArticle.setArticleTags(articleTags); 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.setArticleStatus(article.getArticleStatus());
newArticle.setUpdatedTime(new Date()); newArticle.setUpdatedTime(new Date());
articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml); 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.setArticlePermalink(domain + "/draft/" + newArticle.getIdArticle());
newArticle.setArticleLink("/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); articleMapper.updateByPrimaryKeySelective(newArticle);
map.put("id", newArticle.getIdArticle()); map.put("id", newArticle.getIdArticle());
@ -279,31 +280,36 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
} }
private ArticleDTO genArticle(ArticleDTO article, Integer type) { 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.setArticleAuthor(author);
article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime())); article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime()));
List<ArticleTagDTO> tags = articleMapper.selectTags(article.getIdArticle()); List<ArticleTagDTO> tags = articleMapper.selectTags(article.getIdArticle());
article.setTags(tags); article.setTags(tags);
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle()); if (!type.equals(ARTICLE_LIST)) {
if (type.equals(1) || type.equals(0)){ ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
article.setArticleContent(articleContent.getArticleContentHtml()); if (type.equals(ARTICLE_VIEW)){
} else if (type.equals(2)) { article.setArticleContent(articleContent.getArticleContentHtml());
article.setArticleContent(articleContent.getArticleContent()); // 获取评论列表数据
} List<CommentDTO> commentDTOList = commentService.getArticleComments(article.getIdArticle());
article.setArticleComments(commentDTOList);
if(StringUtils.isBlank(article.getArticlePreviewContent())){ // 获取所属作品集列表数据
Integer length = articleContent.getArticleContentHtml().length(); List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
if(length > MAX_PREVIEW){ article.setPortfolios(portfolioArticleDTOList);
length = 200; } 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; 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;
}
} }

View File

@ -78,10 +78,10 @@
delete from vertical_tag_article where id = #{idArticleTag} delete from vertical_tag_article where id = #{idArticleTag}
</delete> </delete>
<select id="selectArticles" resultMap="DTOResultMap"> <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>
<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 join vertical_user su on art.article_author_id = su.id where art.id = #{id}
<if test="type == 1"> <if test="type == 1">
and art.article_status = 0 and art.article_status = 0
</if> </if>
@ -90,30 +90,30 @@
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}
</select> </select>
<select id="selectArticlesByTopicUri" resultMap="DTOResultMap"> <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 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 where topic.id = vtt.id_topic and topic.topic_uri = #{topicName}))) order by updated_time desc
</select> </select>
<select id="selectArticlesByTagName" resultMap="DTOResultMap"> <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>
<select id="selectUserArticles" resultMap="DTOResultMap"> <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 and art.article_author_id = su.id where article_author_id = #{idUser} and art.article_status = 0 order by updated_time desc
</select> </select>
<select id="selectTags" resultMap="ArticleTagDTOResultMap"> <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>
<select id="selectDrafts" resultMap="DTOResultMap"> <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>
<select id="selectArticlesByIdPortfolio" resultMap="DTOResultMap"> <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} 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>
<select id="selectUnbindArticlesByIdPortfolio" resultMap="DTOResultMap"> <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 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>
<select id="selectPortfolioArticles" resultMap="PortfolioArticleResultMap"> <select id="selectPortfolioArticles" resultMap="PortfolioArticleResultMap">