ProductSku改造
This commit is contained in:
parent
50d8aac20f
commit
53a33e4999
@ -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);
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
@ -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()) {
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
###
|
||||
|
@ -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();
|
||||
|
@ -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,10 +55,11 @@ 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();
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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())) {
|
||||
|
Loading…
Reference in New Issue
Block a user