package com.zm.order.tool.server.manager;


import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.zm.order.tool.server.constants.CommonConstants;
import com.zm.order.tool.server.dao.*;
import com.zm.order.tool.server.hint.*;
import com.zm.order.tool.server.model.*;
import com.zm.order.tool.server.query.*;
import com.zm.order.tool.server.sharding.OrderHintManager;
import org.apache.shardingsphere.api.hint.HintManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Author 陈标
 * @Date 2020/2/28 15:36
 */
@Component
@SuppressWarnings("all")
public class CommonManager {

    private static final Logger logger = LoggerFactory.getLogger(CommonManager.class);

    @Autowired
    private HintOrderOperationDao orderOperationDao;
    @Autowired
    private HintOrderPushLogsDao orderPushLogsDao;
    @Autowired
    private HintOrderDao hintOrderDao;
    @Autowired
    private HintOrderDiscountDao hintOrderDiscountDao;
    @Autowired
    private HintOrderItemDao hintOrderItemDao;
    @Autowired
    private OrderDiscountDao orderDiscountDao;
    @Autowired
    private OrderItemDao orderItemDao;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private RefundDao refundDao;
    @Autowired
    private RefundItemDao refundItemDao;
    @Autowired
    private HintOrderPayDetailsDao hintOrderPayDetailsDao;
    @Autowired
    private OrderPayDetailsDao orderPayDetailsDao;
    @Autowired
    private HintItemBatchingDao hintBatchingDao;
    @Autowired
    private HintOrderExtendsDao hintExtendsDao;
    @Autowired
    private HintSelfTakeDao selfTakeDao;
    @Autowired
    private HintOrderAddrDao addrDao;

    @Autowired
    private HintOrderCommentDao commentDao;
    @Autowired
    private HintOrderItemCommentDao itemCommentDao;

    @Value("${new.sharding.db.size}")
    private int dbSize;

    @Value("${new.sharding.tb.size}")
    private int tbSize;

