|
@@ -5,6 +5,7 @@ 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.apache.commons.collections.map.HashedMap;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
@@ -16,7 +17,9 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
* Created by dongbw on 17/02/25 16:05.
|
|
@@ -39,9 +42,14 @@ public class NewsServiceImpl implements NewsService {
|
|
|
return news;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public List<News> findBycreated(int pagenumber , int pagesize , String taxonomySlug) {
|
|
|
+ public Map<String,Object> findBycreated(int pagenumber , int pagesize , String taxonomySlug) {
|
|
|
+ Map<String,Object> result = new HashMap();
|
|
|
List<Long> idByTaxonomySlug = newsRepository.findNewsIdByTaxonomySlug(taxonomySlug);
|
|
|
+ if (idByTaxonomySlug != null){
|
|
|
+ result.put("count",idByTaxonomySlug.size());
|
|
|
+ }
|
|
|
Pageable pageable = new PageRequest(pagenumber-1 ,pagesize, new Sort(Sort.Direction.DESC, "modified"));
|
|
|
Page<News> page = newsRepository.findAll((root, query, builder) -> {
|
|
|
Predicate predicateId = root.get("id").in(idByTaxonomySlug);
|
|
@@ -50,15 +58,21 @@ public class NewsServiceImpl implements NewsService {
|
|
|
return null;
|
|
|
}, pageable);
|
|
|
if (page != null && !CollectionUtils.isEmpty(page.getContent())) {
|
|
|
- return NewsCloumnCutUtil.cutText(page.getContent());
|
|
|
+ result.put("content",NewsCloumnCutUtil.cutText(page.getContent()));
|
|
|
+ return result;
|
|
|
}
|
|
|
- return Collections.emptyList();
|
|
|
+ result.put("content",Collections.emptyList());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public List<News> findByViewCount(int pagenumber , int pagesize , String taxonomySlug) {
|
|
|
+ public Map<String,Object> findByViewCount(int pagenumber , int pagesize , String taxonomySlug) {
|
|
|
+ Map<String,Object> result = new HashMap();
|
|
|
List<Long> idByTaxonomySlug = newsRepository.findNewsIdByTaxonomySlug(taxonomySlug);
|
|
|
+ if (idByTaxonomySlug != null){
|
|
|
+ result.put("count",idByTaxonomySlug.size());
|
|
|
+ }
|
|
|
Pageable pageable = new PageRequest(pagenumber-1 ,pagesize, new Sort(Sort.Direction.DESC, "viewCount"));
|
|
|
Page<News> page = newsRepository.findAll((root, query, builder) -> {
|
|
|
Predicate predicateId = root.get("id").in(idByTaxonomySlug);
|
|
@@ -67,9 +81,11 @@ public class NewsServiceImpl implements NewsService {
|
|
|
return null;
|
|
|
}, pageable);
|
|
|
if (page != null && !CollectionUtils.isEmpty(page.getContent())) {
|
|
|
- return NewsCloumnCutUtil.cutText(page.getContent());
|
|
|
+ result.put("content",NewsCloumnCutUtil.cutText(page.getContent()));
|
|
|
+ return result;
|
|
|
}
|
|
|
- return Collections.emptyList();
|
|
|
+ result.put("content",Collections.emptyList());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|