专题模块功能重构

This commit is contained in:
x ronger 2020-08-01 00:43:58 +08:00
parent b7e0468007
commit 26d8674f34
6 changed files with 36 additions and 17 deletions

View File

@ -50,8 +50,6 @@ public class ArticleDTO {
private List<ArticleTagDTO> tags;
private List<CommentDTO> articleComments;
private List<PortfolioArticleDTO> portfolios;
private Integer sortNo;

View File

@ -0,0 +1,17 @@
package com.rymcu.vertical.dto;
import lombok.Data;
/**
* @author ronger
*/
@Data
public class ArticleSearchDTO {
private String searchText;
private String topicUri;
private String tag;
}

View File

@ -19,9 +19,10 @@ public interface ArticleMapper extends Mapper<Article> {
* 获取文章列表
* @param searchText
* @param tag
* @param topicUri
* @return
*/
List<ArticleDTO> selectArticles(@Param("searchText") String searchText, @Param("tag") String tag);
List<ArticleDTO> selectArticles(@Param("searchText") String searchText, @Param("tag") String tag, @Param("topicUri") String topicUri);
/**
* 根据文章 ID 查询文章

View File

@ -2,6 +2,7 @@ package com.rymcu.vertical.service;
import com.rymcu.vertical.core.service.Service;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.dto.ArticleSearchDTO;
import com.rymcu.vertical.entity.Article;
import com.rymcu.vertical.web.api.exception.BaseApiException;
@ -17,11 +18,10 @@ public interface ArticleService extends Service<Article> {
/**
* 根据检索内容/标签查询文章列表
* @param searchText
* @param tag
* @param searchDTO
* @return
* */
List<ArticleDTO> findArticles(String searchText, String tag);
List<ArticleDTO> findArticles(ArticleSearchDTO searchDTO);
/**
* 查询文章详情信息

View File

@ -52,10 +52,16 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
private static final int MAX_PREVIEW = 200;
private static final String defaultStatus = "0";
private static final String defaultTopicUri = "news";
@Override
public List<ArticleDTO> findArticles(String searchText, String tag) {
List<ArticleDTO> list = articleMapper.selectArticles(searchText, tag);
public List<ArticleDTO> findArticles(ArticleSearchDTO searchDTO) {
List<ArticleDTO> list;
if (StringUtils.isNotBlank(searchDTO.getTopicUri()) && !defaultTopicUri.equals(searchDTO.getTopicUri())) {
list = articleMapper.selectArticlesByTopicUri(searchDTO.getTopicUri());
} else {
list = articleMapper.selectArticles(searchDTO.getSearchText(), searchDTO.getTag(), searchDTO.getTopicUri());
}
list.forEach(article->{
genArticle(article,0);
});
@ -292,9 +298,6 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
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);

View File

@ -92,9 +92,9 @@ public class CommonApiController {
@GetMapping("/articles")
@VisitLogger
public GlobalResult<Map> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestParam(defaultValue = "") String searchText, @RequestParam(defaultValue = "") String tag){
public GlobalResult<Map> articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO searchDTO){
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticles(searchText,tag);
List<ArticleDTO> list = articleService.findArticles(searchDTO);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);