|
@@ -2,11 +2,10 @@ package com.izouma.nineth.web;
|
|
|
|
|
|
|
|
import com.izouma.nineth.domain.Collection;
|
|
import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.FileObject;
|
|
import com.izouma.nineth.domain.FileObject;
|
|
|
-import com.izouma.nineth.dto.CollectionDTO;
|
|
|
|
|
-import com.izouma.nineth.dto.CreateBlindBox;
|
|
|
|
|
-import com.izouma.nineth.dto.PageQuery;
|
|
|
|
|
|
|
+import com.izouma.nineth.dto.*;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
|
|
|
+import com.izouma.nineth.repo.NewsRepo;
|
|
|
import com.izouma.nineth.service.CollectionService;
|
|
import com.izouma.nineth.service.CollectionService;
|
|
|
import com.izouma.nineth.service.LikeService;
|
|
import com.izouma.nineth.service.LikeService;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
@@ -16,15 +15,14 @@ import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/collection")
|
|
@RequestMapping("/collection")
|
|
@@ -33,6 +31,7 @@ public class CollectionController extends BaseController {
|
|
|
private CollectionService collectionService;
|
|
private CollectionService collectionService;
|
|
|
private CollectionRepo collectionRepo;
|
|
private CollectionRepo collectionRepo;
|
|
|
private LikeService likeService;
|
|
private LikeService likeService;
|
|
|
|
|
+ private NewsRepo newsRepo;
|
|
|
|
|
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
@PostMapping("/save")
|
|
@@ -99,8 +98,8 @@ public class CollectionController extends BaseController {
|
|
|
collectionService.appointment(id, SecurityUtils.getAuthenticatedUser().getId());
|
|
collectionService.appointment(id, SecurityUtils.getAuthenticatedUser().getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @GetMapping("/recommend")
|
|
|
|
|
- @Cacheable("recommend")
|
|
|
|
|
|
|
+ // @GetMapping("/recommend")
|
|
|
|
|
+// @Cacheable("recommend")
|
|
|
public List<CollectionDTO> recommend(@RequestParam String type) {
|
|
public List<CollectionDTO> recommend(@RequestParam String type) {
|
|
|
return collectionRepo.recommend(type).stream().map(rc -> {
|
|
return collectionRepo.recommend(type).stream().map(rc -> {
|
|
|
if (StringUtils.isNotBlank(rc.getRecommend().getPic())) {
|
|
if (StringUtils.isNotBlank(rc.getRecommend().getPic())) {
|
|
@@ -112,5 +111,34 @@ public class CollectionController extends BaseController {
|
|
|
return collectionDTO;
|
|
return collectionDTO;
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/recommend")
|
|
|
|
|
+ @Cacheable("recommend")
|
|
|
|
|
+ public List<RecommendDTO> recommendAll() {
|
|
|
|
|
+ List<RecommendDTO> recommedDTOS = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ 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 new RecommendDTO(rc.getRecommend().getSort(), collectionDTO, "collection");
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<RecommendDTO> news = newsRepo.recommend("LIST").stream().map(rn -> {
|
|
|
|
|
+ if (StringUtils.isNotBlank(rn.getRecommend().getPic())) {
|
|
|
|
|
+ rn.getNews().setPic(rn.getRecommend().getPic());
|
|
|
|
|
+ }
|
|
|
|
|
+ rn.getNews().setSort(rn.getRecommend().getSort());
|
|
|
|
|
+ return new RecommendDTO(rn.getRecommend().getSort(), rn.getNews(), "news");
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ recommedDTOS.addAll(collectionDTOS);
|
|
|
|
|
+ recommedDTOS.addAll(news);
|
|
|
|
|
+ recommedDTOS.sort((a, b) -> b.getSort().compareTo(a.getSort()));
|
|
|
|
|
+ return recommedDTOS;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|