Search in sources :

Example 6 with ResponseResult

use of com.whoiszxl.bean.ResponseResult in project shopzz by whoiszxl.

the class OrderServiceImpl method getOrderConfirmData.

@Override
public OrderConfirmVO getOrderConfirmData() {
    OrderConfirmVO result = new OrderConfirmVO();
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    CompletableFuture<Void> itemAndStockFuture = CompletableFuture.supplyAsync(() -> {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        // 1. 获取购物车中所有的选中的sku商品
        ResponseResult<List<CartDTO>> cartResult = cartFeignClient.getCheckedCartItem();
        List<CartDTO> checkedCartList = cartResult.getData();
        result.setCheckItem(checkedCartList);
        return checkedCartList;
    }, executor).thenAcceptAsync(checkedCartList -> {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        // 2. 获取库存信息
        List<Long> skuIds = checkedCartList.stream().map(CartDTO::getSkuId).collect(Collectors.toList());
        ResponseResult<List<InventorySkuDTO>> stockResult = inventoryFeignClient.getSaleStockQuantity(skuIds);
        List<InventorySkuDTO> stockSkuList = stockResult.getData();
        Map<Long, Integer> stock = stockSkuList.stream().collect(Collectors.toMap(InventorySkuDTO::getSkuId, InventorySkuDTO::getQuantity));
        result.setStocks(stock);
    }, executor);
    // 3. 获取所有收货地址
    CompletableFuture<Void> addressFuture = CompletableFuture.runAsync(() -> {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        List<MemberAddressDTO> addressList = memberFeignClient.listMemberAddress();
        result.setMemberAddressDTOS(addressList);
    }, executor);
    // 4. 获取优惠券信息
    CompletableFuture<Void> couponFuture = CompletableFuture.runAsync(() -> {
        RequestContextHolder.setRequestAttributes(requestAttributes);
        List<MemberCouponDTO> myCouponList = promotionFeignClient.getMyCoupon();
        result.setMyCoupons(myCouponList);
    }, executor);
    // 8. 执行异步任务
    try {
        CompletableFuture.allOf(itemAndStockFuture, addressFuture, couponFuture).get();
    } catch (Exception e) {
        log.error("获取确认订单界面数据失败", e);
    }
    return result;
}
Also used : OrderConfirmVO(com.whoiszxl.entity.vo.OrderConfirmVO) RequestAttributes(org.springframework.web.context.request.RequestAttributes) ResponseResult(com.whoiszxl.bean.ResponseResult) List(java.util.List)

Example 7 with ResponseResult

use of com.whoiszxl.bean.ResponseResult in project shopzz by whoiszxl.

the class OrderFeignClientImpl method notifyDcPaySuccess.

@Override
public ResponseResult<Boolean> notifyDcPaySuccess(List<Long> orderIds) {
    // 1. 更新订单到发货状态
    List<Order> orderList = orderIds.stream().map(orderId -> {
        Order order = new Order();
        order.setId(orderId);
        order.setOrderStatus(OrderStatusConstants.WAIT_FOR_DELIVERY);
        order.setUpdatedBy("admin");
        return order;
    }).collect(Collectors.toList());
    boolean updateFlag = orderService.updateBatchById(orderList);
    for (Long orderId : orderIds) {
        OrderInfoDTO orderInfo = orderService.getOrderInfo(orderId);
        // 2. 清空购物车
        ResponseResult<Boolean> clearCartResult = cartFeignClient.clearCheckedCartByMemberId(orderInfo.getMemberId());
        if (!clearCartResult.getData()) {
            log.error("下单成功,但是清空购物车失败了");
        }
        // 3. 通知库存中心更新库存
        inventoryFeignClient.notifyPayOrderEvent(orderInfo);
        // 4. 通知WMS订单支付成功,更新WMS中心库存,WMS新增出库单
        wmsFeignClient.notifyPayOrderSuccess(orderInfo);
        // 5. 更新会员中心等级与积分
        memberFeignClient.notifyPayOrderSuccess(orderInfo.getMemberId(), orderInfo.getTotalAmount());
    }
    return ResponseResult.buildByFlag(updateFlag);
}
Also used : Order(com.whoiszxl.entity.Order) com.whoiszxl.feign(com.whoiszxl.feign) ResponseResult(com.whoiszxl.bean.ResponseResult) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Autowired(org.springframework.beans.factory.annotation.Autowired) OrderInfoDTO(com.whoiszxl.dto.OrderInfoDTO) Order(com.whoiszxl.entity.Order) OrderService(com.whoiszxl.service.OrderService) OrderStatusConstants(com.whoiszxl.constants.OrderStatusConstants) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) OrderInfoDTO(com.whoiszxl.dto.OrderInfoDTO)

Aggregations

ResponseResult (com.whoiszxl.bean.ResponseResult)7 Order (com.whoiszxl.entity.Order)4 List (java.util.List)4 OrderStatusConstants (com.whoiszxl.constants.OrderStatusConstants)3 OrderService (com.whoiszxl.service.OrderService)3 Collectors (java.util.stream.Collectors)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 OrderInfoDTO (com.whoiszxl.dto.OrderInfoDTO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 OrderPayTypeConstants (com.whoiszxl.constants.OrderPayTypeConstants)1 OrderPayCommand (com.whoiszxl.cqrs.command.OrderPayCommand)1 OrderSubmitCommand (com.whoiszxl.cqrs.command.OrderSubmitCommand)1 OrderCheckDTO (com.whoiszxl.cqrs.dto.OrderCheckDTO)1 OrderCreateInfoDTO (com.whoiszxl.cqrs.dto.OrderCreateInfoDTO)1 CartDetailApiResponse (com.whoiszxl.cqrs.response.CartDetailApiResponse)1 CartItemVO (com.whoiszxl.cqrs.response.CartItemVO)1 DozerUtils (com.whoiszxl.dozer.DozerUtils)1 com.whoiszxl.dto (com.whoiszxl.dto)1