@Override
  public StockOrder verifyStockOrder(StockOrder stockOrder) {
    logger.debug("call verifyStockOrder");
    StockOrder orderParam = stockOrder;
    stockOrder = orderDao.findStockOrderById(stockOrder.getId());
    stockOrder.setStatus(Status.VERIFY);
    stockOrder.setLastModifyBy(orderParam.getLastModifyBy());
    stockOrder.setLastModifyTime(orderParam.getLastModifyTime());
    orderDao.updateStockOrder(stockOrder);
    for (StockOrderItem item : stockOrder.getItems()) {
      logger.debug("item id: " + item.getId() + ", book id: " + item.getBook().getId());
      BookRepository repository =
          bookRepositoryDao.findByStoreBook(stockOrder.getStore(), item.getBook());
      logger.debug("" + repository);
      if (repository == null) {

        // add a new book repository
        logger.debug("add a new repository");
        repository = new BookRepository();
        repository.setStore(stockOrder.getStore());
        repository.setBook(item.getBook());
        repository.setDate(new Date());
        repository.setNum(item.getNum());
        bookRepositoryDao.insert(repository);
      } else {

        // increase the book repository
        logger.debug("update repository");
        repository.setNum(repository.getNum() + item.getNum());
        bookRepositoryDao.update(repository);
      }
    }
    return stockOrder;
  }
 @Override
 public QuotaOrder addQuotaOrder(QuotaOrder quotaOrder) throws BookNotExistsException {
   logger.debug("call addQuotaOrder");
   quotaOrder.setTotalPrice(new BigDecimal(0.00));
   for (QuotaOrderItem item : quotaOrder.getItems()) {
     Book book = bookDao.get(item.getBook().getId());
     if (book == null) {
       throw new BookNotExistsException("book id: " + item.getBook().getId());
     }
     item.setPrice(book.getPrice());
     quotaOrder.setTotalPrice(
         item.getPrice().multiply(new BigDecimal(item.getNum())).add(quotaOrder.getTotalPrice()));
   }
   orderDao.insertQuotaOrder(quotaOrder);
   return null;
 }
 @Override
 public DrawOrder addDrawOrder(DrawOrder drawOrder) throws BookRepositoryOutOfBoundException {
   logger.debug("call addDrawOrder");
   drawOrder.setTotalPrice(new BigDecimal(0.00));
   for (DrawOrderItem item : drawOrder.getItems()) {
     BookRepository repository =
         bookRepositoryDao.findByStoreBook(drawOrder.getStore(), item.getBook());
     if (repository == null || repository.getNum() - item.getNum() < 0) {
       throw new BookRepositoryOutOfBoundException("draw num: " + item.getNum());
     }
     item.setPrice(repository.getBook().getPrice());
     drawOrder.setTotalPrice(
         item.getPrice().multiply(new BigDecimal(item.getNum())).add(drawOrder.getTotalPrice()));
   }
   orderDao.insertDrawOrder(drawOrder);
   for (DrawOrderItem item : drawOrder.getItems()) {
     BookRepository repository =
         bookRepositoryDao.findByStoreBook(drawOrder.getStore(), item.getBook());
     repository.setNum(repository.getNum() - item.getNum());
     bookRepositoryDao.update(repository);
   }
   return drawOrder;
 }
 @Override
 public List<StockOrder> findStockOrders(Store store, Book book) {
   logger.debug("call findStockOrders");
   return orderDao.findStockOrders(store, book);
 }
 @Override
 public List<StockOrder> findStockOrders(
     Store store, Date startDate, Date endDate, Status status) {
   logger.debug("call findStockOrders");
   return orderDao.findStockOrders(store, startDate, endDate, status);
 }
 @Override
 public StockOrder findStockOrderById(Long id) {
   logger.debug("call findStockOrderById");
   return orderDao.findStockOrderById(id);
 }