コード例 #1
0
  @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;
  }
コード例 #2
0
 @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;
 }