创建交易订单-单元测试-冲突合并
This commit is contained in:
parent
f21ce954ec
commit
9cf470df94
|
@ -25,7 +25,7 @@ public class ProductSpuApiImpl implements ProductSpuApi {
|
||||||
private ProductSpuMapper productSpuMapper;
|
private ProductSpuMapper productSpuMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SpuInfoRespDTO> getSpusByIds(Collection<Long> spuIds) {
|
public List<SpuInfoRespDTO> getSpuList(Collection<Long> spuIds) {
|
||||||
if (CollectionUtils.isAnyEmpty(spuIds)) {
|
if (CollectionUtils.isAnyEmpty(spuIds)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,5 +20,5 @@ public interface TradeOrderItemConvert {
|
||||||
* @param items sku列表价格
|
* @param items sku列表价格
|
||||||
* @return 订单项
|
* @return 订单项
|
||||||
*/
|
*/
|
||||||
List<TradeOrderItemDO> convertList(List<PriceCalculateRespDTO.Item> items);
|
List<TradeOrderItemDO> convertList(List<PriceCalculateRespDTO.OrderItem> items);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.dataobject.order.TradeOrderItemDO;
|
||||||
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
|
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.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.TradeOrderItemRefundStatusEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
|
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
|
||||||
|
@ -82,12 +82,12 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||||
|
|
||||||
List<Item> items = createReqVO.getItems();
|
List<Item> items = createReqVO.getItems();
|
||||||
// 商品SKU检查 sku可售状态,库存
|
// 商品SKU检查 sku可售状态,库存
|
||||||
List<SkuInfoRespDTO> skuInfos = productSkuApi.getSkusByIds(CollectionUtils.convertSet(items, Item::getSkuId));
|
List<ProductSkuRespDTO> skuInfos = productSkuApi.getSkuList(CollectionUtils.convertSet(items, Item::getSkuId));
|
||||||
Map<Long, SkuInfoRespDTO> skuInfoMap = CollectionUtils.convertMap(skuInfos, SkuInfoRespDTO::getId);
|
Map<Long, ProductSkuRespDTO> skuInfoMap = CollectionUtils.convertMap(skuInfos, ProductSkuRespDTO::getId);
|
||||||
checkSaleableAndStockFromSpu(skuInfoMap, items);
|
checkSaleableAndStockFromSpu(skuInfoMap, items);
|
||||||
|
|
||||||
// 商品SPU检查 sku可售状态,库存
|
// 商品SPU检查 sku可售状态,库存
|
||||||
List<SpuInfoRespDTO> spuInfos = productSpuApi.getSpusByIds(CollectionUtils.convertSet(skuInfos, SkuInfoRespDTO::getSpuId));
|
List<SpuInfoRespDTO> spuInfos = productSpuApi.getSpuList(CollectionUtils.convertSet(skuInfos, ProductSkuRespDTO::getSpuId));
|
||||||
checkSaleableFromSpu(spuInfos);
|
checkSaleableFromSpu(spuInfos);
|
||||||
|
|
||||||
// 价格计算
|
// 价格计算
|
||||||
|
@ -99,7 +99,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||||
tradeOrderMapper.insert(tradeOrderDO);
|
tradeOrderMapper.insert(tradeOrderDO);
|
||||||
|
|
||||||
// 订单项信息记录
|
// 订单项信息记录
|
||||||
List<TradeOrderItemDO> tradeOrderItems = TradeOrderItemConvert.INSTANCE.convertList(priceResp.getItems());
|
List<TradeOrderItemDO> tradeOrderItems = TradeOrderItemConvert.INSTANCE.convertList(priceResp.getOrder().getItems());
|
||||||
//-填充订单项-SKU信息
|
//-填充订单项-SKU信息
|
||||||
fillItemsInfoFromSkuAndOrder(tradeOrderDO, tradeOrderItems, skuInfoMap);
|
fillItemsInfoFromSkuAndOrder(tradeOrderDO, tradeOrderItems, skuInfoMap);
|
||||||
tradeOrderItemMapper.insertBatch(tradeOrderItems);
|
tradeOrderItemMapper.insertBatch(tradeOrderItems);
|
||||||
|
@ -156,13 +156,13 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillItemsInfoFromSkuAndOrder(TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> tradeOrderItems,
|
private void fillItemsInfoFromSkuAndOrder(TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> tradeOrderItems,
|
||||||
Map<Long, SkuInfoRespDTO> spuInfos) {
|
Map<Long, ProductSkuRespDTO> spuInfos) {
|
||||||
for (TradeOrderItemDO tradeOrderItem : tradeOrderItems) {
|
for (TradeOrderItemDO tradeOrderItem : tradeOrderItems) {
|
||||||
// 填充订单信息
|
// 填充订单信息
|
||||||
tradeOrderItem.setOrderId(tradeOrderDO.getId());
|
tradeOrderItem.setOrderId(tradeOrderDO.getId());
|
||||||
tradeOrderItem.setUserId(tradeOrderDO.getUserId());
|
tradeOrderItem.setUserId(tradeOrderDO.getUserId());
|
||||||
// 填充SKU信息
|
// 填充SKU信息
|
||||||
SkuInfoRespDTO skuInfoRespDTO = spuInfos.get(tradeOrderItem.getSkuId());
|
ProductSkuRespDTO skuInfoRespDTO = spuInfos.get(tradeOrderItem.getSkuId());
|
||||||
tradeOrderItem.setSpuId(skuInfoRespDTO.getSpuId());
|
tradeOrderItem.setSpuId(skuInfoRespDTO.getSpuId());
|
||||||
tradeOrderItem.setPicUrl(skuInfoRespDTO.getPicUrl());
|
tradeOrderItem.setPicUrl(skuInfoRespDTO.getPicUrl());
|
||||||
tradeOrderItem.setName(skuInfoRespDTO.getName());
|
tradeOrderItem.setName(skuInfoRespDTO.getName());
|
||||||
|
@ -182,14 +182,14 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSaleableAndStockFromSpu(Map<Long, SkuInfoRespDTO> skuInfoMap,
|
private void checkSaleableAndStockFromSpu(Map<Long, ProductSkuRespDTO> skuInfoMap,
|
||||||
List<Item> items) {
|
List<Item> items) {
|
||||||
// sku 不存在
|
// sku 不存在
|
||||||
if (items.size() != skuInfoMap.size()) {
|
if (items.size() != skuInfoMap.size()) {
|
||||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_SKU_NOT_FOUND);
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_SKU_NOT_FOUND);
|
||||||
}
|
}
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
SkuInfoRespDTO skuInfoDTO = skuInfoMap.get(item.getSkuId());
|
ProductSkuRespDTO skuInfoDTO = skuInfoMap.get(item.getSkuId());
|
||||||
// sku禁用
|
// sku禁用
|
||||||
if (!Objects.equals(CommonStatusEnum.ENABLE.getStatus(), skuInfoDTO.getStatus())) {
|
if (!Objects.equals(CommonStatusEnum.ENABLE.getStatus(), skuInfoDTO.getStatus())) {
|
||||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_SKU_NOT_SALE);
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_SKU_NOT_SALE);
|
||||||
|
|
|
@ -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.market.api.price.dto.PriceCalculateRespDTO;
|
||||||
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
|
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.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.ProductSpuApi;
|
||||||
import cn.iocoder.yudao.module.product.api.spu.dto.SpuInfoRespDTO;
|
import cn.iocoder.yudao.module.product.api.spu.dto.SpuInfoRespDTO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
|
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
|
||||||
|
@ -60,21 +60,21 @@ class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||||
spuInfo.setId(1L);
|
spuInfo.setId(1L);
|
||||||
spuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
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数据
|
// mock 商品SkU数据
|
||||||
SkuInfoRespDTO skuInfoRespDTO = randomPojo(SkuInfoRespDTO.class, skuInfo -> {
|
ProductSkuRespDTO skuInfoRespDTO = randomPojo(ProductSkuRespDTO.class, skuInfo -> {
|
||||||
skuInfo.setId(1L);
|
skuInfo.setId(1L);
|
||||||
skuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
skuInfo.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
skuInfo.setStock(randomInteger());
|
skuInfo.setStock(randomInteger());
|
||||||
skuInfo.setSpuId(1L);
|
skuInfo.setSpuId(1L);
|
||||||
});
|
});
|
||||||
when(productSkuApi.getSkusByIds(Collections.singleton(1L))).thenReturn(Lists.newArrayList(skuInfoRespDTO));
|
when(productSkuApi.getSkuList(Collections.singleton(1L))).thenReturn(Lists.newArrayList(skuInfoRespDTO));
|
||||||
// mock 价格信息
|
// mock 价格信息
|
||||||
PriceCalculateRespDTO calculateRespDTO = randomPojo(PriceCalculateRespDTO.class, priceCalculateRespDTO -> {
|
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.setSkuId(1L);
|
||||||
item.setCount(2);
|
item.setCount(2);
|
||||||
priceCalculateRespDTO.setItems(Collections.singletonList(item));
|
priceCalculateRespDTO.getOrder().setItems(Collections.singletonList(item));
|
||||||
});
|
});
|
||||||
when(priceApi.calculatePrice(any())).thenReturn(calculateRespDTO);
|
when(priceApi.calculatePrice(any())).thenReturn(calculateRespDTO);
|
||||||
//mock 支付订单信息
|
//mock 支付订单信息
|
||||||
|
@ -103,7 +103,7 @@ class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||||
assertEquals(skuInfoRespDTO.getId(), tradeOrderItemDO.getSkuId());
|
assertEquals(skuInfoRespDTO.getId(), tradeOrderItemDO.getSkuId());
|
||||||
assertEquals(1L, tradeOrderItemDO.getUserId());
|
assertEquals(1L, tradeOrderItemDO.getUserId());
|
||||||
//价格
|
//价格
|
||||||
assertEquals(calculateRespDTO.getItems().get(0).getPresentPrice(), tradeOrderItemDO.getPresentPrice());
|
assertEquals(calculateRespDTO.getOrder().getItems().get(0).getPresentPrice(), tradeOrderItemDO.getPresentPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue