Asynchronous processing operations <record>

Implementation class there are too many logical, does not affect the return of some of the logic operations may be asynchronous to accelerate the processing speed and efficiency of the front end access interface

Directly on the part of the code

Implementation class method:

  / ** 
     * Merchant confirm that the user has paid 
     * 
     * @param orderId order ID 
     * @param confirmStatus confirm the status
      * / 
    @Override 
    public  void confirmUserPayed (orderId String, String confirmStatus) { 
        CommonOrder userOrder = commonOrderRepository.findById (orderId) .orElse ( null ); 
        DomainUtils.checkNull (userOrder, "the order does not exist" );
         IF ! ( OrderStatus.USER_CONFIRM_PAYED.equals (userOrder.getOrderStatus ())) {
             the throw  new new CommonException ( "user has not yet confirmed payment, payment can not be confirmed or canceled." ); 
        }
        // Analyzing submission status 
        Switch (ConfirmStatus.valueOf (confirmStatus)) {
             Case SUCCESS: 
                userOrder.setOrderStatus (OrderStatus.WAITSEND); // wait state delivery 
                BREAK ;
             Case the CANCEL: 
                userOrder.setOrderStatus (OrderStatus.CONCEL); 
                // Review billing status 
                CommonBill Bill = commonBillRepository.findByOrderId (the orderId); 
                DomainUtils.checkNull (Bill, "does not correspond to the billing inquiry" ); 
                bill.setBillStatus (BillStatus.CANCEL); // cancel bill 
                commonBillRepository.save (Bill);
                 //Send a message to the user 
                sendMessageService.sendConfirmOrderFialMsg (userOrder, bill.getFormId (), " the business has confirmed the order amount is not credited into account, the order has been canceled", "Hui Shopping Center commercial" ,
                         "If in doubt, consult the business." );
                 BREAK ;
             default :
                 the throw  new new CommonException ( "incoming state error" ); 
        } 
        // perform the update 
        commonOrderRepository.save (userOrder);
         // asynchronous processing sales and inventory 
        the try {
             handlerNewestStore.handlerCommonPayed (userOrder); 
        } the catch (Exception E) { 
            log.error ( "exception processing Order Stock ID:% s", UserOrder.getId ()); 
        } 
    } 

asynchronous processing services:
package com.yikesong.favourablelife.service.async;

import com.yikesong.favourablelife.dao.NewestRepository;
import com.yikesong.favourablelife.dao.OrderItemRepository;
import com.yikesong.favourablelife.exception.CommonException;
import com.yikesong.favourablelife.pojo.entity.Newest;
import com.yikesong.favourablelife.pojo.entity.OrderItem;
import com.yikesong.favourablelife.pojo.entity.baseclass.Order;
import com.yikesong.favourablelife.pojo.enums.CartHandlerType;
import com.yikesong.favourablelife.service.IShopCartService;
import com.yikesong.favourablelife.utils.DomainUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

/**
 * 处理商品销量 库存
 *
 * @Author xs
 * @Date 2019/7/12 11:04
 */
@Slf4j
@Component
@Transactional
public class HandlerNewestStore {

    @Autowired
    private OrderItemRepository orderItemRepository;
    @Autowired
    private NewestRepository newestRepository;
    @Autowired
    private IShopCartService shopCartService;

    /**
     * Asynchronous processing of goods inventory 
     * 
     * @param the Order Orders 
     * / 
                DomainUtils.checkNull (Newest, "the absence of goods - product inventory process");
    @Async 
    public void handlerCommonPayed (the Order Order) { 
        // Check Order Entry 
        List <the OrderItem> orderItemList = orderItemRepository.findByOrderId (order.getId ()); 
        // traversal order entry 
        if (orderItemList == null || orderItemList.size ( ) <= 0) { 
            the throw new new CommonException (String.format ( "abnormality warning !! Order Order entry ID:% S", order.getId ())); 
        } 
        for (the orderItem orderItem: orderItemList) { 
            the try { 
                Newest Newest = newestRepository .findById (orderItem.getGoodsId ()) orElse (null);. 
                // Save inventory 
                int = STORECOUNT newest.getStoreCount () - orderItem.getNum (); 
                IF (STORECOUNT <= 0) {
                    = 0 STORECOUNT; 
                    // handling cart sold 
                    shopCartService.handlerSaleOut (orderItem.getGoodsId (), CartHandlerType.SALEOUT, null); 
                } 
                newest.setStoreCount (STORECOUNT); 
                // increase sales 
                int saleCount = (newest.getSaleCount () = null 0 =:? newest.getSaleCount ()) + orderItem.getNum (); 
                newest.setSaleCount (saleCount); 
                newestRepository.save (Newest); 
            } the catch (exception E) { 
                log.error ( "exception handling merchandise inventory item ID : {} ", orderItem.getGoodsId ()); 
            } 
        } 
    } 

}

 
 

 



 

Guess you like

Origin www.cnblogs.com/aijiajia1314/p/11407348.html