Search in sources :

Example 1 with OrderSubmitDTO

use of com.fp.mall.order.model.dto.OrderSubmitDTO 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;
}
Also used : OrderSubmitSkuDTO(com.fp.mall.order.model.dto.OrderSubmitSkuDTO) OrderService(com.fp.mall.order.service.OrderService) OrderInfoMapper(com.fp.mall.order.mapper.OrderInfoMapper) OrderItemDTO(com.fp.mall.order.model.dto.OrderItemDTO) Resource(javax.annotation.Resource) LocalDateTime(java.time.LocalDateTime) StockModifyBO(com.fp.api.mall.product.model.StockModifyBO) RemoteSpuService(com.fp.api.mall.product.service.RemoteSpuService) RemoteStockService(com.fp.api.mall.product.service.RemoteStockService) OrderSpuBO(com.fp.api.mall.product.model.OrderSpuBO) Collectors(java.util.stream.Collectors) OrderItemEntity(com.fp.mall.order.model.entity.OrderItemEntity) OrderSubmitDTO(com.fp.mall.order.model.dto.OrderSubmitDTO) BigDecimal(java.math.BigDecimal) List(java.util.List) GlobalTransactional(io.seata.spring.annotation.GlobalTransactional) Service(org.springframework.stereotype.Service) OrderItemMapper(com.fp.mall.order.mapper.OrderItemMapper) DubboReference(org.apache.dubbo.config.annotation.DubboReference) OrderInfoEntity(com.fp.mall.order.model.entity.OrderInfoEntity) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) OrderSubmitSkuDTO(com.fp.mall.order.model.dto.OrderSubmitSkuDTO) StockModifyBO(com.fp.api.mall.product.model.StockModifyBO) OrderInfoEntity(com.fp.mall.order.model.entity.OrderInfoEntity) OrderSpuBO(com.fp.api.mall.product.model.OrderSpuBO) OrderItemEntity(com.fp.mall.order.model.entity.OrderItemEntity) BigDecimal(java.math.BigDecimal) GlobalTransactional(io.seata.spring.annotation.GlobalTransactional)

Aggregations

OrderSpuBO (com.fp.api.mall.product.model.OrderSpuBO)1 StockModifyBO (com.fp.api.mall.product.model.StockModifyBO)1 RemoteSpuService (com.fp.api.mall.product.service.RemoteSpuService)1 RemoteStockService (com.fp.api.mall.product.service.RemoteStockService)1 OrderInfoMapper (com.fp.mall.order.mapper.OrderInfoMapper)1 OrderItemMapper (com.fp.mall.order.mapper.OrderItemMapper)1 OrderItemDTO (com.fp.mall.order.model.dto.OrderItemDTO)1 OrderSubmitDTO (com.fp.mall.order.model.dto.OrderSubmitDTO)1 OrderSubmitSkuDTO (com.fp.mall.order.model.dto.OrderSubmitSkuDTO)1 OrderInfoEntity (com.fp.mall.order.model.entity.OrderInfoEntity)1 OrderItemEntity (com.fp.mall.order.model.entity.OrderItemEntity)1 OrderService (com.fp.mall.order.service.OrderService)1 GlobalTransactional (io.seata.spring.annotation.GlobalTransactional)1 BigDecimal (java.math.BigDecimal)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 DubboReference (org.apache.dubbo.config.annotation.DubboReference)1 BeanUtils (org.springframework.beans.BeanUtils)1