|
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.mszlu.blog.dao.mapper.ArticleMapper;
|
|
|
import com.mszlu.blog.dao.pojo.Article;
|
|
|
import com.mszlu.blog.service.ArticleService;
|
|
|
+import com.mszlu.blog.service.SysUserService;
|
|
|
+import com.mszlu.blog.service.TagService;
|
|
|
import com.mszlu.blog.vo.ArticleVo;
|
|
|
import com.mszlu.blog.vo.Result;
|
|
|
import com.mszlu.blog.vo.params.PageParams;
|
|
@@ -20,6 +22,10 @@ import java.util.List;
|
|
|
public class ArticleServiceImpl implements ArticleService {
|
|
|
@Autowired
|
|
|
private ArticleMapper articleMapper;
|
|
|
+ @Autowired
|
|
|
+ private TagService tagService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
@Override
|
|
|
public Result listArticle(PageParams pageParams) {
|
|
|
/**
|
|
@@ -33,22 +39,30 @@ public class ArticleServiceImpl implements ArticleService {
|
|
|
queryWrapper.orderByDesc(Article::getWeight,Article::getCreateDate);
|
|
|
Page<Article> articlePage = articleMapper.selectPage(page, queryWrapper);
|
|
|
List<Article> records = articlePage.getRecords();
|
|
|
- List<ArticleVo> articleVoList = copyList(records);
|
|
|
+ List<ArticleVo> articleVoList = copyList(records,true,true);
|
|
|
return Result.success(articleVoList);
|
|
|
}
|
|
|
|
|
|
- private List<ArticleVo> copyList(List<Article> records) {
|
|
|
+ private List<ArticleVo> copyList(List<Article> records,boolean isTag,boolean isAuthor) {
|
|
|
List<ArticleVo> articleVoList = new ArrayList<>();
|
|
|
for (Article record : records){
|
|
|
- articleVoList.add(copy(record));
|
|
|
+ articleVoList.add(copy(record,isTag,isAuthor));
|
|
|
}
|
|
|
- return null;
|
|
|
+ return articleVoList;
|
|
|
}
|
|
|
|
|
|
- private ArticleVo copy(Article article){
|
|
|
+ private ArticleVo copy(Article article,boolean isTag,boolean isAuthor){
|
|
|
ArticleVo articleVo = new ArticleVo();
|
|
|
BeanUtils.copyProperties(article,articleVo);
|
|
|
articleVo.setCreateDate(new DateTime(article.getCreateDate()).toString("yyyy-MM-dd HH:mm"));
|
|
|
+ if (isTag){
|
|
|
+ Long articleId = article.getId();
|
|
|
+ articleVo.setTags(tagService.findTagsByArticleId(articleId));
|
|
|
+ }
|
|
|
+ if (isAuthor){
|
|
|
+ Long authorId = article.getAuthorId();
|
|
|
+ articleVo.setAuthor(sysUserService.findUserById(authorId).getNickname());
|
|
|
+ }
|
|
|
return articleVo;
|
|
|
}
|
|
|
}
|