use of com.fp.mall.order.model.entity.OrderItemEntity in project FCLProject by FlowingCloudL.
the class OrderServiceImpl method submitOrder.
@GlobalTransactional
@Override
public Long submitOrder(Long uid, OrderSubmitDTO orderSubmitDTO) {
// 扣减库存
List<StockModifyBO> bos = orderSubmitDTO.getSkus().stream().map(dto -> {
StockModifyBO bo = new StockModifyBO();
BeanUtils.copyProperties(dto, bo);
return bo;
}).collect(Collectors.toList());
remoteStockService.decrStock(bos);
// 创建订单基本信息
OrderInfoEntity orderInfoEntity = new OrderInfoEntity();
BeanUtils.copyProperties(orderSubmitDTO, orderInfoEntity);
orderInfoEntity.setUserId(uid);
orderInfoEntity.setCreateTime(LocalDateTime.now());
orderInfoEntity.setUpdateTime(LocalDateTime.now());
orderInfoMapper.insert(orderInfoEntity);
// 创建订单项
for (OrderSubmitSkuDTO submitSkuDTO : orderSubmitDTO.getSkus()) {
// 远程调用获得订单项所需的SKU和SPU信息
OrderSpuBO orderSpuBO = remoteSpuService.getSpuBySkuId(submitSkuDTO.getSkuId());
// 生成订单项Entity
OrderItemEntity orderItemEntity = new OrderItemEntity();
// 设置订单id
orderItemEntity.setOrderId(orderInfoEntity.getOrderId());
// 设置spu部分
BeanUtils.copyProperties(orderSpuBO, orderItemEntity);
// 设置sku部分
BeanUtils.copyProperties(orderSpuBO.getSkuBO(), orderItemEntity);
// 设置单价
orderItemEntity.setSkuPrice(orderSpuBO.getSkuBO().getPrice());
// 设置数量
orderItemEntity.setSkuQuantity(submitSkuDTO.getCount());
// 计算订单项价格
orderItemEntity.setRealAmount(orderItemEntity.getSkuPrice().multiply(new BigDecimal(orderItemEntity.getSkuQuantity())));
orderItemMapper.insert(orderItemEntity);
}
return null;
}
Aggregations