Browse Source

处理推荐产品速度比较慢的问题。

yujia 7 years ago
parent
commit
decb50d31f

+ 3 - 2
src/main/java/com/uas/platform/b2c/prod/product/component/dao/ComponentInfoDao.java

@@ -77,10 +77,11 @@ public interface ComponentInfoDao extends JpaSpecificationExecutor<ComponentInfo
 
 	/**
 	 * 获取一页有图片的器件
-	 * @param pageable 分页参数
+	 * @param count 分页参数
 	 * @return 库存数量大于指定值的一页器件
 	 */
-	Page<ComponentInfo> findByImgIsNotNull(Pageable pageable);
+	@Query(value = "select c from ComponentInfo c where c.img is not null limit (:count)")
+	List<ComponentInfo> findByImgIsNotNull(@Param("count") Integer count);
 
 	/**
 	 * 根据批次号获取器件信息

+ 3 - 1
src/main/java/com/uas/platform/b2c/trade/deprecated/controller/RecommendController.java

@@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 /**
  * 推荐
  *
@@ -32,7 +34,7 @@ public class RecommendController {
     }
 
     @RequestMapping(value = "/comps", method = RequestMethod.GET)
-    public Page<ComponentInfo> getRecommendCompsForUser(Long userUU, String usedFor, Pageable pageable) {
+    public List<ComponentInfo> getRecommendCompsForUser(Long userUU, String usedFor, Pageable pageable) {
         logger.info(String.format("推荐服务:%s 在 %s 获取推荐器件,分页信息: %s", userUU, usedFor, pageable.toString()));
         return recommendService.getRecommendCompsForUser(userUU, usedFor, pageable);
     }

+ 4 - 2
src/main/java/com/uas/platform/b2c/trade/deprecated/service/RecommendService.java

@@ -1,10 +1,12 @@
 package com.uas.platform.b2c.trade.deprecated.service;
 
-import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
 import com.uas.platform.b2c.prod.commodity.model.Goods;
+import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 
+import java.util.List;
+
 /**
  * 推荐服务
  * @author yangck
@@ -27,5 +29,5 @@ public interface RecommendService {
      * @param pageable 分页信息
      * @return 一页ComponentInfo
      */
-    Page<ComponentInfo> getRecommendCompsForUser(Long userUU, String usedFor, Pageable pageable);
+    List<ComponentInfo> getRecommendCompsForUser(Long userUU, String usedFor, Pageable pageable);
 }

+ 10 - 4
src/main/java/com/uas/platform/b2c/trade/deprecated/service/impl/RecommendServiceImpl.java

@@ -1,15 +1,18 @@
 package com.uas.platform.b2c.trade.deprecated.service.impl;
 
-import com.uas.platform.b2c.prod.product.component.dao.ComponentInfoDao;
-import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
 import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
 import com.uas.platform.b2c.prod.commodity.model.Goods;
+import com.uas.platform.b2c.prod.product.component.dao.ComponentInfoDao;
+import com.uas.platform.b2c.prod.product.component.modal.ComponentInfo;
 import com.uas.platform.b2c.trade.deprecated.service.RecommendService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author yangck
  */
@@ -38,8 +41,11 @@ public class RecommendServiceImpl implements RecommendService {
     }
 
     @Override
-    public Page<ComponentInfo> getRecommendCompsForUser(Long userUU, String usedFor, Pageable pageable) {
-        Page<ComponentInfo> page = componentInfoDao.findByImgIsNotNull(pageable);
+    public List<ComponentInfo> getRecommendCompsForUser(Long userUU, String usedFor, Pageable pageable) {
+        if (pageable == null) {
+            return new ArrayList<>();
+        }
+        List<ComponentInfo> page = componentInfoDao.findByImgIsNotNull(pageable.getPageSize());
         return page;
     }
 }