|
@@ -1,8 +1,15 @@
|
|
package cn.rankin.productservice.controller;
|
|
package cn.rankin.productservice.controller;
|
|
|
|
|
|
import cn.rankin.common.utils.enums.BaseStatusEnum;
|
|
import cn.rankin.common.utils.enums.BaseStatusEnum;
|
|
|
|
+import cn.rankin.data.api.product.entity.Goods;
|
|
|
|
+import cn.rankin.data.api.product.entity.MerchantProduct;
|
|
import cn.rankin.data.api.product.entity.Poster;
|
|
import cn.rankin.data.api.product.entity.Poster;
|
|
|
|
+import cn.rankin.data.api.product.entity.Product;
|
|
|
|
+import cn.rankin.productservice.repository.GoodsRepository;
|
|
|
|
+import cn.rankin.productservice.repository.MerchantProductRepository;
|
|
import cn.rankin.productservice.repository.PosterRepository;
|
|
import cn.rankin.productservice.repository.PosterRepository;
|
|
|
|
+import cn.rankin.productservice.repository.ProductRepository;
|
|
|
|
+import cn.rankin.productservice.service.ProductService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
@@ -19,6 +26,18 @@ public class MerchantController {
|
|
@Autowired
|
|
@Autowired
|
|
private PosterRepository posterRepo;
|
|
private PosterRepository posterRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductService productService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductRepository productRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MerchantProductRepository merchantProductRepository;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private GoodsRepository goodsRepository;
|
|
|
|
+
|
|
@RequestMapping(value = "/{merchantId}/posters", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/{merchantId}/posters", method = RequestMethod.GET)
|
|
public List<Poster> getPosters(@PathVariable("merchantId") String merchantId, @RequestParam("start") Long start,
|
|
public List<Poster> getPosters(@PathVariable("merchantId") String merchantId, @RequestParam("start") Long start,
|
|
@RequestParam("offset") Integer offset, @RequestParam("sortKey") String sortKey,
|
|
@RequestParam("offset") Integer offset, @RequestParam("sortKey") String sortKey,
|
|
@@ -38,5 +57,31 @@ public class MerchantController {
|
|
log.info("Find Posters, len={}, merchantId={}", posters.size(), merchantId);
|
|
log.info("Find Posters, len={}, merchantId={}", posters.size(), merchantId);
|
|
return posters;
|
|
return posters;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/{merchantId}/product/{pid}", method = RequestMethod.GET)
|
|
|
|
+ public Product getProduct(@PathVariable("merchantId") String merchantId, @PathVariable("pid") String pid){
|
|
|
|
+
|
|
|
|
+ //check merchant
|
|
|
|
+ MerchantProduct merchantProduct = merchantProductRepository.findByPidAndMerchantId(pid, merchantId);
|
|
|
|
+
|
|
|
|
+ if (null == merchantProduct){
|
|
|
|
+ log.error("Cannot Find Merchant Product By pid, pid={}, merchantId={}", pid, merchantId);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Product product = productRepository.findByPid(pid);
|
|
|
|
+
|
|
|
|
+ if (null == product){
|
|
|
|
+ log.error("Cannot Find Product By pid, pid={}", pid);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //get goods
|
|
|
|
+ List<Goods> goods = goodsRepository.findByPidAndMerchantId(pid, merchantId);
|
|
|
|
+
|
|
|
|
+ product.setGoods(goods);
|
|
|
|
+
|
|
|
|
+ return product;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|