Browse Source

ProductService.getRelatedPackages, filter offline pkgs by status

xuchaolang 6 years ago
parent
commit
a6153d0f3e

+ 1 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/controller/ProductController.java

@@ -136,6 +136,7 @@ public class ProductController {
 
         //get pkgs
         List<Product> pkgs = productService.getRelatedPackages(pid, merchantId, start, offset, sortKey, Sort.Direction.ASC);
+
         for (Product pkg :pkgs){
 
             List<Product> childrens = packageService.getChildrens(pkg.getPid());

+ 5 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/repository/MerchantProductRepository.java

@@ -19,11 +19,16 @@ public interface MerchantProductRepository extends BasicJpaRepository<MerchantPr
     @Query(value = "select m from MerchantProduct m where m.pid in (?1) and m.merchantId = ?2 order by m.sort")
     List<MerchantProduct> findByPidsAndMerchantId(List<String> pids, String merchantId);
 
+
+
     @Query(value = "select m from MerchantProduct m where m.pid in (?1) and m.merchantId = ?2 and m.status = ?3 order by m.sort")
     List<MerchantProduct> findByPidsAndMerchantId(List<String> pids, String merchantId, BaseStatusEnum status);
 
     MerchantProduct findByPidAndMerchantId(String pid, String merchantId);
 
+    @Query(value = "select m from MerchantProduct m where m.pid = ?1 and m.merchantId = ?2 and m.status=?3 order by m.sort")
+    MerchantProduct findByPidAndMerchantIdAndStatus(String pid, String merchantId, BaseStatusEnum status);
+
     @Modifying
     @Query(value = "update MerchantProduct m set m.status = 1 where m.pid = ?1")
     Integer deleteByPid(String pid);

+ 4 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/repository/ProductRepository.java

@@ -1,5 +1,6 @@
 package cn.rankin.productservice.repository;
 
+import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.jpa.BasicJpaRepository;
 import cn.rankin.data.api.product.entity.Product;
 import org.springframework.data.jpa.repository.Modifying;
@@ -14,6 +15,9 @@ public interface ProductRepository extends BasicJpaRepository<Product, String> {
     @Query(value = "select p from Product p where p.pid in (?1)")
     List<Product> findByPids(List<String> pids);
 
+    @Query(value = "select p from Product p where p.pid in (?1) and p.status=?2")
+    List<Product> findByPidsAndStatus(List<String> pids, BaseStatusEnum status);
+
     @Modifying
     @Query(value = "update Product p set p.status = 1 where p.pid = ?1")
     Integer deleteByPid(String pid);

+ 4 - 3
rankin-product-service/src/main/java/cn/rankin/productservice/service/ProductService.java

@@ -3,6 +3,7 @@ package cn.rankin.productservice.service;
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
+import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.enums.ProductTypeEnum;
 import cn.rankin.common.utils.util.BeanUtil;
 import cn.rankin.common.utils.util.JpaSortUtil;
@@ -162,8 +163,8 @@ public class ProductService {
         for(PackageProductRelation rel : currentRelationList){
             //skip pid not belong merchant
             String pkgId = rel.getPkgId();
-            if(null == pkgId || null == merchantProductRepository.findByPidAndMerchantId(pkgId, merchantId)){
-                log.info("Skip, pkgId not Belong Merchant, pkgId={}, merchantId={}", pkgId, merchantId);
+            if(null == pkgId || null == merchantProductRepository.findByPidAndMerchantIdAndStatus(pkgId, merchantId, BaseStatusEnum.NORMAL)){
+                log.info("Skip, pkgId not Belong Merchant Or Not on Sale, pkgId={}, merchantId={}", pkgId, merchantId);
                 continue;
             }
 
@@ -175,7 +176,7 @@ public class ProductService {
             return new ArrayList<>();
         }
 
-        List<Product> pkgs = productRepository.findByPids(pids);
+        List<Product> pkgs = productRepository.findByPidsAndStatus(pids, BaseStatusEnum.NORMAL);
 
         if (null == pkgs){
             pkgs = new ArrayList<>();