@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 StockOrder findStockOrderById(Long id) { logger.debug("call findStockOrderById"); return orderDao.findStockOrderById(id); }