Esempio n. 1
0
  /**
   * 根据orderId查询订单明细
   *
   * @param orderId 订单ID
   * @return 订单明细列表
   * @throws OrderNotFoundException
   */
  @GET
  @Path("/{orderId}")
  @Scope("request")
  @Produces(MediaType.APPLICATION_JSON)
  public Map<String, Object> getOrderItemsByOrderId(@PathParam("orderId") Long orderId)
      throws OrderNotFoundException {
    logger.info("[REST_CALL= getOrderItemsByOrderId, orderId=" + orderId + "]");

    Map<String, Object> result = new HashMap<String, Object>();
    List<OrderItemVO> orderItemVOs = new ArrayList<OrderItemVO>();
    Order order = orderService.getOrderById(orderId);

    if (null == order) {
      result.put("exception", MessageUtil.getMessage("order_not_found_exception", "" + orderId));
    } else {
      List<OrderItem> orderItems = new ArrayList<OrderItem>(order.getOrderItems());
      OrderItemVO orderItemVO = null;
      for (OrderItem orderItem : orderItems) {
        orderItemVO = new OrderItemVO();
        orderItemVO.setId(orderItem.getId());
        orderItemVO.setDishId(orderItem.getDish().getId());
        orderItemVO.setDishName(orderItem.getDish().getName());
        orderItemVO.setDishPrice(orderItem.getDish().getPrice());
        orderItemVO.setDishPicture(orderItem.getDish().getPicPath());
        orderItemVO.setDishAmount(orderItem.getDishAmount());
        orderItemVOs.add(orderItemVO);
      }

      result.put("orders", orderItemVOs);
    }

    return result;
  }
Esempio n. 2
0
  @POST
  @Path("/")
  @Scope("request")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public CallResult placeOrder(NewOrderVO newOrderVO) {
    logger.info("[REST_CALL= placeOrder]");

    logger.debug(newOrderVO);
    CallResult callResult = new CallResult();

    try {
      Long orderId = orderService.placeOrder(newOrderVO);
      Order order = null;
      try {
        order = orderService.getOrderById(orderId);
      } catch (Exception exception) {
        callResult.setResult(Constants.FALSE);
        callResult.setMessage(exception.getMessage());
      }

      callResult.setResult(Constants.SUCCESS);
      callResult.setMessage(MessageUtil.getMessage("place_order_success", order.getOrderSeq()));
    } catch (UserNotFoundException exception) {
      callResult.setResult(Constants.FALSE);
      callResult.setMessage(exception.getMessage());
    } catch (ZeroOrderItemException exception) {
      callResult.setResult(Constants.FALSE);
      callResult.setMessage(exception.getMessage());
    } catch (DishNotFoundException exception) {
      callResult.setResult(Constants.FALSE);
      callResult.setMessage(exception.getMessage());
    }

    return callResult;
  }