/** * Cancels an order. Note that cancel requests for orders will be rejected if they are older than * one hour, or don't target the given customer. * * @param alias the customer alias * @param passwordHash the customer password-hash * @param orderIdentity the order identity * @throws IllegalStateException if the login data is invalid, if the order is too old, or if it * is not targeting the given customer * @throws SQLException if there is a problem with the underlying JDBC connection */ public void deleteOrder(final String alias, final byte[] passwordHash, final long orderIdentity) throws SQLException { final Customer customer = this.queryCustomer(alias, passwordHash); final Order order = this.queryOrder(alias, passwordHash, orderIdentity); if (order.getCustomerIdentity() != customer.getIdentity()) throw new IllegalStateException("purchase not created by given customer."); if (System.currentTimeMillis() > order.getCreationTimestamp() + TimeUnit.HOURS.toMillis(1)) throw new IllegalStateException("purchase too old."); synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_DELETE_PURCHASE)) { statement.setLong(1, orderIdentity); statement.executeUpdate(); } } for (final OrderItem item : order.getItems()) { synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_RELEASE_ARTICLE_UNITS)) { statement.setLong(1, item.getCount()); statement.setLong(2, item.getArticleIdentity()); statement.executeUpdate(); } } } }
public OrderItem searchOrderItemBYID(String ID) { for (OrderItem orderItem : orderItemList) { if (ID.equals(orderItem.getOrderID())) return orderItem; } return null; }
/** * 获得选中订单的订单号 * * @return */ public List<String> getOrders() { List<String> order = new ArrayList<String>(); for (OrderItem item : selectItems) { order.add(item.getOrderId()); } return order; }
@RequestMapping(value = "/waiter/orders/{orderId}", method = RequestMethod.GET) public String showOrderInWaiter( @PathVariable("orderId") String orderId, Model uiModel, Locale locale) { // warmup stuff Order order = warmupRestaurantByOrder(orderId, uiModel); Restaurant resto = order.getBill().getDiningTable().getRestaurant(); List<Order> allPreparedOrders = orderService.findPreparedOrdersForRestaurant(resto); uiModel.addAttribute("allPreparedOrders", allPreparedOrders); List<Bill> allSubmittedBills = billService.findSubmittedBillsForRestaurant(resto); uiModel.addAttribute("allSubmittedBills", allSubmittedBills); String orderContent = ""; for (OrderItem orderItem : order.getOrderItems()) { orderContent += orderItem.getMenuItem().getId() + " (" + orderItem.getQuantity() + "x)" + "; "; } uiModel.addAttribute( "message", new Message( "info", messageSource.getMessage("label_order_content", new Object[] {}, locale) + ": " + orderContent)); return "hartigehap/waiter"; }
public float getTotal() { float total = 0; for (OrderItem it : new ArrayList<OrderItem>(items)) { total += it.getPrice() * it.getQuantity(); } return total; }
private void deleteOrderItemAssociations(Accompaniment root) { List<OrderItem> orderItens = orderItemDAO.listByAccompanimentId(root.getId()); for (OrderItem item : orderItens) { item.setAccompaniments(null); orderItemDAO.update(item); } root.setOrderItems(null); }
public void displayOrderedItems() { for (Iterator<OrderItem> i = orderItemsList.iterator(); i.hasNext(); ) { OrderItem orderitem = (OrderItem) i.next(); System.out.println( orderitem.getName() + "," + orderitem.getQuantity() + "," + orderitem.getTotalItemCost()); } System.out.println(); }
@Override public int getItemsCount() { int res = 0; for (OrderItem orderItem : orderItems) { res += orderItem.getQuantity(); } return res; }
/* * @GRASP: Polimorfismo * */ @Override double orderPayment(Order order) { double total = 0; for (OrderItem item : order.getItems()) { total += item.calculatePriceItem(order.getShipping()); } total *= 0.5; return total; }
/** * XML fragment representation of this object * * @return XML fragment for this object. Name for outer tag expected to be set by calling method. * This fragment returns inner properties representation only */ public String toXMLFragment() { StringBuffer xml = new StringBuffer(); java.util.List<OrderItem> orderItemList = getOrderItem(); for (OrderItem orderItem : orderItemList) { xml.append("<OrderItem>"); xml.append(orderItem.toXMLFragment()); xml.append("</OrderItem>"); } return xml.toString(); }
/** * 根据订单Id查询Sku列表 * * @param orderId * @return */ @RequestMapping(value = "/order/sku/{orderId}") public void skuGrid(@PathVariable("orderId") int orderId, HttpServletResponse response) throws IOException { List<OrderItem> orderItems = tradeCenterBossClient.queryOrderItemWithoutBackingNumberByOrderId(orderId); List<ProductSku> list = new ArrayList<ProductSku>(); for (OrderItem orderItem : orderItems) { ProductSku sku = new ProductSku(); sku.setNumber(orderItem.getNumber()); sku.setSkuId(orderItem.getSkuId()); sku.setProductId(orderItem.getProductId()); sku.setSkuState(orderItem.getOrderState().serviceDesc()); sku.setShipmentNum(orderItem.getShipmentNum()); sku.setBackNumber(orderItem.getBackNum()); sku.setBarCode(orderItem.getBarCode()); StockKeepingUnit stockKeepingUnit = skuService.getStockKeepingUnit(orderItem.getSkuId()); if (stockKeepingUnit != null) { Product product = productService.getProductById(stockKeepingUnit.getProductId()); Money money = new Money(); money.setCent(stockKeepingUnit.getPrice()); sku.setSkuPrice(money.toString()); sku.setProductName(product.getName()); sku.setAttribute(skuService.getSkuPropertyToString(stockKeepingUnit)); sku.setProductCode(stockKeepingUnit.getSkuCode()); // product.getProductCode()); } else { sku.setProductName("没有此 SKU! 被删除或重新生成过."); } list.add(sku); } new JsonResult(true) .addData("totalCount", list.size()) .addData("result", list) .toJson(response); }
@XmlElement public List<OrderClientItem> getClientItems() { if (this.orderItems != null && !this.orderItems.isEmpty()) { List<OrderClientItem> list = new ArrayList<OrderClientItem>(); for (OrderItem item : orderItems) { OrderClientItem o = queryByRecipe(item.getRecipe().getId(), list); if (o == null) { o = new OrderClientItem(); o.setCountNew(0); o.setCountDeposit(0); o.setCountConfirm(0); o.setRecipe(item.getRecipe()); list.add(o); } if (item.getStatus() == 0) { o.setCountNew(o.getCountNew() + item.getCount()); } if (item.getStatus() == 1) { o.setCountDeposit(o.getCountDeposit() + item.getCount()); } if (item.getStatus() == 2) { o.setCountConfirm(o.getCountConfirm() + item.getCount()); } } return list; } return null; }
public void changeOrderedItem(String name, int quantity) { for (Iterator<OrderItem> i = orderItemsList.iterator(); i.hasNext(); ) { OrderItem orderitem = (OrderItem) i.next(); if (orderitem.ordernamematches(name)) { changeItemListInventory(name, orderitem.getQuantity() - quantity); orderitem.setQuantity(quantity); orderitem.setTotalItemCost(quantity); } } items.disply(); }
public void deleteOrderedItem(String name) { for (Iterator<OrderItem> i = orderItemsList.iterator(); i.hasNext(); ) { OrderItem orderitem = (OrderItem) i.next(); if (orderitem.ordernamematches(name)) { changeItemListInventory(name, orderitem.getQuantity()); orderItemsList.remove(orderitem); break; } } items.disply(); }
/** * String representation of the OrderItemList object. * * @return It returns all the available OrderItem data in a String format. It uses the OrderItem * object's toString() method. */ @Override public String toString() { StringBuilder orderItemListBuilder = new StringBuilder(); java.util.List<OrderItem> orderItemList = getOrderItem(); for (OrderItem orderItem : orderItemList) { orderItemListBuilder.append("OrderItem: "); orderItemListBuilder.append(orderItem.toString()); orderItemListBuilder.append("\n"); } return orderItemListBuilder.toString(); }
public Double process(Order order) { Double totalAmount = 0d; List<OrderItem> orderItems = order.getItems(); for (int i = 0; i < orderItems.size(); i++) { OrderItem item = orderItems.get(i); // static method double productPrice = productPrice(item); totalAmount += item.getSum() * productPrice; } return totalAmount; }
public BigDecimal computeTotalCost(int creditLimit) { BigDecimal totalCost = BigDecimal.ZERO; for (OrderItem o : items) { totalCost = totalCost.add(o.getCost()); } if (creditLimit == 150000) { totalCost = totalCost.subtract(getDiscount(totalCost)); } return totalCost; }
public void consolidateItems() { ArrayList<OrderItem> newOrderList = new ArrayList<OrderItem>(); for (OrderItem i : items) { if (newOrderList.contains(i)) { updateOrderItem(newOrderList.indexOf(i), i.getQuantity()); } else { newOrderList.add(i); } } items = newOrderList; }
@Transient public Long getOrderMoney() { Long money = 0L; for (Order order : orders) { for (OrderItem item : order.getItems()) { money += item.getMoney(); } } return money; }
public BigDecimal getOrderItemTotal() { BigDecimal orderItemsTotal = new BigDecimal("0"); if (shipments != null && Hibernate.isInitialized(shipments)) { for (final OrderShipment orderShipment : shipments) { for (final OrderItem orderItem : orderShipment.getOrderItems()) { orderItemsTotal = orderItemsTotal.add(orderItem.getTotalAmountOrderItem()); } } } return orderItemsTotal; }
/** * Creates an order from the given items. Note that the suggested price for each item must be * equal to or exceed the current article price. Also, note that orders which exhaust the * available article capacity are rejected. * * @param alias the customer alias * @param passwordHash the customer password-hash * @param items the items * @return the order identity * @throws NullPointerException if one of the given values is {@code null} * @throws IllegalArgumentException if items is empty, or if any of the given items is priced too * low * @throws IllegalStateException if the login data is invalid, or the order creation fails * @throws SQLException if there is a problem with the underlying JDBC connection */ public long insertOrder( final String alias, final byte[] passwordHash, final double taxRate, final Collection<OrderItem> items) throws SQLException { final long purchaseIdentity; final Customer customer = this.queryCustomer(alias, passwordHash); synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_INSERT_PURCHASE, Statement.RETURN_GENERATED_KEYS)) { statement.setLong(1, customer.getIdentity()); statement.setLong(2, System.currentTimeMillis()); statement.setDouble(3, taxRate); if (statement.executeUpdate() != 1) throw new IllegalStateException("purchase creation failed."); try (ResultSet resultSet = statement.getGeneratedKeys()) { if (!resultSet.next()) throw new IllegalStateException("purchase key generation failed."); purchaseIdentity = resultSet.getLong(1); } } } if (items.isEmpty()) throw new IllegalArgumentException("missing items."); for (final OrderItem item : items) { if (item.getCount() <= 0) throw new IllegalArgumentException("item count too low."); final Article article = this.queryArticle(item.getArticleIdentity()); if (article.getPrice() > item.getArticleGrossPrice()) throw new IllegalArgumentException("price offer too low."); synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_RESERVE_ARTICLE_UNITS)) { statement.setLong(1, item.getCount()); statement.setLong(2, article.getIdentity()); statement.setLong(3, item.getCount()); if (statement.executeUpdate() != 1) throw new IllegalStateException("too few article units on stock."); } } synchronized (this.connection) { try (PreparedStatement statement = this.connection.prepareStatement(SQL_INSERT_PURCHASE_ITEM)) { statement.setLong(1, purchaseIdentity); statement.setLong(2, item.getArticleIdentity()); statement.setLong(3, item.getArticleGrossPrice()); statement.setInt(4, item.getCount()); if (statement.executeUpdate() != 1) throw new IllegalStateException("purchase item creation failed."); } } } return purchaseIdentity; }
public float calculateTotalValue(int customerId) { float totalValue = 0.0f; for (OrderItem item : items) { totalValue += item.getValue(); } float discountValue = discountPolicy.calculateDiscount(customerId); if (discountValue != 0.0f) return totalValue - discountValue; return totalValue; }
public Set<OrderTax> getOrderTaxes() { Set<OrderTax> orderTaxes = null; if (shipments != null && Hibernate.isInitialized(shipments)) { orderTaxes = new HashSet<OrderTax>(); for (final OrderShipment orderShipment : shipments) { for (final OrderItem orderItem : orderShipment.getOrderItems()) { for (OrderTax orderTax : orderItem.getTaxes()) { orderTaxes.add(orderTax); } } } } return orderTaxes; }
public Order getOrder(Integer orderId) throws Exception { LOGGER.info("Getting Order with no: " + orderId); Order corder = _orders.get(orderId); if (corder == null) { throw new RuntimeException("Order " + orderId + " not found!"); } LOGGER.info("Updating descriptions: " + corder.getItems()); // Get the updated descriptions of items for (OrderItem orderItem : corder.getItems()) { Item item = _warehouse.getItem(orderItem.getItem().getItemId()); orderItem.setItem(item); } return corder; }
public static void addOrderToDB(Order o) { Customer customer = CustomerServiceImpl.getCustomer(o.getCustomerID()); customer.setOrders(OrderServiceImpl.retrieveUnpaidOrders(customer)); customer.addOrder(o); if (customer.getOrders().contains(o)) { orderDAO.addOrder(o); List<OrderItem> items = o.getItems(); Inventory inventory = new Inventory(InventoryServiceImpl.getAllAvailableProductsInDB()); for (OrderItem i : items) { Product product = ProductServiceImpl.getProduct(i.getItemSKUNumber()); InventoryItem inventoryitem = InventoryServiceImpl.getInventoryItem(inventory, product); InventoryServiceImpl.deductFromInventory(inventory, inventoryitem, i.getQuantity()); } } }
@Override public double calculateShippingCost(Order order) { List<OrderItem> items = order.getItems(); double totalWeight = 0; for (OrderItem item : items) { if (item.getWeight() < 1) { totalWeight += 1; } else { totalWeight += item.getWeight(); } } return totalWeight * GROUND_COST_PER_POUND; }
public void addOrderItem(MenuItem menuItem) { Iterator<OrderItem> orderItemIterator = orderItems.iterator(); boolean found = false; while (orderItemIterator.hasNext()) { OrderItem orderItem = orderItemIterator.next(); if (orderItem.getMenuItem().equals(menuItem)) { orderItem.incrementQuantity(); found = true; break; } } if (!found) { OrderItem orderItem = new OrderItem(menuItem, 1); orderItems.add(orderItem); } }
public void addOrderedItem(String name, int quantity) { for (Iterator<Store> i = items.getItemList().iterator(); i.hasNext(); ) { Store item = (Store) i.next(); if (item.getItem().matches(name)) { if (item.getQuantity() >= quantity) { OrderItem neworderitems = new OrderItem(name, quantity, item.getItem().getCost()); neworderitems.setTotalItemCost(quantity); item.setQuantity(item.getQuantity() - quantity); orderItemsList.add(neworderitems); } else { System.out.println(item.getQuantity() + " " + item.getItem().getName() + "are there."); } } } items.disply(); }
public String addItems(Order order) throws Exception { LOGGER.info("Adding items to order: " + order.getOrderId()); Order corder = getOrder(order.getOrderId()); for (OrderItem orderItem : order.getItems()) { LOGGER.info("Adding item: " + orderItem.getItem().getItemId()); Item item = _warehouse.getItem(orderItem.getItem().getItemId()); if (item == null) { throw new RuntimeException("Item " + orderItem.getItem().getItemId() + " not found!"); } else { orderItem.setItem(item); corder.getItems().add(orderItem); } } LOGGER.info("Order after adding items: " + corder); return SUCCESS; }
public String removeItem(String orderItemId) throws Exception { // Not so elegant, but what to do? String[] ids = orderItemId.split(":"); if (ids.length != 2) { throw new RuntimeException("Missing either order id or item id!"); } Integer orderId = Integer.parseInt(ids[0]); Integer itemId = Integer.parseInt(ids[1]); Order corder = getOrder(orderId); for (OrderItem orderItem : corder.getItems()) { if (orderItem.getItem().getItemId() == itemId) { corder.getItems().remove(orderItem); break; } } LOGGER.info("Order after deleting item: " + corder); return SUCCESS; }