コード例 #1
0
ファイル: OrderFormBean.java プロジェクト: SimonSWLiu/Study
  public OrderFormBean(OrderForm orderForm) {

    this.orderFormId = String.valueOf(orderForm.getmId());

    if (orderForm.getmTrade() != null) {
      if (orderForm.getmTrade().getmGetType() != null)
        this.getType = String.valueOf(orderForm.getmTrade().getmGetType());
      if (orderForm.getmTrade().getmCustomerName() != null)
        this.customerName = orderForm.getmTrade().getmCustomerName();
      if (orderForm.getmTrade().getmCustomerAddress() != null)
        this.customerAddress = orderForm.getmTrade().getmCustomerAddress();
      if (orderForm.getmTrade().getmCustomerPhone() != null)
        this.customerPhone = orderForm.getmTrade().getmCustomerPhone();
    }
    if (orderForm.getmCode() != null) this.orderFormCode = orderForm.getmCode();
    if (orderForm.getmTaxFee() != null)
      this.taxFee = FormatUtils.formatPrice(orderForm.getmTaxFee());
    if (orderForm.getmTipsFee() != null)
      this.tipsFee = FormatUtils.formatPrice(orderForm.getmTipsFee());
    if (orderForm.getmDeliveryFee() != null)
      this.deliveryFee = FormatUtils.formatPrice(orderForm.getmDeliveryFee());
    if (orderForm.getmDiscountFee() != null)
      this.discountFee = FormatUtils.formatPrice(orderForm.getmDiscountFee());
    if (orderForm.getmPrice() != null)
      this.orderFormPrice = FormatUtils.formatPrice(orderForm.getmPrice());

    if (orderForm.getmStatus() != null) this.status = orderForm.getmStatus();

    if (orderForm.getmRestConfirmedTimestamp() != null)
      this.orderFormRestConfirmedDateTime =
          TimestampUtil.formatTimestamp(orderForm.getmRestConfirmedTimestamp());
    if (orderForm.getmCancelTimestamp() != null)
      this.orderFormCancelDateTime = TimestampUtil.formatTimestamp(orderForm.getmCancelTimestamp());
    if (orderForm.getmCallDeliveryTimestamp() != null)
      this.orderFormCallDeliveryDateTime =
          TimestampUtil.formatTimestamp(orderForm.getmCallDeliveryTimestamp());
    if (orderForm.getmDriverConfirmedTimestamp() != null)
      this.orderFormDriverConfirmedDateTime =
          TimestampUtil.formatTimestamp(orderForm.getmDriverConfirmedTimestamp());
    if (orderForm.getmArrivedTimestamp() != null)
      this.orderFormArrivedDateTime =
          TimestampUtil.formatTimestamp(orderForm.getmArrivedTimestamp());
    if (orderForm.getmCreateTimestamp() != null)
      this.orderFormCreateDateTime = TimestampUtil.formatTimestamp(orderForm.getmCreateTimestamp());

    if (orderForm.getmRestConfirmedTimestamp() != null)
      this.orderFormRestConfirmedTimestamp = orderForm.getmRestConfirmedTimestamp();
    if (orderForm.getmCancelTimestamp() != null)
      this.orderFormCancelTimestamp = orderForm.getmCancelTimestamp();
    if (orderForm.getmCallDeliveryTimestamp() != null)
      this.orderFormCallDeliveryTimestamp = orderForm.getmCallDeliveryTimestamp();
    if (orderForm.getmDriverConfirmedTimestamp() != null)
      this.orderFormDriverConfirmedTimestamp = orderForm.getmDriverConfirmedTimestamp();
    if (orderForm.getmArrivedTimestamp() != null)
      this.orderFormArrivedTimestamp = orderForm.getmArrivedTimestamp();
    if (orderForm.getmCreateTimestamp() != null)
      this.orderFormCreateTimestamp = orderForm.getmCreateTimestamp();

    List<OrderItemBean> orderItemBeanList = new ArrayList<OrderItemBean>();
    for (OrderItem orderItem : orderForm.getmOrderItemSet()) {

      OrderItemBean orderItemBean = new OrderItemBean();

      orderItemBean.setDishId(String.valueOf(orderItem.getmId()));
      ;
      if (orderItem.getmDishName() != null) orderItemBean.setDishName(orderItem.getmDishName());
      ;
      if (orderItem.getmDishImageUrl() != null)
        orderItemBean.setDishImageUrl(orderItem.getmDishImageUrl());
      ;
      if (orderItem.getmDishAmount() != null)
        orderItemBean.setDishAmount(orderItem.getmDishAmount());
      ;
      if (orderItem.getmDishPrice() != null) orderItemBean.setDishPrice(orderItem.getmDishPrice());
      ;
      if (orderItem.getmPrice() != null)
        orderItemBean.setOrderItemPrice(FormatUtils.formatPrice(orderItem.getmPrice()));
      ;

      List<DishOptionItemBean> dishOptionItemBeanList = new ArrayList<DishOptionItemBean>();
      for (OrderItemIngredient ingredient : orderItem.getmOrderItemIngredientSet()) {

        DishOptionItemBean ingredientBean = new DishOptionItemBean();

        if (ingredient.getmName() != null) ingredientBean.setName(ingredient.getmName());
        if (ingredient.getmPrice() != null)
          ingredientBean.setPrice(FormatUtils.formatPrice(ingredient.getmPrice()));

        dishOptionItemBeanList.add(ingredientBean);
      }
      orderItemBean.setOrderItemOptionItemArray(dishOptionItemBeanList);

      orderItemBeanList.add(orderItemBean);
    }

    this.orderItemArray = orderItemBeanList;

    this.curTimestamp = TimestampUtil.getCurrentTimestamp();
  }
