public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    JObject jobject = new JObject();
    try {

      String pin = (String) request.getAttribute("pin");
      Staff staff = StaffDao.verify(Integer.parseInt(pin));

      String reason = request.getParameter("reason");
      CancelReason.InsertBuilder builder = new InsertBuilder(staff.getRestaurantId(), reason);
      CancelReasonDao.insert(staff, builder);
      jobject.initTip(true, "操作成功, 已添加退菜原因信息.");
    } catch (BusinessException e) {
      e.printStackTrace();
      jobject.initTip(e);
    } catch (Exception e) {
      e.printStackTrace();
      jobject.initTip4Exception(e);
    } finally {
      response.getWriter().print(jobject.toString());
    }
    return null;
  }
  /**
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward getInfo(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    JObject jobject = new JObject();
    try {
      int restaurantId = WxRestaurantDao.getRestaurantIdByWeixin(request.getParameter("fid"));
      final String info =
          WxRestaurantDao.get(StaffDao.getAdminByRestaurant(restaurantId)).getWeixinInfo();
      jobject.setExtra(
          new Jsonable() {

            @Override
            public JsonMap toJsonMap(int flag) {
              JsonMap jm = new JsonMap();
              jm.putString("info", info);
              return jm;
            }

            @Override
            public void fromJsonMap(JsonMap jsonMap, int flag) {}
          });
      jobject.setSuccess(true);
    } catch (Exception e) {
      e.printStackTrace();
      jobject.initTip4Exception(e);
    } finally {
      response.getWriter().print(jobject.toString());
    }
    return null;
  }
 @Test
 public void testJson4Order() {
   String jsonText =
       "[{\"id\":12301,\"alias\":101,\"name\":\"珍藏日本吉品鲍18头\",\"amount\":0,\"unitPrice\":980,\"commission\":0,\"restaurantId\":40,\"pinyin\":\"zzrbjpb18t\",\"desc\":\"\",\"status\":8,\"stockStatusValue\":2,\"stockStatusText\":\"商品出库\",\"tasteRefType\":1,\"kitchen\":{\"id\":1576,\"alias\":2,\"rid\":40,\"name\":\"鲍鱼\",\"isAllowTmp\":false,\"typeValue\":0,\"dept\":{\"rid\":40,\"id\":4,\"name\":\"厨房\",\"typeValue\":0}},\"count\":1,\"isHangup\":false,\"tasteGroup\":{\"tastePref\":\"加快,免做,中牌\",\"price\":490,\"normalTasteContent\":[{\"id\":1169,\"alias\":1169,\"rid\":40,\"name\":\"加快\",\"price\":0,\"rate\":0,\"rank\":2,\"cateValue\":156,\"cateText\":\"口味\",\"cateStatusValue\":2,\"cateStatusText\":\"口味\",\"calcValue\":0,\"calcText\":\"按价格\",\"typeValue\":0,\"typeText\":\"一般\"},{\"id\":1168,\"alias\":1168,\"rid\":40,\"name\":\"免做\",\"price\":0,\"rate\":0,\"rank\":1,\"cateValue\":156,\"cateText\":\"口味\",\"cateStatusValue\":2,\"cateStatusText\":\"口味\",\"calcValue\":0,\"calcText\":\"按价格\",\"typeValue\":0,\"typeText\":\"一般\"},{\"id\":1134,\"alias\":1134,\"rid\":40,\"name\":\"中牌\",\"price\":0,\"rate\":0.5,\"rank\":0,\"cateValue\":29,\"cateText\":\"规格\",\"cateStatusValue\":1,\"cateStatusText\":\"规格\",\"calcValue\":1,\"calcText\":\"按比例\",\"typeValue\":0,\"typeText\":\"一般\"}],\"normalTaste\":{\"name\":\"加快,免做,中牌\",\"price\":490}}},{\"isTemporary\":true,\"id\":\"353\",\"alias\":\"353\",\"name\":\"linshicai\",\"count\":1,\"unitPrice\":12,\"isHangup\":false,\"kitchen\":{\"id\":\"1578\"},\"tasteGroup\":{\"tastePref\":\"无口味\",\"price\":0,\"normalTasteContent\":[]}}]";
   System.out.println(
       JObject.parseList(OrderFood.JSON_CREATOR, OrderFood.OF_JSONABLE_4_COMMIT, jsonText));
 }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    JObject jobject = new JObject();
    SystemSetting set = null;
    try {

      String pin = (String) request.getAttribute("pin");
      StaffDao.verify(Integer.parseInt(pin));

      String restaurantID = (String) request.getAttribute("restaurantID");
      String priceTail = request.getParameter("priceTail");
      String eraseQuota = request.getParameter("eraseQuota");

      if (restaurantID == null || restaurantID.trim().isEmpty()) {
        jobject.initTip(false, "操作失败, 获取餐厅信息失败.");
        return null;
      }

      if (priceTail == null || priceTail.trim().isEmpty()) {
        jobject.initTip(false, "操作失败, 获取收款金额尾数处理方式失败.");
        return null;
      }
      if (eraseQuota == null || eraseQuota.trim().isEmpty()) {
        jobject.initTip(false, "操作失败, 获取抹数金额上限失败.");
        return null;
      }

      set = new SystemSetting();
      set.getSetting().setPriceTail(Integer.parseInt(priceTail));
      set.getSetting().setEraseQuota(Integer.parseInt(eraseQuota));
      set.setRestaurantID(Integer.parseInt(restaurantID));

      SystemDao.updatePriceTail(set);
      jobject.initTip(true, "操作成功, 已修改收款设置.");

    } catch (BusinessException e) {
      e.printStackTrace();
      jobject.initTip(e);

    } catch (Exception e) {
      e.printStackTrace();
      jobject.initTip4Exception(e);
    } finally {
      response.getWriter().print(jobject.toString());
    }

    return null;
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    JObject jobject = new JObject();
    List<PrintFunc> root;
    try {
      String pin = (String) request.getAttribute("pin");
      String printerId = request.getParameter("printerId");
      Staff staff = StaffDao.verify(Integer.parseInt(pin));
      root =
          PrintFuncDao.getByCond(
              staff, new PrintFuncDao.ExtraCond().setPrinter(Integer.parseInt(printerId)));
      List<PrintFunc> roots = new ArrayList<PrintFunc>();

      boolean detail = true;
      for (PrintFunc printFunc : root) {
        if (printFunc.getType() == PType.PRINT_ORDER_DETAIL
            || printFunc.getType() == PType.PRINT_CANCELLED_FOOD_DETAIL) {
          if (printFunc.getType() == PType.PRINT_ORDER_DETAIL) {
            if (detail) {
              roots.add(printFunc);
              detail = false;
            }
          } else if (printFunc.getType() == PType.PRINT_CANCELLED_FOOD_DETAIL) {
            if (detail) {
              printFunc.setType(PType.PRINT_ORDER_DETAIL);
              roots.add(printFunc);
              detail = false;
            }
          }
        } else {
          roots.add(printFunc);
        }
      }

      jobject.setTotalProperty(roots.size());
      jobject.setRoot(roots);

    } catch (BusinessException e) {
      jobject.initTip(e);
      e.printStackTrace();

    } catch (Exception e) {
      jobject.initTip4Exception(e);
      e.printStackTrace();
    } finally {

      response.getWriter().print(jobject.toString());
    }
    return null;
  }
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    final String pin = (String) request.getAttribute("pin");
    final String branchId = request.getParameter("branchId");
    final String beginDate = request.getParameter("beginDate");
    final String opening = request.getParameter("opening");
    final String ending = request.getParameter("ending");
    final String endDate = request.getParameter("endDate");
    final String orderID = request.getParameter("orderID");
    final String tableID = request.getParameter("tableID");
    final String deptID = request.getParameter("deptID");
    final String kitchenId = request.getParameter("kitchenID");
    final String queryType = request.getParameter("queryType");
    final String staffId = request.getParameter("staffID");
    final String isPaging = request.getParameter("isPaging");
    final String start = request.getParameter("start");
    final String limit = request.getParameter("limit");
    final String foodId = request.getParameter("foodId");
    final String regionId = request.getParameter("regionId");
    final String calcByDuty = request.getParameter("calcByDuty");
    final JObject jObject = new JObject();

    try {

      Staff staff = StaffDao.verify(Integer.parseInt(pin));

      if (branchId != null && !branchId.isEmpty() && Integer.parseInt(branchId) > 0) {
        staff = StaffDao.getAdminByRestaurant(Integer.parseInt(branchId));
      }

      List<OrderFood> list = null;

      if (queryType.equalsIgnoreCase("TodayByTbl")) {
        list = OrderFoodDao.getSingleDetailByTableId(staff, Integer.parseInt(tableID));
        if (orderID != null && !orderID.trim().isEmpty()) {
          final float totalPrice =
              OrderDao.getById(staff, Integer.parseInt(orderID), DateType.TODAY).calcTotalPrice();
          jObject.setExtra(
              new Jsonable() {

                @Override
                public JsonMap toJsonMap(int flag) {
                  JsonMap jm = new JsonMap();
                  jm.putFloat("detailTotalPrice", totalPrice);
                  return jm;
                }

                @Override
                public void fromJsonMap(JsonMap jsonMap, int flag) {}
              });
        }
      } else {
        final OrderFoodDao.ExtraCond extraCond;
        if (queryType.equalsIgnoreCase("today")) {
          extraCond = new OrderFoodDao.ExtraCond(DateType.TODAY);
        } else {
          extraCond = new OrderFoodDao.ExtraCond(DateType.HISTORY);
        }

        if (foodId != null && !foodId.isEmpty()) {
          extraCond.setFood(Integer.parseInt(foodId));
        }

        if (kitchenId != null && !kitchenId.isEmpty() && Integer.parseInt(kitchenId) > 0) {
          extraCond.setKitchen(Integer.parseInt(kitchenId));
        }

        if (regionId != null && !regionId.isEmpty() && Integer.parseInt(regionId) > 0) {
          extraCond.setRegionId(Region.RegionId.valueOf(Integer.parseInt(regionId)));
        }

        if (staffId != null && !staffId.isEmpty() && Integer.parseInt(staffId) > 0) {
          extraCond.setStaffId(Integer.parseInt(staffId));
        }

        if (beginDate != null && !beginDate.isEmpty() && endDate != null && !endDate.isEmpty()) {
          if (calcByDuty != null && !calcByDuty.isEmpty() && Boolean.parseBoolean(calcByDuty)) {
            DutyRange range = DutyRangeDao.exec(staff, beginDate, endDate);
            if (range != null) {
              extraCond.setDutyRange(range);
            } else {
              extraCond.setDutyRange(beginDate, endDate);
            }
          } else {
            extraCond.setDutyRange(beginDate, endDate);
          }
        }

        if (opening != null && !opening.isEmpty() && ending != null && !ending.isEmpty()) {
          HourRange range = new HourRange(opening, ending);
          extraCond.setHourRange(range);
        }

        if (deptID != null && !deptID.isEmpty() && !deptID.equals("-1")) {
          extraCond.setDeptId(DeptId.valueOf(Integer.parseInt(deptID)));
        }

        if (orderID != null && !orderID.isEmpty()) {
          extraCond.setOrder(Integer.parseInt(orderID));
        }

        list = OrderFoodDao.getSingleDetail(staff, extraCond, " ORDER BY OF.order_date ");
      }

      if (start != null && !start.isEmpty() && limit != null && !limit.isEmpty()) {
        list = DataPaging.getPagingData(list, Boolean.parseBoolean(isPaging), start, limit);
      }
      jObject.setRoot(list);

    } catch (BusinessException | SQLException e) {
      e.printStackTrace();
      jObject.initTip(e);

    } catch (Exception e) {
      e.printStackTrace();
      jObject.initTip4Exception(e);

    } finally {
      response.getWriter().print(jObject.toString());
    }

    return null;
  }