示例#1
0
  public List<ShopOrder> priceOrders(List<ShopOrder> allOrders) {

    Marketplace lmp = null;

    System.out.println("priceOrders:allOrders" + allOrders);

    for (ShopOrder odr : allOrders) {

      if (lmp == null)
        lmp =
            (Marketplace)
                wirc.getByID("localhost:8180", "Marketplace", new Long(odr.getMarketIdSrc()));

      Marketplace fmp =
          (Marketplace)
              wirc.getByID("localhost:8180", "Marketplace", new Long(odr.getMarketIdTgt()));

      if (odr.getMarketIdSrc().equals(odr.getMarketIdTgt())) {
        calculatePriceLocal(odr);
        odr.setTotalPrice(odr.getPrice().intValue());
      } else {

        calculatePriceLocal(odr);

        FXRate rt =
            (FXRate)
                wirc.getByPath(
                    "localhost:8180",
                    FXRate.class.getSimpleName(),
                    "convert/" + lmp.getCCY(),
                    fmp.getCCY());

        Product fprd =
            (Product) wirc.getByID(fmp.getURL(), "Product", new Long(odr.getProductID()));

        System.out.println("fprd:" + fprd);
        System.out.println("rate:" + rt);

        double rate = rt.getRate();

        odr.setRate(rate);

        odr.setFrgPrice(new Long((long) (odr.getQty() * rate * fprd.getPrice())));
        odr.setShippingCosts((int) fmp.getShippingCosts());

        odr.setTotalPrice((int) (odr.getFrgPrice() + odr.getShippingCosts()));
      }
    }

    return allOrders;
  }
示例#2
0
  public static Boolean checkProduct(ShopOrder order, Boolean execOrder) {

    boolean result = false;

    execOrder = false;

    OrderService os = new OrderService();

    Stock stock = (Stock) wirc.getByPath("localhost:8180", "Stock", "prdid", order.getProductID());

    System.out.println("O.qty" + order.getQty());
    System.out.println("s.qty" + stock.getQty());

    if (order.getQty() <= stock.getQty()) {
      result = true;
      if (execOrder) {
        stock.setQty(stock.getQty() - order.getQty());
        order.setPrice(os.calculatePriceLocal(order) * order.getQty());
        order.setTotalPrice(order.getPrice().intValue());
        wirc.putObject("localhost:8180", stock, stock.getId());
      }
      order.setStatus("OK");
    } else {
      order.setStatus("FAIL:QTY");
      result = false;
    }

    if (execOrder) {
      Long id = wirc.putObject("localhost:8180", order, null);
      order.setId(id);
    }

    return new Boolean(result);
  }