|
|
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
import com.luoo.music.dao.*;
|
|
|
|
|
import com.luoo.music.dto.request.cms.ArticleAddModel;
|
|
|
|
|
import com.luoo.music.dto.response.ArticleDTO;
|
|
|
|
|
import com.luoo.music.dto.response.TotalCommentVo;
|
|
|
|
|
import com.luoo.music.dto.response.cms.ArticleRespDTO;
|
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
@ -264,6 +265,11 @@ public class CMSArticleService {
|
|
|
|
|
List<ArticleRespDTO> pageArticleFromCache = getPageArticleFromCache(page, size);
|
|
|
|
|
return Result.success(new PageResult<>(Long.valueOf(pageArticleFromCache.size()), pageArticleFromCache));
|
|
|
|
|
}
|
|
|
|
|
public Result<PageResult<ArticleDTO>> searchArticleDTO(int page, int size) {
|
|
|
|
|
List<ArticleDTO> pageArticleFromCache = getPageArticleDTOFromCache(page, size);
|
|
|
|
|
return Result.success(new PageResult<>(Long.valueOf(pageArticleFromCache.size()), pageArticleFromCache));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Specification<Article> buildSearchSpecification() {
|
|
|
|
|
return (Root<Article> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
|
|
|
|
|
List<Predicate> predicateList = new ArrayList<Predicate>();
|
|
|
|
@ -293,6 +299,12 @@ public class CMSArticleService {
|
|
|
|
|
return (List<ArticleRespDTO>) cacheChannel.get(constants.Constants.J2CACHE_REGION_ARTICLE_PAGE, page+","+size, key -> getPageArticle(page,size), false).getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ArticleDTO> getPageArticleDTOFromCache(int page , int size){
|
|
|
|
|
|
|
|
|
|
return (List<ArticleDTO>) cacheChannel.get(constants.Constants.J2CACHE_REGION_ARTICLE_DTO_PAGE, page+","+size, key -> getPageArticleDTO(page,size), false).getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<ArticleRespDTO> getPageArticle(int page , int size){
|
|
|
|
|
|
|
|
|
|
List<ArticleRespDTO> result = new ArrayList<>();
|
|
|
|
@ -310,6 +322,24 @@ public class CMSArticleService {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ArticleDTO> getPageArticleDTO(int page,int size) {
|
|
|
|
|
|
|
|
|
|
List<ArticleDTO> result = new ArrayList<>();
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(page - 1, size);
|
|
|
|
|
Specification<Article> articleSpecification = buildSearchSpecification();
|
|
|
|
|
Page<Article> ArticlePage = articleDao.findAll(articleSpecification,pageRequest);
|
|
|
|
|
|
|
|
|
|
List<Article> content = ArticlePage.getContent();
|
|
|
|
|
if (!CollectionUtils.isEmpty(content)) {
|
|
|
|
|
for (Article item : content) {
|
|
|
|
|
ArticleDTO response = ArticleDTO.convertPojo(item);
|
|
|
|
|
result.add(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getArticleFromCache(String id){
|
|
|
|
|
return (String) cacheChannel.get(constants.Constants.J2CACHE_REGION_ARTICLE, id, key -> getArticleById(id), false).getValue();
|
|
|
|
|
}
|
|
|
|
|