xiongzhu 3 лет назад
Родитель
Сommit
504add629c

+ 14 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -33,6 +33,7 @@ import org.springframework.data.redis.core.BoundValueOperations;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.TaskScheduler;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.annotation.PostConstruct;
 import javax.persistence.criteria.Predicate;
@@ -455,4 +456,17 @@ public class CollectionService {
         rocketMQTemplate.convertAndSend(generalProperties.getUpdateQuotaTopic(), id);
         return stock;
     }
+
+    @Cacheable(value = "recommendLegacy", key = "#type")
+    public List<CollectionDTO> recommendLegacy(@RequestParam String type) {
+        return collectionRepo.recommend(type).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;
+        }).collect(Collectors.toList());
+    }
 }

+ 6 - 1
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -131,7 +131,11 @@ public class CollectionController extends BaseController {
 
     @GetMapping("/recommend")
     @Cacheable("recommend")
-    public List<RecommendDTO> recommendAll() {
+    public Object recommendAll(@RequestParam(required = false) String type) {
+        if (StringUtils.isNotEmpty(type)) {
+            return collectionService.recommendLegacy(type);
+        }
+
         List<RecommendDTO> recommedDTOS = new ArrayList<>();
 
         List<RecommendDTO> collectionDTOS = collectionRepo.recommend("LIST").stream().map(rc -> {
@@ -157,6 +161,7 @@ public class CollectionController extends BaseController {
         return recommedDTOS;
     }
 
+
     @PreAuthorize("hasRole('ADMIN')")
     @GetMapping("/clearRecommend")
     public String clearRecommend() {