From 9cf470df9495e54db919f191dfb895cc1fe843cc Mon Sep 17 00:00:00 2001 From: "ex_yang.li@ca-nio.com" Date: Thu, 15 Sep 2022 17:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BA=A4=E6=98=93=E8=AE=A2?= =?UTF-8?q?=E5=8D=95-=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95-=E5=86=B2?= =?UTF-8?q?=E7=AA=81=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/api/spu/ProductSpuApiImpl.java | 2 +- .../convert/order/TradeOrderItemConvert.java | 2 +- .../service/order/TradeOrderServiceImpl.java | 18 +++++++++--------- .../service/order/TradeOrderServiceTest.java | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApiImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApiImpl.java index e0bb69a5e..bc914d7a1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApiImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApiImpl.java @@ -25,7 +25,7 @@ public class ProductSpuApiImpl implements ProductSpuApi { private ProductSpuMapper productSpuMapper; @Override - public List getSpusByIds(Collection spuIds) { + public List getSpuList(Collection spuIds) { if (CollectionUtils.isAnyEmpty(spuIds)) { return Collections.emptyList(); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderItemConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderItemConvert.java index d5ef21b5b..ed26fab7e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderItemConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderItemConvert.java @@ -20,5 +20,5 @@ public interface TradeOrderItemConvert { * @param items sku列表价格 * @return 订单项 */ - List convertList(List items); + List convertList(List items); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index 88ea312fa..fb0f22ce9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -30,7 +30,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.dal.mysql.orderitem.TradeOrderItemMapper; -import cn.iocoder.yudao.module.trade.enums.enums.ErrorCodeConstants; +import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemRefundStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; @@ -82,12 +82,12 @@ public class TradeOrderServiceImpl implements TradeOrderService { List items = createReqVO.getItems(); // 商品SKU检查 sku可售状态,库存 - List skuInfos = productSkuApi.getSkusByIds(CollectionUtils.convertSet(items, Item::getSkuId)); - Map skuInfoMap = CollectionUtils.convertMap(skuInfos, SkuInfoRespDTO::getId); + List skuInfos = productSkuApi.getSkuList(CollectionUtils.convertSet(items, Item::getSkuId)); + Map skuInfoMap = CollectionUtils.convertMap(skuInfos, ProductSkuRespDTO::getId); checkSaleableAndStockFromSpu(skuInfoMap, items); // 商品SPU检查 sku可售状态,库存 - List spuInfos = productSpuApi.getSpusByIds(CollectionUtils.convertSet(skuInfos, SkuInfoRespDTO::getSpuId)); + List spuInfos = productSpuApi.getSpuList(CollectionUtils.convertSet(skuInfos, ProductSkuRespDTO::getSpuId)); checkSaleableFromSpu(spuInfos); // 价格计算 @@ -99,7 +99,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { tradeOrderMapper.insert(tradeOrderDO); // 订单项信息记录 - List tradeOrderItems = TradeOrderItemConvert.INSTANCE.convertList(priceResp.getItems()); + List tradeOrderItems = TradeOrderItemConvert.INSTANCE.convertList(priceResp.getOrder().getItems()); //-填充订单项-SKU信息 fillItemsInfoFromSkuAndOrder(tradeOrderDO, tradeOrderItems, skuInfoMap); tradeOrderItemMapper.insertBatch(tradeOrderItems); @@ -156,13 +156,13 @@ public class TradeOrderServiceImpl implements TradeOrderService { } private void fillItemsInfoFromSkuAndOrder(TradeOrderDO tradeOrderDO, List tradeOrderItems, - Map spuInfos) { + Map spuInfos) { for (TradeOrderItemDO tradeOrderItem : tradeOrderItems) { // 填充订单信息 tradeOrderItem.setOrderId(tradeOrderDO.getId()); tradeOrderItem.setUserId(tradeOrderDO.getUserId()); // 填充SKU信息 - SkuInfoRespDTO skuInfoRespDTO = spuInfos.get(tradeOrderItem.getSkuId()); + ProductSkuRespDTO skuInfoRespDTO = spuInfos.get(tradeOrderItem.getSkuId()); tradeOrderItem.setSpuId(skuInfoRespDTO.getSpuId()); tradeOrderItem.setPicUrl(skuInfoRespDTO.getPicUrl()); tradeOrderItem.setName(skuInfoRespDTO.getName()); @@ -182,14 +182,14 @@ public class TradeOrderServiceImpl implements TradeOrderService { } } - private void checkSaleableAndStockFromSpu(Map skuInfoMap, + private void checkSaleableAndStockFromSpu(Map skuInfoMap, List items) { // sku 不存在 if (items.size() != skuInfoMap.size()) { throw ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_SKU_NOT_FOUND); } for (Item item : items) { - SkuInfoRespDTO skuInfoDTO = skuInfoMap.get(item.getSkuId()); + ProductSkuRespDTO skuInfoDTO = skuInfoMap.get(item.getSkuId()); // sku禁用 if (!Objects.equals(CommonStatusEnum.ENABLE.getStatus(), skuInfoDTO.getStatus())) { throw ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_SKU_NOT_SALE); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/main/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java index b307258cb..97fb084a8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.module.market.api.price.PriceApi; import cn.iocoder.yudao.module.market.api.price.dto.PriceCalculateRespDTO; import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; -import cn.iocoder.yudao.module.product.api.sku.dto.SkuInfoRespDTO; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.dto.SpuInfoRespDTO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; @@ -60,21 +60,21 @@ class TradeOrderServiceTest extends BaseDbUnitTest { spuInfo.setId(1L); spuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus()); }); - when(productSpuApi.getSpusByIds(Collections.singleton(1L))).thenReturn(Lists.newArrayList(spuInfoRespDTO)); + when(productSpuApi.getSpuList(Collections.singleton(1L))).thenReturn(Lists.newArrayList(spuInfoRespDTO)); // mock 商品SkU数据 - SkuInfoRespDTO skuInfoRespDTO = randomPojo(SkuInfoRespDTO.class, skuInfo -> { + ProductSkuRespDTO skuInfoRespDTO = randomPojo(ProductSkuRespDTO.class, skuInfo -> { skuInfo.setId(1L); skuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus()); skuInfo.setStock(randomInteger()); skuInfo.setSpuId(1L); }); - when(productSkuApi.getSkusByIds(Collections.singleton(1L))).thenReturn(Lists.newArrayList(skuInfoRespDTO)); + when(productSkuApi.getSkuList(Collections.singleton(1L))).thenReturn(Lists.newArrayList(skuInfoRespDTO)); // mock 价格信息 PriceCalculateRespDTO calculateRespDTO = randomPojo(PriceCalculateRespDTO.class, priceCalculateRespDTO -> { - PriceCalculateRespDTO.Item item = priceCalculateRespDTO.getItems().get(0); + PriceCalculateRespDTO.OrderItem item = priceCalculateRespDTO.getOrder().getItems().get(0); item.setSkuId(1L); item.setCount(2); - priceCalculateRespDTO.setItems(Collections.singletonList(item)); + priceCalculateRespDTO.getOrder().setItems(Collections.singletonList(item)); }); when(priceApi.calculatePrice(any())).thenReturn(calculateRespDTO); //mock 支付订单信息 @@ -103,7 +103,7 @@ class TradeOrderServiceTest extends BaseDbUnitTest { assertEquals(skuInfoRespDTO.getId(), tradeOrderItemDO.getSkuId()); assertEquals(1L, tradeOrderItemDO.getUserId()); //价格 - assertEquals(calculateRespDTO.getItems().get(0).getPresentPrice(), tradeOrderItemDO.getPresentPrice()); + assertEquals(calculateRespDTO.getOrder().getItems().get(0).getPresentPrice(), tradeOrderItemDO.getPresentPrice()); } }