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

import com.google.common.base.Throwables;
import com.zm.order.tool.server.constants.CommonConstants;
import com.zm.order.tool.server.hintnew.*;
import com.zm.order.tool.server.model.*;
import com.zm.order.tool.server.query.OrderQuery;
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.stereotype.Component;

import java.util.List;

/**
 * @author nianchang
 * @date 2021/12/21 4:13 下午
 */
@Component
public class NewHintManager {

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

    @Autowired
    private NewHintOrderDao hintOrderDao;

    @Autowired
    private NewHintOrderItemDao hintOrderItemDao;

    @Autowired
    private NewHintOrderDiscountDao discountDao;

    @Autowired
    private NewHintOrderPayDetailsDao payDetailsDao;

    @Autowired
    private NewHintOrderAddrDao orderAddrDao;

    @Autowired
    private NewHintOrderItemBatchingDao itemBatchingDao;

    @Autowired
    private NewHintOrderSelfTakeDao selfTakeDao;

    @Autowired
    private NewHintOrderExtendsDao extendsDao;

    /**
     * 扫描订单
     */
    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 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 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 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);
            payDetailsDao.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 List<Order> selectOrderById(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("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

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

    /**
     * 扫描订单
     */
    public List<Long> scanRespId(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("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

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

    /**
     * 扫描商品
     */
    public List<OrderDiscount> selectDiscountById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return discountDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描商品
     */
    public List<OrderExtends> selectExtendsById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            return extendsDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描商品
     */
    public List<OrderPayDetails> selectPayDetailsById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return payDetailsDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描商品
     */
    public List<OrderPayDetails> selectRespById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return payDetailsDao.selectRespById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描商品
     */
    public List<OrderAddr> selectAddressById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            return orderAddrDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描商品
     */
    public List<OrderItemBatching> selectItemBatchingById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            return itemBatchingDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 扫描商品
     */
    public List<PerformanceSelfTake> selectSelfTakeById(List<Long> idList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            return selfTakeDao.selectListById(idList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[scanOrder]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceOrder(List<Order> orderList, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            hintOrderDao.replaceList(orderList);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceDiscount(List<OrderDiscount> discounts, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            discountDao.replaceList(discounts);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceExtends(List<OrderExtends> orderExtends, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            extendsDao.replaceList(orderExtends);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceItems(List<OrderItem> orderItems, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.replaceList(orderItems);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replacePayDetails(List<OrderPayDetails> record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            payDetailsDao.replaceList(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceAddress(List<OrderAddr> record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            orderAddrDao.replaceList(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceBatching(List<OrderItemBatching> record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            itemBatchingDao.replaceList(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 新增
     */
    public void replaceSelfTake(List<PerformanceSelfTake> record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            selfTakeDao.replaceList(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[insert]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

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

    /**
     * 更新
     */
    public void update(OrderItem orderItem, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            hintOrderItemDao.update(orderItem);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 更新
     */
    public void update(OrderDiscount discount, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            discountDao.update(discount);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 更新
     */
    public void update(OrderPayDetails record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            payDetailsDao.update(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 更新
     */
    public void update(OrderAddr record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            orderAddrDao.update(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 更新
     */
    public void update(OrderExtends orderExtends, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            extendsDao.update(orderExtends);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 更新
     */
    public void update(OrderItemBatching record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            itemBatchingDao.update(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    /**
     * 更新
     */
    public void update(PerformanceSelfTake record, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            selfTakeDao.update(record);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[update]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int orderCount(OrderQuery query, int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER, dbIndex, tbIndex);
            return hintOrderDao.count(query);
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int itemCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM, dbIndex, tbIndex);
            return hintOrderItemDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int discountCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_DISCOUNT, dbIndex, tbIndex);
            return discountDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int payDetailCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_PAY_DETAILS, dbIndex, tbIndex);
            return payDetailsDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int batchingCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ITEM_BATCHING, dbIndex, tbIndex);
            return itemBatchingDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int addressCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_ADDRESS, dbIndex, tbIndex);
            return orderAddrDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int selfTakeCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_SELF_TAKE, dbIndex, tbIndex);
            return selfTakeDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }

    public int extendCount(int dbIndex, int tbIndex) {
        HintManager hintManager = null;
        try {
            hintManager = OrderHintManager.initScanHint(CommonConstants.LOGIC_TABLE_ORDER_EXTENDS, dbIndex, tbIndex);
            return extendsDao.count();
        } catch (Throwable throwable) {
            logger.error("NewHintManager[count]failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            throw new RuntimeException(throwable.getMessage());
        } finally {
            OrderHintManager.closeHint(hintManager);
        }
    }
}