    /**
     * 扫描操作订单记录
     */
    public List<OrderOperation> scanOrderOperation(OrderOperationQuery orderOperationQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_OPERATIONS, dbIndex, tbIndex);
            return orderOperationDao.selectList(orderOperationQuery);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderOperation] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描操作订单记录
     */
    public List<Long> selectOrderOperation(OrderOperationQuery orderOperationQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_OPERATIONS, dbIndex, tbIndex);
            return orderOperationDao.selectIdList(orderOperationQuery);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderOperation] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 删除数据
     */
    public int deleteOrderOperationSize(OrderOperationQuery orderOperationQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        int i = 0;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_OPERATIONS, dbIndex, tbIndex);
            i = orderOperationDao.deleteListSize(orderOperationQuery);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrderOperationSize] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
        return i;
    }

    /**
     * 更新时间
     */
    public int updateOrderUpdatedAt(OrderOperationQuery orderOperationQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        int i = 0;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            i = hintOrderDao.updateUpdatedAt(orderOperationQuery);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrderUpdatedAt] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
        return i;
    }

    /**
     * 删除数据
     */
    public int deleteOrderPushLogsSize(OrderOperationQuery orderOperationQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        int i = 0;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PUSH_LOGS, dbIndex, tbIndex);
            i = orderPushLogsDao.deleteListSize(orderOperationQuery);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrderPushLogsSize] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
        return i;
    }

    /**
     * 删除数据
     */
    public void deleteOrderOperation(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_OPERATIONS, dbIndex, tbIndex);
            orderOperationDao.deleteList(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderOperation] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描支付信息
     */
    public List<OrderPayDetails> scanOrderPayDetails(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.scan(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描支付信息
     */
    public List<OrderPayDetails> scanPayDetailsId(OrderPayDetailsQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.selectIdList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 删除支付信息
     */
    public void deletePayDetailsById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            hintOrderPayDetailsDao.delete(list);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanOrderDeleted(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectDeleted(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanOrder(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.scan(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }
    /**
     * 扫描订单
     */
    public List<Order> selectWuyin(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectWuyin(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanAppointSellerList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.scanAppointSellerList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 倒序扫描订单
     */
    public List<Order> scanOrderDesc(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.scan(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Long> scanOrderId(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.scanId(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanOrderByOrderNo(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectByOrderNo(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> listOrder(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[listOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> listOrderById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[listOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> listOrderBySyncFlag(List<Long> idList, int dbIndex, int tbIndex, Integer syncFlag, List<Integer> deleteTypeList) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectListBySyncFlag(idList, syncFlag, deleteTypeList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[listOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateOrder(Order order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateFlag(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateEncrypt(Date start, Date end, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateEncrypt(start, end);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateEncryptbyId(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateEncryptById(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void batchUpdateSyncFlag(List<Long> idList, Integer syncFlag, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateSyncFlag(idList, syncFlag);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateStoreOrderNo(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateStoreOrderNo(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updatePayBizType(Integer bizType, List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            hintOrderPayDetailsDao.updateBizType(bizType, orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updatePayBizTypeBaking(Integer bizType, List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            hintOrderPayDetailsDao.updateBizTypeBaking(bizType, orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateBizType(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateBizType(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateBizTypeBaking(List<Order> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateBizTypeBaking(list);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateOrderCompleteStatus(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateStatus(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateBizTypeForItem(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateBizType(orderNoList, 8);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateBizTypeForItem] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateBizTypeForDiscount(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateBizType(orderNoList, 8);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateBizTypeForDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单优惠
     */
    public List<OrderDiscount> scanOrderDiscount(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.list(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单支付
     */
    public List<OrderPayDetails> scanPayByOrderNo(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.scanByOrderNo(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanPayByOrderNo] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanOrderById(Long orderId, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectListById(Lists.newArrayList(orderId));
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanOrderByIdList(List<Long> orderIds, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectListById(orderIds);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> scanOrderRespExt(List<Long> orderIds, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.selectListRespExt(orderIds);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void batchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdateDate(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单优惠
     */
    public List<OrderDiscount> scanOrderDiscount1(OrderDiscountQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.selectList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单优惠id
     */
    public List<Long> scanOrderDiscountId(OrderDiscountQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.selectIdList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderDiscountId] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 根据订单优惠id 更新updatedAt
     */
    public void updateOrderDiscountById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateByIdList(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrderDiscountById] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 修改订单
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void updateOrders(AdminUpdateBody body, OrderItemQuery itemQuery, OrderDiscountQuery discountQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.update(body);
            hintOrderItemDao.update(itemQuery);
            hintOrderDiscountDao.update(discountQuery);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrders] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateOrder(AdminUpdateBody body, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDao.update(body);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void batchUpdateOrderItemAndDiscount(List<Order> orderList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateList(orderList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单中商品快照
     * 勿动
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdateOrderItemInfo(List<Long> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdateItemInfo(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单信息
     * 勿动
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdateOrderInfo(List<Order> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdateOrderInfo(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单信息-卤味迁移到烘焙
     * 勿动
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdateOrderBaking(List<Order> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateBatchOrderBaking(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 巴莉甜甜迁移批量更新订单信息
     * 勿动
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     */
    public void updateBatchOrderInfo(List<Order> order, int dbIndex, int tbIndex, Long sellerId) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.updateBatchOrderInfo(order, sellerId);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }
    /**
     * 批量更新订单优惠信息
     * @param orderDiscountList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void updateDiscountBatch(List<OrderDiscount> orderDiscountList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateBatch(orderDiscountList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单优惠信息
     * @param orderDiscountList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void updateDiscountBatchBaking(List<OrderDiscount> orderDiscountList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateBatchBaking(orderDiscountList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updatePayBatchBaking(List<OrderPayDetails> payList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            hintOrderPayDetailsDao.updateBatchOrderBaking(payList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updatePayBatchBaking] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单支付字段
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdatePayDetailInfo(List<Order> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdatePayDetailInfo(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量回滚订单
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdateOrderRollBack(List<Order> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdateOrderRollBack(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量回滚订单
     * @param order
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdateOrder(List<Order> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdateOrder(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单中商品类型
     * 勿动
     * @param list
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void batchUpdateItemType(List<OrderItem> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateItemType(list);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 批量更新订单中商品类型
     * 勿动
     * @param list
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2021/2/19 2:11 下午
     */
    public void updateBizTypeRollBack(List<OrderItem> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateBizTypeRollBack(list);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void batchUpdatePayDetailsInfo(List<Order> order, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchUpdatePayDetails(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void batchDeleteOrder(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.batchDeleted(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单优惠
     */
    public List<OrderDiscount> listOrderDiscountById(OrderDiscountQuery orderDiscountQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.selectListById(orderDiscountQuery);
        } catch (Throwable throwable) {
            logger.error("OrderManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateItemBizType(List<String> orderNoList, Integer bizType, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateBizType(orderNoList, bizType);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateItemBizTypeSellerId(List<OrderItem> newOrderItemList, Integer bizType, Long sellerId, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateBizTypeSellerId(newOrderItemList, bizType, sellerId);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateItemDeleted(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateDeleted(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateDiscountDeleted(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateDeleted(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateDiscountSellerId(List<OrderDiscount> orderDiscountList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateSellerId(orderDiscountList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateItemUserId(String orderNo, Long userId, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.updateUserId(userId, orderNo);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateDiscountUserId(String orderNo, Long userId, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.updateUserId(userId, orderNo);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateItemBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void updateDiscountType(List<OrderDiscount> discountList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.batchUpdateDiscountType(discountList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateDiscountBizType] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteOrder(Order order, List<OrderItem> itemList, List<OrderDiscount> discountList) {
        try {
            if (Objects.equals(order.getIsDeleted(), -100)) {
                return;
            }
            // 软删旧订单
            orderDao.delete(order.getId(), order.getUserId(), -100);
            // 软删旧orderItem
            if (!CollectionUtils.isEmpty(itemList)) {
                List<Long> itemIdList = itemList.stream().map(OrderItem::getId).collect(Collectors.toList());
                orderItemDao.deletes(itemIdList, order.getUserId(), -100);
            }
            // 软删orderDiscount
            if (!CollectionUtils.isEmpty(discountList)) {
                List<Long> discountIdList = discountList.stream().map(OrderDiscount::getId).collect(Collectors.toList());
                orderDiscountDao.deletes(discountIdList, order.getUserId(), -100);
            }
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        }
    }

    /**
     * 物理删除订单(慎用)
     *
     * @param idList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2020/12/18 5:41 PM
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteOrder(List<Long> idList,int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.physicalDeleted(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 物理删除商品(慎用)
     *
     * @param orderNoList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2020/12/18 5:41 PM
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteItem(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.physicalDeleted(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }
    /**
     * 物理删除商品(慎用)
     *
     * @param orderNoList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2020/12/18 5:41 PM
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteItemTest(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.physicalDeletedTest(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 物理删除优惠(慎用)
     *
     * @param orderNoList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2020/12/18 5:41 PM
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteDiscount(List<String> orderNoList,int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.physicalDeleted(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public boolean isSame(Long newUserId, Long oldUserId) {

        long newDb = newUserId % dbSize;

        long newTb = (newUserId / dbSize) % tbSize;

        long oldDb = oldUserId % dbSize;

        long oldTb = (oldUserId / dbSize) % tbSize;

        return (Objects.equals(newDb, oldDb) && Objects.equals(newTb, oldTb));

    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void updateRefund(Refund refund, List<RefundItem> refundItems, Long userId) {

        try {
        } catch (Throwable throwable) {
            logger.error("CommonManager[updateRefund] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        }

    }

    /**
     * 扫描订单商品
     */
    public List<OrderItem> scanOrderItem(List<String> orderNoList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            return hintOrderItemDao.list(orderNoList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderItem] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void insertOrderPayDetails(OrderPayDetails orderPayDetails, Order order) {
        try {
            orderPayDetailsDao.insert(orderPayDetails);
            orderDao.updatePayDetail(order);
        } catch (Throwable throwable) {
            logger.error("CommonManager[insertOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        }
    }

    /**
     * 扫描订单优惠
     */
    public List<OrderDiscount> listTbOrderDiscount(OrderDiscountQuery orderDiscountQuery, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.selectList(orderDiscountQuery);
        } catch (Throwable throwable) {
            logger.error("OrderManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 item start------------------------------------------------
     *
     * 扫描订单商品
     */
    public List<Long> scanItemIdList(OrderItemQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            return hintOrderItemDao.scan(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderItem]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单商品
     */
    public List<OrderItem> queryItemListById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            return hintOrderItemDao.listById(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderItem] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderItem> scanItemList(OrderItemQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            return hintOrderItemDao.scanList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderItem]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void itemBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[itemBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 item end--------------------------------------------------
     * -----------------------------------------------数据扫描 discount start--------------------------------------------
     */

    /**
     * 扫描订单优惠
     *
     * @param query
     * @param dbIndex
     * @param tbIndex
     * @return
     */
    public List<Long> scanDiscountIdList(OrderDiscountQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.scan(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanDiscountIdList]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单优惠
     *
     * @param query
     * @param dbIndex
     * @param tbIndex
     * @return
     */
    public List<OrderDiscount> queryDiscountListById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.listById(list);
        } catch (Throwable throwable) {
            logger.error("OrderManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单优惠
     *
     * @param query
     * @param dbIndex
     * @param tbIndex
     * @return
     */
    public List<OrderDiscount> scanDiscountList(OrderDiscountQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.selectList(query);
        } catch (Throwable throwable) {
            logger.error("OrderManager[scanOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void discountBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            hintOrderDiscountDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[discountBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 discount end----------------------------------------------
     * -----------------------------------------------数据扫描 payDetails start------------------------------------------
     */

    /**
     * 扫描支付信息
     */
    public List<Long> scanPayDetailsIdList(OrderPayDetailsQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.scanId(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描支付信息
     */
    public List<OrderPayDetails> queryPayDetailsListById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.listById(list);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描支付信息
     */
    public List<OrderPayDetails> scanPayDetailsList(OrderPayDetailsQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.scanList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanOrderPayDetails] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void payDetailsBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            hintOrderPayDetailsDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[payDetailsBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 payDetails end----------------------------------------------
     * -----------------------------------------------数据扫描 batching start------------------------------------------
     */

    public List<Long> scanBatchingIdList(OrderItemQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            return hintBatchingDao.scanId(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanBatchingIdList]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderItemBatching> queryBatchingListById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            return hintBatchingDao.listById(list);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanBatchingIdList]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderItemBatching> scanBatchingList(OrderItemQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            return hintBatchingDao.scanList(query);
        } catch (Throwable throwable) {
            logger.error("CommonManager[scanBatchingList]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void batchingBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            hintBatchingDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[batchingBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 batching end----------------------------------------------
     * -----------------------------------------------数据扫描 extends start------------------------------------------
     */

    public List<Long> scanExtendsIdList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            return hintExtendsDao.scanId(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanExtendsIdList]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderExtends> queryExtendsListById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            return hintExtendsDao.listById(list);
        } catch (Throwable e) {
            logger.error("CommonManager[queryExtendsListById]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderExtends> scanExtendsList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            return hintExtendsDao.scanList(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanExtendsList]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void extendsBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            hintExtendsDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[extendsBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 extends end----------------------------------------------
     * -----------------------------------------------数据扫描 selfTake start------------------------------------------
     */

    public List<Long> scanSelfTakeIdList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            return selfTakeDao.scanId(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanSelfTakeIdList]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<PerformanceSelfTake> querySelfTakeListById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            return selfTakeDao.listById(list);
        } catch (Throwable e) {
            logger.error("CommonManager[querySelfTakeListById]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<PerformanceSelfTake> scanSelfTakeList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            return selfTakeDao.scanList(query);
        } catch (Throwable e) {
            logger.error("CommonManager[querySelfTakeListById]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void selfTakeBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            selfTakeDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[selfTakeBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 selfTake end----------------------------------------------
     * -----------------------------------------------数据扫描 orderAddr end---------------------------------------------
     */

    public List<Long> scanOrderAddrIdList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            return addrDao.scanId(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanOrderAddrIdList]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderAddr> queryOrderAddrListById(List<Long> list, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            return addrDao.listById(list);
        } catch (Throwable e) {
            logger.error("CommonManager[queryOrderAddrListById]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderAddr> scanOrderAddrList(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            return addrDao.scanList(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanOrderAddrList]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public void addrBatchUpdateDate(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            addrDao.batchUpdateDate(idList);
        } catch (Throwable e) {
            logger.error("CommonManager[addrBatchUpdateDate]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * -----------------------------------------------数据扫描 orderAddr end----------------------------------------------
     */

    public List<OrderComment> scanComment(OrderCommentQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_COMMENT, dbIndex, tbIndex);
            return commentDao.scan(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanComment]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public List<OrderItemComment> scanItemComment(OrderItemCommentQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_COMMENT, dbIndex, tbIndex);
            return itemCommentDao.scan(query);
        } catch (Throwable e) {
            logger.error("CommonManager[scanItemComment]failed, cause by:{}", e);
            throw new RuntimeException(e.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<Order> checkOrder(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.checkOrder();
        } catch (Throwable throwable) {
            logger.error("CommonManager[checkOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<OrderItem> checkOrderItem(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            return hintOrderItemDao.checkItem();
        } catch (Throwable throwable) {
            logger.error("CommonManager[checkOrderItem] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<OrderDiscount> checkOrderDiscount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return hintOrderDiscountDao.checkDiscount();
        } catch (Throwable throwable) {
            logger.error("CommonManager[checkOrderDiscount] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描订单
     */
    public List<OrderPayDetails> checkOrderPay(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return hintOrderPayDetailsDao.checkPay();
        } catch (Throwable throwable) {
            logger.error("CommonManager[checkOrderPay] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 物理删除订单(慎用)
     *
     * @param idList
     * @param dbIndex
     * @param tbIndex
     * @return:
     * @Date: 2020/12/18 5:41 PM
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteOrderTest(List<Long> idList,int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.physicalDeletedTest(idList);
        } catch (Throwable throwable) {
            logger.error("CommonManager[deleteOrder] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }
}
