|
|
@@ -3,10 +3,7 @@ package com.izouma.nineth.web;
|
|
|
import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.FileObject;
|
|
|
import com.izouma.nineth.domain.News;
|
|
|
-import com.izouma.nineth.dto.CollectionDTO;
|
|
|
-import com.izouma.nineth.dto.CreateBlindBox;
|
|
|
-import com.izouma.nineth.dto.PageQuery;
|
|
|
-import com.izouma.nineth.dto.RecommendNews;
|
|
|
+import com.izouma.nineth.dto.*;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
|
import com.izouma.nineth.repo.NewsRepo;
|
|
|
@@ -19,16 +16,12 @@ import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@@ -120,29 +113,32 @@ public class CollectionController extends BaseController {
|
|
|
}
|
|
|
|
|
|
@GetMapping("/recommend")
|
|
|
- @Cacheable("recommend")
|
|
|
- public Map<String, List<?>> recommendAll() {
|
|
|
- Map<String, List<?>> map = new HashMap<>();
|
|
|
+// @Cacheable("recommend")
|
|
|
+ public List<RecommendDTO> recommendAll() {
|
|
|
+ List<RecommendDTO> recommedDTOS = new ArrayList<>();
|
|
|
|
|
|
- List<CollectionDTO> collectionDTOS = collectionRepo.recommend("LIST").stream().map(rc -> {
|
|
|
+ List<RecommendDTO> collectionDTOS = collectionRepo.recommend("LIST").stream().map(rc -> {
|
|
|
if (StringUtils.isNotBlank(rc.getRecommend().getPic())) {
|
|
|
rc.getCollection().setPic(Collections.singletonList(new FileObject(null, rc.getRecommend()
|
|
|
.getPic(), null, null)));
|
|
|
}
|
|
|
CollectionDTO collectionDTO = new CollectionDTO();
|
|
|
BeanUtils.copyProperties(rc.getCollection(), collectionDTO);
|
|
|
- return collectionDTO;
|
|
|
+ return new RecommendDTO(rc.getRecommend().getSort(), collectionDTO, "collection");
|
|
|
}).collect(Collectors.toList());
|
|
|
- map.put("collection", collectionDTOS);
|
|
|
|
|
|
- List<News> news = newsRepo.recommend("LIST").stream().map(rn -> {
|
|
|
+ List<RecommendDTO> news = newsRepo.recommend("LIST").stream().map(rn -> {
|
|
|
if (StringUtils.isNotBlank(rn.getRecommend().getPic())) {
|
|
|
rn.getNews().setPic(rn.getRecommend().getPic());
|
|
|
}
|
|
|
- return rn.getNews();
|
|
|
+ rn.getNews().setSort(rn.getRecommend().getSort());
|
|
|
+ return new RecommendDTO(rn.getRecommend().getSort(), rn.getNews(), "news");
|
|
|
}).collect(Collectors.toList());
|
|
|
- map.put("news", news);
|
|
|
- return map;
|
|
|
+
|
|
|
+ recommedDTOS.addAll(collectionDTOS);
|
|
|
+ recommedDTOS.addAll(news);
|
|
|
+ recommedDTOS.sort((a, b) -> b.getSort().compareTo(a.getSort()));
|
|
|
+ return recommedDTOS;
|
|
|
}
|
|
|
}
|
|
|
|