Browse Source

ProductService.getRelatedPkgs, set goods

xuchaolang 6 years ago
parent
commit
a6a6614946

+ 20 - 5
rankin-product-service/src/main/java/cn/rankin/productservice/controller/PackageController.java

@@ -1,13 +1,11 @@
 package cn.rankin.productservice.controller;
 
 import cn.rankin.data.api.product.entity.Product;
+import cn.rankin.productservice.repository.GoodsRepository;
 import cn.rankin.productservice.service.PackageService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 
 @RestController
@@ -18,11 +16,28 @@ public class PackageController {
     @Autowired
     private PackageService packageService;
 
+    @Autowired
+    private GoodsRepository goodsRepository;
+
     @RequestMapping(value = "/{pid}", method = RequestMethod.GET)
     public Product getPackage(@PathVariable("pid") String pid) {
 
-        return packageService.get(pid);
+        if(null == pid || pid.isEmpty()){
+            return null;
+        }
+
+        Product pkg =  packageService.get(pid);
+
+        if (null == pkg){
+            log.info("Cannot Find Package By pkgId, pkgId={}", pid);
+            return null;
+        }
+
+        //List<Goods> goods = goodsRepository.findByPidAndMerchantId(pid, merchantId);
+
+        //pkg.setGoods(goods);
 
+        return pkg;
     }
 }
 

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

@@ -7,6 +7,7 @@ import cn.rankin.data.api.product.dto.*;
 import cn.rankin.data.api.product.entity.*;
 import cn.rankin.data.api.product.entity.Package;
 import cn.rankin.productservice.code.ProductServiceAPICode;
+import cn.rankin.productservice.repository.GoodsRepository;
 import cn.rankin.productservice.service.PackageService;
 import cn.rankin.productservice.service.ProductService;
 import org.apache.commons.lang3.StringUtils;
@@ -29,6 +30,9 @@ public class ProductController {
     @Autowired
     private PackageService packageService;
 
+    @Autowired
+    private GoodsRepository goodsRepository;
+
     @RequestMapping(method = RequestMethod.GET)
     public APIResult<Page<Product>> search(ProductSearchDTO searchDTO) {
         Product product = new Product();
@@ -136,7 +140,15 @@ public class ProductController {
 
             List<Product> childrens = packageService.getChildrens(pkg.getPid());
 
+            //goods
+            List<Goods> goodsList = null;
+
+            if(null != pkg.getPid()){
+                goodsList = goodsRepository.findByPidAndMerchantId(pkg.getPid(), merchantId);
+            }
+
             pkg.setChildrens(childrens);
+            pkg.setGoods(goodsList);
         }
 
         if(null == pkgs){