ProductSku改造

pull/4/head
zhuyang 2021-10-07 23:55:34 +08:00
parent 50d8aac20f
commit 53a33e4999
12 changed files with 110 additions and 97 deletions

View File

@ -0,0 +1,27 @@
package cn.iocoder.mall.productservice.rpc.sku;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(value = "product-service")
public interface ProductSkuFeign {
@GetMapping("/product/sku/getProductSku")
CommonResult<ProductSkuRespDTO> getProductSku(@RequestParam("productSkuId") Integer productSkuId);
/**
* SKU
*
* @param queryReqDTO SKU DTO
* @return SKU
*/
@PostMapping("/product/sku/listProductSkus")
CommonResult<List<ProductSkuRespDTO>> listProductSkus(@RequestBody ProductSkuListQueryReqDTO queryReqDTO);
}

View File

@ -1,30 +0,0 @@
package cn.iocoder.mall.productservice.rpc.sku;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import java.util.List;
/**
* SKU Rpc
*/
public interface ProductSkuRpc {
/**
* SKU
*
* @param productSkuId SKU
* @return SKU
*/
CommonResult<ProductSkuRespDTO> getProductSku(Integer productSkuId);
/**
* SKU
*
* @param queryReqDTO SKU DTO
* @return SKU
*/
CommonResult<List<ProductSkuRespDTO>> listProductSkus(ProductSkuListQueryReqDTO queryReqDTO);
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.mall.productservice.controller;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.productservice.manager.attr.ProductAttrManager;
import cn.iocoder.mall.productservice.manager.sku.ProductSkuManager;
import cn.iocoder.mall.productservice.rpc.attr.dto.*;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("/product/sku")
@Api("商品sku")
public class ProductSkuController {
@Autowired
private ProductSkuManager productSkuManager;
/**
* SKU
*
* @param productSkuId SKU
* @return SKU
*/
@GetMapping("getProductSku")
CommonResult<ProductSkuRespDTO> getProductSku(@RequestParam("productSkuId") Integer productSkuId){
return success(productSkuManager.getProductSku(productSkuId));
}
/**
* SKU
*
* @param queryReqDTO SKU DTO
* @return SKU
*/
@PostMapping("listProductSkus")
CommonResult<List<ProductSkuRespDTO>> listProductSkus(@RequestBody ProductSkuListQueryReqDTO queryReqDTO){
return success(productSkuManager.listProductSkus(queryReqDTO));
}
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.mall.productservice.rpc.sku;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.manager.sku.ProductSkuManager;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* SKU Rpc
*/
@DubboService
public class ProductSkuRpcImpl implements ProductSkuRpc {
@Autowired
private ProductSkuManager productSkuManager;
@Override
public CommonResult<ProductSkuRespDTO> getProductSku(Integer productSkuId) {
return success(productSkuManager.getProductSku(productSkuId));
}
@Override
public CommonResult<List<ProductSkuRespDTO>> listProductSkus(ProductSkuListQueryReqDTO queryReqDTO) {
return success(productSkuManager.listProductSkus(queryReqDTO));
}
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.mall.promotionservice.manager.price;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuFeign;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
@ -21,7 +21,6 @@ import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcRespDTO;
import cn.iocoder.mall.promotionservice.service.activity.PromotionActivityService;
import cn.iocoder.mall.promotionservice.service.coupon.CouponCardService;
import cn.iocoder.mall.promotionservice.service.coupon.CouponTemplateService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
@ -36,8 +35,8 @@ import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.*;
@Validated
public class PriceManager {
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
private ProductSkuRpc productSkuRpc;
@Autowired
private ProductSkuFeign productSkuFeign;
@Autowired
private ProductSpuFeign productSpuFeign;
@ -53,7 +52,7 @@ public class PriceManager {
// 校验商品都存在
Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap = CollectionUtils.convertMap(
calcReqDTO.getItems(), PriceProductCalcReqDTO.Item::getSkuId);
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus(
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuFeign.listProductSkus(
new ProductSkuListQueryReqDTO().setProductSkuIds(calcProductItemDTOMap.keySet()));
listProductSkusResult.checkError();
if (calcReqDTO.getItems().size() != listProductSkusResult.getData().size()) {

View File

@ -5,7 +5,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.productservice.rpc.category.ProductCategoryFeign;
import cn.iocoder.mall.productservice.rpc.category.dto.ProductCategoryRespDTO;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuFeign;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
@ -20,7 +20,6 @@ import cn.iocoder.mall.searchservice.service.product.bo.SearchProductBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductConditionBO;
import cn.iocoder.mall.searchservice.service.product.bo.SearchProductSaveBO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -33,9 +32,9 @@ public class SearchProductManager {
private static final Integer REBUILD_FETCH_PER_SIZE = 100;
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
private ProductSkuRpc productSkuRpc;
@Autowired
private ProductSkuFeign productSkuFeign;
@Autowired
private ProductCategoryFeign productCategoryFeign;
@Autowired
@ -102,7 +101,7 @@ public class SearchProductManager {
}
// 获得商品 SKU
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult =
productSkuRpc.listProductSkus(new ProductSkuListQueryReqDTO().setProductSpuId(id));
productSkuFeign.listProductSkus(new ProductSkuListQueryReqDTO().setProductSpuId(id));
listProductSkusResult.checkError();
if (CollectionUtils.isEmpty(listProductSkusResult.getData())) {
log.error("[saveProduct][商品 SPU({}) 的 SKU 不存在]", id);

View File

@ -1,5 +1,5 @@
### /product-spu/page 计算商品 SKU 价格
GET {{shop-api-base-url}}/product-sku/cal-price?id=33
GET http://127.0.0.1:18084/shop-api/product-sku/cal-price?id=33
Content-Type: application/x-www-form-urlencoded
###

View File

@ -2,10 +2,8 @@ package cn.iocoder.mall.shopweb.service.trade;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.tradeservice.rpc.cart.CartRpc;
import cn.iocoder.mall.tradeservice.rpc.cart.dto.*;
import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuFeign;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc;
@ -16,7 +14,10 @@ import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcReqDTO;
import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcRespDTO;
import cn.iocoder.mall.shopweb.controller.trade.vo.cart.CartDetailVO;
import cn.iocoder.mall.shopweb.convert.trade.CartConvert;
import cn.iocoder.mall.tradeservice.rpc.cart.CartRpc;
import cn.iocoder.mall.tradeservice.rpc.cart.dto.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@ -34,8 +35,9 @@ public class CartManager {
private PriceRpc priceRpc;
@DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}")
private PromotionActivityRpc promotionActivityRpc;
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
private ProductSkuRpc productSkuRpc;
@Autowired
private ProductSkuFeign productSkuFeign;
/**
*
@ -158,7 +160,7 @@ public class CartManager {
}
private Map<Integer, ProductSkuRespDTO> getProductSkuMap(List<CartItemRespDTO> itemRespDTOs) {
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus(new ProductSkuListQueryReqDTO()
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuFeign.listProductSkus(new ProductSkuListQueryReqDTO()
.setProductSkuIds(CollectionUtils.convertSet(itemRespDTOs, CartItemRespDTO::getSkuId))
.setFields(Arrays.asList(ProductSkuDetailFieldEnum.SPU.getField(), ProductSkuDetailFieldEnum.ATTR.getField())));
listProductSkusResult.checkError();

View File

@ -6,7 +6,7 @@ import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuFeign;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc;
@ -55,11 +55,12 @@ public class TradeOrderService {
private PromotionActivityRpc promotionActivityRpc;
@DubboReference(version = "${dubbo.consumer.ProductCategoryRpc.version}")
private CartRpc cartRpc;
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
private ProductSkuRpc productSkuRpc;
@DubboReference(version = "${dubbo.consumer.CouponCardRpc.version}")
private CouponCardRpc couponCardRpc;
@Autowired
private ProductSkuFeign productSkuFeign;
@Autowired
private TradeOrderClient tradeOrderClient;
@ -128,7 +129,7 @@ public class TradeOrderService {
private Map<Integer, ProductSkuRespDTO> checkProductSkus(Map<Integer, Integer> skuMap) {
// 获得商品 SKU 列表
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus(new ProductSkuListQueryReqDTO()
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuFeign.listProductSkus(new ProductSkuListQueryReqDTO()
.setProductSkuIds(skuMap.keySet())
.setFields(Arrays.asList(ProductSkuDetailFieldEnum.SPU.getField(), ProductSkuDetailFieldEnum.ATTR.getField())));
listProductSkusResult.checkError();

View File

@ -2,8 +2,12 @@ package cn.iocoder.mall.tradeservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc"})
public class TradeServiceApplication {
public static void main(String[] args) {

View File

@ -2,10 +2,10 @@ package cn.iocoder.mall.tradeservice.client.product;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuFeign;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
@ -15,15 +15,14 @@ import java.util.List;
@Service
public class ProductSkuClient {
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
private ProductSkuRpc productSkuRpc;
@Autowired
private ProductSkuFeign productSkuFeign;
public List<ProductSkuRespDTO> listProductSkus(Collection<Integer> productSkuIds, String... fields) {
if (CollectionUtils.isEmpty(productSkuIds)) {
return Collections.emptyList();
}
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus(
CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuFeign.listProductSkus(
new ProductSkuListQueryReqDTO().setProductSkuIds(productSkuIds).setFields(Arrays.asList(fields)));
listProductSkusResult.checkError();
return listProductSkusResult.getData();

View File

@ -3,13 +3,11 @@ package cn.iocoder.mall.tradeservice.service.cart;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuFeign;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import cn.iocoder.mall.tradeservice.convert.cart.CartConvert;
import cn.iocoder.mall.tradeservice.rpc.cart.dto.*;
import cn.iocoder.mall.tradeservice.service.cart.CartService;
import cn.iocoder.mall.tradeservice.service.cart.bo.CartItemBO;
import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc;
import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -23,8 +21,8 @@ import static cn.iocoder.mall.tradeservice.enums.OrderErrorCodeConstants.CARD_IT
@Service
public class CartManager {
@DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}")
private ProductSkuRpc productSkuRpc;
@Autowired
private ProductSkuFeign productSkuFeign;
@Autowired
private CartService cartService;
@ -104,7 +102,7 @@ public class CartManager {
* @return SKU
*/
private ProductSkuRespDTO checkProductSku(Integer skuId) {
CommonResult<ProductSkuRespDTO> getProductSkuResult = productSkuRpc.getProductSku(skuId);
CommonResult<ProductSkuRespDTO> getProductSkuResult = productSkuFeign.getProductSku(skuId);
getProductSkuResult.checkError();
ProductSkuRespDTO skuDTO = getProductSkuResult.getData();
if (skuDTO == null || CommonStatusEnum.DISABLE.getValue().equals(skuDTO.getStatus())) {