Search in sources :

Example 1 with OrderCreateInfoDTO

use of com.whoiszxl.dto.OrderCreateInfoDTO in project shopzz by whoiszxl.

the class SubmitOrderStockUpdaterFactory method createCommand.

@Override
public StockUpdater createCommand(T parameter) {
    OrderCreateInfoDTO orderCreateInfoDTO = (OrderCreateInfoDTO) parameter;
    Map<Long, OrderItemDTO> orderItemDTOMap = new HashMap<>();
    for (OrderItemDTO item : orderCreateInfoDTO.getOrderItemList()) {
        orderItemDTOMap.put(item.getSkuId(), item);
    }
    return new SubmitOrderStockUpdater(productStockService, orderItemDTOMap);
}
Also used : OrderCreateInfoDTO(com.whoiszxl.dto.OrderCreateInfoDTO) OrderItemDTO(com.whoiszxl.dto.OrderItemDTO) HashMap(java.util.HashMap)

Example 2 with OrderCreateInfoDTO

use of com.whoiszxl.dto.OrderCreateInfoDTO in project shopzz by whoiszxl.

the class SubmitOrderStockUpdaterFactory method getProductSkuIds.

@Override
protected List<Long> getProductSkuIds(T parameter) {
    OrderCreateInfoDTO orderCreateInfoDTO = (OrderCreateInfoDTO) parameter;
    List<Long> productSkuIds = new ArrayList<>();
    for (OrderItemDTO item : orderCreateInfoDTO.getOrderItemList()) {
        productSkuIds.add(item.getSkuId());
    }
    return productSkuIds;
}
Also used : OrderCreateInfoDTO(com.whoiszxl.dto.OrderCreateInfoDTO) OrderItemDTO(com.whoiszxl.dto.OrderItemDTO) ArrayList(java.util.ArrayList)

Example 3 with OrderCreateInfoDTO

use of com.whoiszxl.dto.OrderCreateInfoDTO in project shopzz by whoiszxl.

the class OrderServiceImpl method submitOrder.

@Override
@Transactional
public String submitOrder(OrderSubmitVO orderSubmitVo) {
    // 0. 获取当前登录用户的信息
    MemberDetailDTO memberDetailDTO = memberFeignClient.getMemberInfo();
    // 1. 创建订单和订单详细条目
    OrderCreateInfo orderCreateInfo = createOrderInfo(memberDetailDTO, orderSubmitVo);
    // 2. 验证提交的价格和计算的价格是否一致
    if (orderSubmitVo.getTotalAmount().compareTo(orderCreateInfo.getPayPrice()) != 0) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("价格计算异常"));
    }
    // 3. 订单与订单详细条目入库
    Order order = orderCreateInfo.getOrder();
    this.save(order);
    orderItemService.saveBatch(orderCreateInfo.getOrderItemList());
    // 4. 创建一个操作日志订单状态管理器,在订单状态流转到待付款状态时记录操作记录
    orderStateManager.create(order);
    // 5. 通知库存中心订单提交了,锁定库存中心的SKU库存
    OrderCreateInfoDTO orderRequestParam = orderCreateInfo.clone(OrderCreateInfoDTO.class);
    ResponseResult updateInventoryResult = inventoryFeignClient.notifySubmitOrderEvent(orderRequestParam);
    if (!updateInventoryResult.isOk()) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("库存不足"));
    }
    // 6. 使用优惠券
    ResponseResult<Boolean> useCouponResult = promotionFeignClient.useCoupon(orderSubmitVo.getCouponId());
    if (!useCouponResult.isOk()) {
        log.error("优惠券使用失败:{}", useCouponResult.getMessage());
    }
    // 7. 发送Kafka消息到WMS中心进行处理
    // 7.1 通过商品的SKU ID查询到货位库存的明细条目,并进行遍历,一个SKU可能在多个货位上
    // 7.2 创建出需要拣货的条目和发货的条目并进行批量入库
    // 7.4 更新wms中心的库存
    OrderCreateInfoDTO orderCreateInfoDTO = new OrderCreateInfoDTO();
    BeanCopierUtils.copyProperties(orderCreateInfo, orderCreateInfoDTO);
    MQSender kafkaSender = mqSenderFactory.get(MQEnum.KAFKA);
    kafkaSender.send(MQConstants.SUBMIT_ORDER_QUEUE, JsonUtil.toJson(orderCreateInfoDTO));
    return order.getOrderSn();
}
Also used : Order(com.whoiszxl.entity.Order) MQSender(com.whoiszxl.mq.MQSender) OrderCreateInfoDTO(com.whoiszxl.dto.OrderCreateInfoDTO) OrderCreateInfo(com.whoiszxl.entity.vo.OrderCreateInfo) ResponseResult(com.whoiszxl.bean.ResponseResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with OrderCreateInfoDTO

use of com.whoiszxl.dto.OrderCreateInfoDTO in project shopzz by whoiszxl.

the class SubmitOrderConsumer method submitOrderSub.

@KafkaListener(topics = MQConstants.SUBMIT_ORDER_QUEUE, groupId = "default-group")
public void submitOrderSub(ConsumerRecord<String, String> record, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic, Consumer consumer) {
    log.info("订阅到新的提交订单,开始处理, 主题为:{}, 消息值为:{}", topic, record.value());
    OrderCreateInfoDTO orderCreateInfoDTO = JsonUtil.fromJson(record.value(), OrderCreateInfoDTO.class);
    List<OrderItemDTO> orderItemList = orderCreateInfoDTO.getOrderItemList();
    for (OrderItemDTO orderItem : orderItemList) {
        // 7.1 通过商品的SKU ID查询到货位库存的明细条目,并进行遍历,一个SKU可能在多个货位上
        SaleDeliveryScheduleResult scheduleResult = saleDeliveryScheduler.schedule(orderItem);
        List<SaleDeliveryOrderPickingItem> pickingItems = scheduleResult.getPickingItems();
        // 7.2 创建出需要拣货的条目和发货的条目并进行批量入库
        saleDeliveryPickingItemService.saveBatch(pickingItems);
        // 7.3 更新wms中心的库存
        WmsStockUpdater stockUpdater = wmsStockUpdaterFactory.create(WmsStockUpdateEventConstants.SUBMIT_ORDER, scheduleResult);
        stockUpdater.update();
    }
}
Also used : WmsStockUpdater(com.whoiszxl.stock.WmsStockUpdater) OrderCreateInfoDTO(com.whoiszxl.dto.OrderCreateInfoDTO) OrderItemDTO(com.whoiszxl.dto.OrderItemDTO) SaleDeliveryOrderPickingItem(com.whoiszxl.entity.SaleDeliveryOrderPickingItem) SaleDeliveryScheduleResult(com.whoiszxl.entity.schedule.SaleDeliveryScheduleResult) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

OrderCreateInfoDTO (com.whoiszxl.dto.OrderCreateInfoDTO)4 OrderItemDTO (com.whoiszxl.dto.OrderItemDTO)3 ResponseResult (com.whoiszxl.bean.ResponseResult)1 Order (com.whoiszxl.entity.Order)1 SaleDeliveryOrderPickingItem (com.whoiszxl.entity.SaleDeliveryOrderPickingItem)1 SaleDeliveryScheduleResult (com.whoiszxl.entity.schedule.SaleDeliveryScheduleResult)1 OrderCreateInfo (com.whoiszxl.entity.vo.OrderCreateInfo)1 MQSender (com.whoiszxl.mq.MQSender)1 WmsStockUpdater (com.whoiszxl.stock.WmsStockUpdater)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1 Transactional (org.springframework.transaction.annotation.Transactional)1