@Override
  public List<DishBean> listDishMenuItemByCondition(MenuSearchConditionBean condition) {

    List<Dish> dishList = mDishDAO.getDishMenuItemListByConditon(condition);

    List<DishBean> dishBeanlList = new ArrayList<DishBean>();
    for (Dish dish : dishList) {
      DishBean dishBean = new DishBean();

      dishBean.dishId = String.valueOf(dish.getmId());
      if (dish.getmName() != null) dishBean.dishName = dish.getmName();
      if (dish.getmPrice() != null) dishBean.dishPrice = FormatUtils.formatPrice(dish.getmPrice());
      if (dish.getmImageName() != null && dish.getmDishCategory().getmRestaurant() != null)
        dishBean.dishImageUrl =
            getDishImageUrl(dish.getmImageName(), dish.getmDishCategory().getmRestaurant());

      int pageView = 0;
      int purchaseVolume = 0;
      DishRank dishRank = dish.getmDishRank();
      if (dishRank != null) {
        pageView = (int) dishRank.getmPageView();
        purchaseVolume = (int) dishRank.getmPurchaseVolume();
      }

      dishBean.rank = (double) (pageView + purchaseVolume);

      dishBeanlList.add(dishBean);
    }

    // Collections.sort(dishBeanlList, new Comparator<DishBean>() {
    //
    // public int compare(DishBean arg0, DishBean arg1) {
    // return arg0.rank.compareTo(arg1.rank);
    // }
    // });

    return dishBeanlList;
  }
