|
@@ -3,6 +3,7 @@ package com.uas.cloud.mall.shop.news.service.impl;
|
|
|
import com.uas.cloud.mall.shop.news.data.NewsRepository;
|
|
|
import com.uas.cloud.mall.shop.news.model.News;
|
|
|
import com.uas.cloud.mall.shop.news.service.NewsService;
|
|
|
+import com.uas.cloud.mall.shop.news.utils.NewsCloumnCutUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
@@ -12,6 +13,7 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -26,35 +28,41 @@ public class NewsServiceImpl implements NewsService {
|
|
|
|
|
|
@Override
|
|
|
public News findone(Long id) {
|
|
|
- return newsRepository.findOne(id);
|
|
|
+ News news = newsRepository.findOne(id);
|
|
|
+
|
|
|
+ if ("".equals(news.getSummary()) || news.getSummary() == null){
|
|
|
+ news.setSummary(NewsCloumnCutUtil.getHtmlText(100,news.getContent()));
|
|
|
+ }
|
|
|
+ return news;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<News> findBycreated() {
|
|
|
- Pageable pageable = new PageRequest(0 ,8, new Sort(Sort.Direction.DESC, "modified"));
|
|
|
+ public List<News> findBycreated(int pagenumber , int pagesize) {
|
|
|
+ Pageable pageable = new PageRequest(pagenumber-1 ,pagesize, new Sort(Sort.Direction.DESC, "modified"));
|
|
|
Page<News> page = newsRepository.findAll((root, query, builder) -> {
|
|
|
Predicate predicate = builder.equal(root.get("module"), "news");
|
|
|
query.where(predicate);
|
|
|
return null;
|
|
|
}, pageable);
|
|
|
if (page != null && !CollectionUtils.isEmpty(page.getContent())) {
|
|
|
- return page.getContent();
|
|
|
+ return NewsCloumnCutUtil.cutText(page.getContent());
|
|
|
}
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public List<News> findByViewCount() {
|
|
|
- Pageable pageable = new PageRequest(0 ,8, new Sort(Sort.Direction.DESC, "viewCount"));
|
|
|
+ public List<News> findByViewCount(int pagenumber , int pagesize) {
|
|
|
+ Pageable pageable = new PageRequest(pagenumber-1 ,pagesize, new Sort(Sort.Direction.DESC, "viewCount"));
|
|
|
Page<News> page = newsRepository.findAll((root, query, builder) -> {
|
|
|
Predicate predicate = builder.equal(root.get("module"), "news");
|
|
|
query.where(predicate);
|
|
|
return null;
|
|
|
}, pageable);
|
|
|
if (page != null && !CollectionUtils.isEmpty(page.getContent())) {
|
|
|
- return page.getContent();
|
|
|
+ return NewsCloumnCutUtil.cutText(page.getContent());
|
|
|
}
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
+
|
|
|
}
|