优惠改造

This commit is contained in:
zhuyang
2021-10-09 22:56:43 +08:00
parent af8f9745e9
commit 341404eafa
37 changed files with 486 additions and 497 deletions

View File

@@ -8,7 +8,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.iocoder.mall.productservice.rpc","cn.iocoder.mall.searchservice.rpc",
"cn.iocoder.mall.tradeservice.rpc","cn.iocoder.mall.payservice.rpc"})
"cn.iocoder.mall.tradeservice.rpc","cn.iocoder.mall.payservice.rpc","cn.iocoder.mall.promotion.api.rpc"})
public class ShopWebApplication {
public static void main(String[] args) {

View File

@@ -1,15 +1,15 @@
package cn.iocoder.mall.shopweb.service.product;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityFeign;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import cn.iocoder.mall.promotion.api.rpc.price.PriceRpc;
import cn.iocoder.mall.promotion.api.rpc.price.PriceFeign;
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.product.vo.sku.ProductSkuCalcPriceRespVO;
import cn.iocoder.mall.shopweb.convert.product.ProductSkuConvert;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -23,11 +23,11 @@ import java.util.List;
@Validated
public class ProductSkuManager {
@DubboReference(version = "${dubbo.consumer.PriceRpc.version}")
private PriceRpc priceRpc;
@DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}")
private PromotionActivityRpc promotionActivityRpc;
@Autowired
private PriceFeign priceFeign;
@Autowired
private PromotionActivityFeign promotionActivityFeign;
/**
* 计算商品 SKU 价格
*
@@ -36,7 +36,7 @@ public class ProductSkuManager {
* @return SKU 价格明细
*/
public ProductSkuCalcPriceRespVO calcProductSkuPrice(Integer userId, Integer skuId) {
CommonResult<PriceProductCalcRespDTO> calcProductPriceResult = priceRpc.calcProductPrice(new PriceProductCalcReqDTO().setUserId(userId)
CommonResult<PriceProductCalcRespDTO> calcProductPriceResult = priceFeign.calcProductPrice(new PriceProductCalcReqDTO().setUserId(userId)
.setItems(Collections.singletonList(new PriceProductCalcReqDTO.Item(skuId, 1, true))));
calcProductPriceResult.checkError();
// 拼接结果
@@ -51,7 +51,7 @@ public class ProductSkuManager {
}
private PromotionActivityRespDTO getPromotionActivity(Integer activityId) {
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivitiesResult = promotionActivityRpc.listPromotionActivities(
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivitiesResult = promotionActivityFeign.listPromotionActivities(
new PromotionActivityListReqDTO().setActiveIds(Collections.singleton(activityId)));
listPromotionActivitiesResult.checkError();
return listPromotionActivitiesResult.getData().get(0);

View File

@@ -2,12 +2,12 @@ package cn.iocoder.mall.shopweb.service.promotion;
import cn.iocoder.common.framework.enums.CommonStatusEnum;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.rpc.banner.BannerRpc;
import cn.iocoder.mall.promotion.api.rpc.banner.BannerFeign;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO;
import cn.iocoder.mall.shopweb.controller.promotion.vo.brand.BannerRespVO;
import cn.iocoder.mall.shopweb.convert.promotion.BannerConvert;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -20,13 +20,11 @@ import java.util.List;
@Service
@Validated
public class BannerManager {
@DubboReference(version = "${dubbo.consumer.BannerRpc.version}")
private BannerRpc bannerRpc;
@Autowired
private BannerFeign bannerFeign;
public List<BannerRespVO> listBanners() {
// 获取 Banner 列表
CommonResult<List<BannerRespDTO>> listBannersResult = bannerRpc.listBanners(
CommonResult<List<BannerRespDTO>> listBannersResult = bannerFeign.listBanners(
new BannerListReqDTO().setStatus(CommonStatusEnum.ENABLE.getValue()));
listBannersResult.checkError();
// 排序返回

View File

@@ -2,13 +2,13 @@ package cn.iocoder.mall.shopweb.service.promotion;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardFeign;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardCreateReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO;
import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardPageReqVO;
import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardRespVO;
import cn.iocoder.mall.shopweb.convert.promotion.CouponCardConvert;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@@ -17,9 +17,8 @@ import org.springframework.stereotype.Service;
@Service
public class CouponCardManager {
@DubboReference(version = "${dubbo.consumer.CouponCardRpc.version}")
private CouponCardRpc couponCardRpc;
@Autowired
private CouponCardFeign couponCardFeign;
/**
* 获得优惠劵分页
*
@@ -28,7 +27,7 @@ public class CouponCardManager {
* @return 优惠劵分页结果
*/
public PageResult<CouponCardRespVO> pageCouponCard(Integer userId, CouponCardPageReqVO pageVO) {
CommonResult<PageResult<CouponCardRespDTO>> pageCouponCardResult = couponCardRpc.pageCouponCard(
CommonResult<PageResult<CouponCardRespDTO>> pageCouponCardResult = couponCardFeign.pageCouponCard(
CouponCardConvert.INSTANCE.convert(pageVO).setUserId(userId));
pageCouponCardResult.checkError();
return CouponCardConvert.INSTANCE.convertPage(pageCouponCardResult.getData());
@@ -42,7 +41,7 @@ public class CouponCardManager {
* @return 优惠劵编号
*/
public Integer createCouponCard(Integer userId, Integer couponTemplateId) {
CommonResult<Integer> createCouponCardResult = couponCardRpc.createCouponCard(
CommonResult<Integer> createCouponCardResult = couponCardFeign.createCouponCard(
new CouponCardCreateReqDTO().setUserId(userId).setCouponTemplateId(couponTemplateId));
createCouponCardResult.checkError();
return createCouponCardResult.getData();

View File

@@ -1,11 +1,11 @@
package cn.iocoder.mall.shopweb.service.promotion;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateFeign;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO;
import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.template.CouponTemplateRespVO;
import cn.iocoder.mall.shopweb.convert.promotion.CouponTemplateConvert;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
@@ -13,12 +13,10 @@ import org.springframework.stereotype.Service;
*/
@Service
public class CouponTemplateManager {
@DubboReference(version = "${dubbo.consumer.CouponTemplateRpc.version}")
private CouponTemplateRpc couponTemplateRpc;
@Autowired
private CouponTemplateFeign couponTemplateFeign;
public CouponTemplateRespVO getCouponTemplate(Integer id) {
CommonResult<CouponTemplateRespDTO> getCouponTemplateResult = couponTemplateRpc.getCouponTemplate(id);
CommonResult<CouponTemplateRespDTO> getCouponTemplateResult = couponTemplateFeign.getCouponTemplate(id);
getCouponTemplateResult.checkError();
return CouponTemplateConvert.INSTANCE.convert(getCouponTemplateResult.getData());
}

View File

@@ -5,14 +5,13 @@ import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendRpc;
import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendFeign;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO;
import cn.iocoder.mall.shopweb.controller.product.vo.product.ProductSpuRespVO;
import cn.iocoder.mall.shopweb.convert.promotion.ProductRecommendConvert;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -28,15 +27,14 @@ import java.util.Map;
@Service
@Validated
public class ProductRecommendManager {
@DubboReference(version = "${dubbo.consumer.ProductRecommendRpc.version}")
private ProductRecommendRpc productRecommendRpc;
@Autowired
private ProductRecommendFeign productRecommendFeign;
@Autowired
private ProductSpuFeign productSpuFeign;
public Map<Integer, Collection<ProductSpuRespVO>> listProductRecommends() {
// 查询商品推荐列表
CommonResult<List<ProductRecommendRespDTO>> listProductRecommendsResult = productRecommendRpc.listProductRecommends(
CommonResult<List<ProductRecommendRespDTO>> listProductRecommendsResult = productRecommendFeign.listProductRecommends(
new ProductRecommendListReqDTO().setStatus(CommonStatusEnum.ENABLE.getValue()));
listProductRecommendsResult.checkError();
listProductRecommendsResult.getData().sort(Comparator.comparing(ProductRecommendRespDTO::getSort)); // 排序,按照 sort 升序

View File

@@ -6,17 +6,16 @@ import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
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;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityFeign;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import cn.iocoder.mall.promotion.api.rpc.price.PriceRpc;
import cn.iocoder.mall.promotion.api.rpc.price.PriceFeign;
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.CartFeign;
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;
@@ -31,10 +30,11 @@ public class CartManager {
@Autowired
private CartFeign cartFeign;
@DubboReference(version = "${dubbo.consumer.PriceRpc.version}")
private PriceRpc priceRpc;
@DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}")
private PromotionActivityRpc promotionActivityRpc;
@Autowired
private PriceFeign priceFeign;
@Autowired
private PromotionActivityFeign promotionActivityFeign;
@Autowired
private ProductSkuFeign productSkuFeign;
@@ -107,7 +107,7 @@ public class CartManager {
return result;
}
// 计算商品价格
CommonResult<PriceProductCalcRespDTO> calcProductPriceResult = priceRpc.calcProductPrice(new PriceProductCalcReqDTO().setUserId(userId)
CommonResult<PriceProductCalcRespDTO> calcProductPriceResult = priceFeign.calcProductPrice(new PriceProductCalcReqDTO().setUserId(userId)
.setItems(listCartItemsResult.getData().stream()
.map(cartItem -> new PriceProductCalcReqDTO.Item(cartItem.getSkuId(), cartItem.getQuantity(), cartItem.getSelected()))
.collect(Collectors.toList())));
@@ -154,7 +154,7 @@ public class CartManager {
}
// 查询促销活动列表
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivitiesResult =
promotionActivityRpc.listPromotionActivities(new PromotionActivityListReqDTO().setActiveIds(activeIds));
promotionActivityFeign.listPromotionActivities(new PromotionActivityListReqDTO().setActiveIds(activeIds));
listPromotionActivitiesResult.checkError();
return CollectionUtils.convertMap(listPromotionActivitiesResult.getData(), PromotionActivityRespDTO::getId);
}

View File

@@ -9,13 +9,13 @@ import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum;
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;
import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityFeign;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardRpc;
import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardFeign;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableListReqDTO;
import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO;
import cn.iocoder.mall.promotion.api.rpc.price.PriceRpc;
import cn.iocoder.mall.promotion.api.rpc.price.PriceFeign;
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.client.trade.TradeOrderClient;
@@ -31,7 +31,6 @@ import cn.iocoder.mall.tradeservice.rpc.cart.dto.CartItemListReqDTO;
import cn.iocoder.mall.tradeservice.rpc.cart.dto.CartItemRespDTO;
import cn.iocoder.mall.tradeservice.rpc.order.dto.TradeOrderPageReqDTO;
import cn.iocoder.mall.tradeservice.rpc.order.dto.TradeOrderRespDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -49,15 +48,15 @@ import static cn.iocoder.mall.shopweb.enums.ShopWebErrorCodeConstants.ORDER_PROD
@Validated
public class TradeOrderService {
@DubboReference(version = "${dubbo.consumer.PriceRpc.version}")
private PriceRpc priceRpc;
@DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}")
private PromotionActivityRpc promotionActivityRpc;
@Autowired
private PriceFeign priceFeign;
@Autowired
private PromotionActivityFeign promotionActivityFeign;
@Autowired
private CartFeign cartFeign;
private CouponCardRpc couponCardRpc;
@Autowired
private CouponCardFeign couponCardFeign;
@Autowired
private ProductSkuFeign productSkuFeign;
@@ -94,7 +93,7 @@ public class TradeOrderService {
// 获得商品 SKU 信息
Map<Integer, ProductSkuRespDTO> productSkuMap = this.checkProductSkus(skuMap);
// 计算商品价格
CommonResult<PriceProductCalcRespDTO> calcProductPriceResult = priceRpc.calcProductPrice(new PriceProductCalcReqDTO()
CommonResult<PriceProductCalcRespDTO> calcProductPriceResult = priceFeign.calcProductPrice(new PriceProductCalcReqDTO()
.setUserId(userId).setCouponCardId(couponCardId)
.setItems(skuMap.entrySet().stream().map(entry -> new PriceProductCalcReqDTO.Item(entry.getKey(), entry.getValue(), true))
.collect(Collectors.toList())));
@@ -119,7 +118,7 @@ public class TradeOrderService {
productSkuMap.get(item.getSkuId()), promotionActivityMap.get(item.getActivityId()))));
}
// 查询可用优惠劵信息
CommonResult<List<CouponCardAvailableRespDTO>> listAvailableCouponCardsResult = couponCardRpc.listAvailableCouponCards(
CommonResult<List<CouponCardAvailableRespDTO>> listAvailableCouponCardsResult = couponCardFeign.listAvailableCouponCards(
new CouponCardAvailableListReqDTO().setUserId(userId)
.setItems(TradeOrderConvert.INSTANCE.convertList(calcProductPriceResult.getData().getItemGroups())));
listAvailableCouponCardsResult.checkError();
@@ -165,7 +164,7 @@ public class TradeOrderService {
}
// 查询促销活动列表
CommonResult<List<PromotionActivityRespDTO>> listPromotionActivitiesResult =
promotionActivityRpc.listPromotionActivities(new PromotionActivityListReqDTO().setActiveIds(activeIds));
promotionActivityFeign.listPromotionActivities(new PromotionActivityListReqDTO().setActiveIds(activeIds));
listPromotionActivitiesResult.checkError();
return CollectionUtils.convertMap(listPromotionActivitiesResult.getData(), PromotionActivityRespDTO::getId);
}