Exemple #2
0
  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();
  }
  @Override
  public DishBean getDishBeanById(MenuSearchConditionBean condition, long id) {

    Dish dish = getBaseDAO().findById(Dish.class, id);
    Restaurant restaurant = dish.getmDishCategory().getmRestaurant();
    DishBean dishBean = new DishBean();
    String curTime = TimestampUtil.dateToStr(new Date(), DateFormatType.Time24);
    if (dish != null) {

      dishBean.dishId = String.valueOf(dish.getmId());
      dishBean.dishPrice = String.valueOf(dish.getmPrice());
      if (dish.getmName() != null) dishBean.dishName = dish.getmName();
      if (dish.getmDescription() != null) {
        dishBean.desc = dish.getmDescription();
      }
      if (dish.getmCustomization() != null) {
        dishBean.customization = JsonFormatUtils.getCustomization(dish.getmCustomization());
      }
      if (dish.getmDishCategory().getmRestaurant().getmFolderName() != null
          && dish.getmImageName() != null)
        dishBean.dishImageUrl =
            AwsS3Utils.getAwsS3RestaurantResUrl()
                + dish.getmDishCategory().getmRestaurant().getmFolderName()
                + "/"
                + dish.getmImageName();

      dishBean.restaurant.restaurantId =
          String.valueOf(dish.getmDishCategory().getmRestaurant().getmId());
      if (dish.getmDishCategory().getmRestaurant().getmName() != null)
        dishBean.restaurant.restaurantName = dish.getmDishCategory().getmRestaurant().getmName();
      dishBean.restaurant.freeDeliveryLimit =
          String.valueOf(dish.getmDishCategory().getmRestaurant().getmFreeDeliveryLimit());
      dishBean.restaurant.deliveryFee =
          String.valueOf(dish.getmDishCategory().getmRestaurant().getmDeliveryFee());
      if (dish.getmDishCategory().getmRestaurant().getmFolderName() != null
          && dish.getmDishCategory().getmRestaurant().getmLogo() != null)
        dishBean.restaurant.restaurantLogoUrl =
            AwsS3Utils.getAwsS3RestaurantResUrl()
                + dish.getmDishCategory().getmRestaurant().getmFolderName()
                + "/"
                + dish.getmDishCategory().getmRestaurant().getmLogo();

      // set different open time and delivery through different week
      int week = FormatUtils.getCurrentWeek();
      RestaurantDeliveryTimeBean restaurantDeliveryTimeBean = new RestaurantDeliveryTimeBean();
      switch (week) {
        case 0:
          if (restaurant.getmSunOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmSunOpenStartTime();
          if (restaurant.getmSunOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmSunOpenEndTime();
          if (restaurant.getmSunDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmSunDeliveryStartTime();
          if (restaurant.getmSunDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmSunDeliveryEndTime();
          break;

        case 1:
          if (restaurant.getmMonOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmMonOpenStartTime();
          if (restaurant.getmMonOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmMonOpenEndTime();
          if (restaurant.getmMonDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmMonDeliveryStartTime();
          if (restaurant.getmMonDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmMonDeliveryEndTime();
          break;

        case 2:
          if (restaurant.getmTueOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmTueOpenStartTime();
          if (restaurant.getmTueOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmTueOpenEndTime();
          if (restaurant.getmTueDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmTueDeliveryStartTime();
          if (restaurant.getmTueDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmTueDeliveryEndTime();
          break;

        case 3:
          if (restaurant.getmWedOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmWedOpenStartTime();
          if (restaurant.getmWedOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmWedOpenEndTime();
          if (restaurant.getmWedDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmWedDeliveryStartTime();
          if (restaurant.getmWedDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmWedDeliveryEndTime();
          break;

        case 4:
          if (restaurant.getmThuOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmThuOpenStartTime();
          if (restaurant.getmThuOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmThuOpenEndTime();
          if (restaurant.getmThuDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmThuDeliveryStartTime();
          if (restaurant.getmThuDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmThuDeliveryEndTime();
          break;

        case 5:
          if (restaurant.getmFriOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmFriOpenStartTime();
          if (restaurant.getmFriOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmFriOpenEndTime();
          if (restaurant.getmFriDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmFriDeliveryStartTime();
          if (restaurant.getmFriDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmFriDeliveryEndTime();
          break;

        case 6:
          if (restaurant.getmSatOpenStartTime() != null)
            dishBean.restaurant.openingStartTime = restaurant.getmSatOpenStartTime();
          if (restaurant.getmSatOpenEndTime() != null)
            dishBean.restaurant.openingEndTime = restaurant.getmSatOpenEndTime();
          if (restaurant.getmSatDeliveryStartTime() != null)
            restaurantDeliveryTimeBean.startTime = restaurant.getmSatDeliveryStartTime();
          if (restaurant.getmSatDeliveryEndTime() != null)
            restaurantDeliveryTimeBean.endTime = restaurant.getmSatDeliveryEndTime();
          break;

        default:
          break;
      }

      // 营业开始时间
      String beginHour = dishBean.restaurant.openingStartTime;
      // 营业结束时间
      String endHour = dishBean.restaurant.openingEndTime;
      // 如果超过则设置为非营业时间(默认是 营业时间)
      if (curTime.compareTo(beginHour) < 0 || curTime.compareTo(endHour) > 0)
        dishBean.restaurant.isOutOfBusinessHour = "1";

      // 送餐时间
      String beginTime = restaurantDeliveryTimeBean.startTime;
      String endTime = restaurantDeliveryTimeBean.endTime;
      if (curTime.compareTo(beginTime) < 0 || curTime.compareTo(endTime) > 0)
        dishBean.restaurant.isOutOfDeliveryTime = "1";

      dishBean.restaurant.deliveryTimeArray.add(restaurantDeliveryTimeBean);

      if (dish.getmStatus() != null) {
        dishBean.dishStatus = dish.getmStatus();
      }

      if (dish.getmDishCategory().getmRestaurant().getmStatus() != null) {
        dishBean.restaurant.restaurantStatus =
            String.valueOf(dish.getmDishCategory().getmRestaurant().getmStatus());
      }

      dishBean.restaurant.minDeliveryTotal = String.valueOf(restaurant.getmMinDeliveryTotal());
      dishBean.restaurant.deliveryDistance = String.valueOf(restaurant.getmDeliveryDistance());

      if (condition.latitude == null || condition.longitude == null) {
        dishBean.restaurant.distance = "999999";

      } else {
        dishBean.restaurant.distance =
            String.valueOf(
                MapUtils.getDistance(
                    condition.latitude,
                    condition.longitude,
                    dish.getmDishCategory().getmRestaurant().getmLatitude(),
                    dish.getmDishCategory().getmRestaurant().getmLongitude()));

        if (dishBean.restaurant.distance.compareTo(dishBean.restaurant.deliveryDistance) <= 0)
          dishBean.restaurant.isOutOfRange = "0";
      }
    }

    return dishBean;
  }