コード例 #2
0
ファイル: EmailUtils.java プロジェクト: SimonSWLiu/Study
  public static Boolean sendOrderFormToRestaurant(OrderForm orderForm) {

    String toMail = orderForm.getmRestaurant().getmEmail();

    if (TextUtils.isEmpty(toMail)) {
      return false;
    }

    Properties mailProps = new Properties();
    mailProps.setProperty("mail.smtp.host", onemenuMailHostName);
    mailProps.setProperty("mail.smtp.starttls.enable", "true");
    mailProps.setProperty("mail.smtp.auth", "true");
    mailProps.setProperty("mail.smtp.quitwait", "false");
    mailProps.setProperty("mail.smtp.ssl.trust", "*");

    Authenticator authenticator = new EmailAuthenticator(onemenuMailAddress, onemenuPassword);

    javax.mail.Session mailSession =
        javax.mail.Session.getDefaultInstance(mailProps, authenticator);
    // mailSession.setDebug(true);

    try {

      Address fromAddress = new InternetAddress(onemenuMailAddress);
      Address toAddress = new InternetAddress(toMail);
      Address bccAddress = new InternetAddress(onemenuMailAddress);

      String content;
      try {
        content = FaxUtils.getOrderFormHtml(orderForm);
      } catch (IOException e) {
        LOGGER.error("", e);
        return false;
      } catch (URISyntaxException e) {
        LOGGER.error("", e);
        return false;
      }

      MimeMessage msg = new MimeMessage(mailSession);
      msg.setFrom(fromAddress);
      msg.setSubject("[OneMenu Order] " + orderForm.getmRestaurant().getmName());
      msg.setSentDate(new Date());
      msg.setContent(content, "text/html;charset=utf-8");
      msg.setRecipient(RecipientType.TO, toAddress);
      msg.setRecipient(RecipientType.BCC, bccAddress);

      /*
       * Transport transport = session.getTransport("smtp"); transport.connect("smtp.163.com",
       * userName, password); transport.sendMessage(msg,msg.getAllRecipients());
       * transport.close();
       */

      Transport.send(msg);
      if (LOGGER.isDebugEnabled()) LOGGER.debug("Send order form email to " + toMail);

    } catch (MessagingException e) {
      LOGGER.error("", e);
    }

    return true;
  }