/**
   * Insert the new weixin order for take out according to builder {@link
   * WxOrder#InsertBuilder4Takeout}.
   *
   * @param dbCon the database connection
   * @param staff the staff to perform this action
   * @param builder the builder {@link WxOrder#InsertBuilder4Takeout}
   * @return the id to weixin order just inserted
   * @throws SQLException throws if failed to execute any SQL statement
   * @throws BusinessException throws if the take-out address to this order does NOT exist
   */
  public static int insert(DBCon dbCon, Staff staff, WxOrder.InsertBuilder4Takeout builder)
      throws SQLException, BusinessException {
    WxOrder wxOrder = builder.build();

    Member member = MemberDao.getByWxSerial(dbCon, staff, wxOrder.getWeixinSerial());
    if (TakeoutAddressDao.getByCond(
            dbCon,
            staff,
            new TakeoutAddressDao.ExtraCond()
                .setMember(member)
                .setId(wxOrder.getTakeoutAddress().getId()))
        .isEmpty()) {
      throw new BusinessException("外卖地址信息不属于此会员", WxOrderError.WX_TAKE_OUT_ORDER_NOT_ALLOW);
    }

    wxOrder.setTakoutAddress(
        TakeoutAddressDao.getById(dbCon, staff, wxOrder.getTakeoutAddress().getId()));

    int id = insert(dbCon, staff, wxOrder);
    String sql;
    sql =
        " UPDATE "
            + Params.dbName
            + ".weixin_order SET "
            + " wx_order_id = "
            + id
            + " ,address_id = "
            + wxOrder.getTakeoutAddress().getId()
            + " ,address = '"
            + wxOrder.getTakeoutAddress().getAddress()
            + "'"
            + " WHERE wx_order_id = "
            + id;
    dbCon.stmt.executeUpdate(sql);

    // Update the last used to take-out address
    sql =
        " UPDATE "
            + Params.dbName
            + ".take_out_address SET "
            + " last_used = NOW() "
            + " WHERE id = "
            + wxOrder.getTakeoutAddress().getId();
    dbCon.stmt.executeUpdate(sql);

    return id;
  }
 private static void fillDetail(DBCon dbCon, Staff staff, WxOrder wxOrder)
     throws SQLException, BusinessException {
   String sql;
   sql =
       " SELECT * FROM "
           + Params.dbName
           + ".weixin_order_food WHERE wx_order_id = "
           + wxOrder.getId();
   dbCon.rs = dbCon.stmt.executeQuery(sql);
   while (dbCon.rs.next()) {
     OrderFood of = new OrderFood();
     of.asFood().copyFrom(FoodDao.getById(staff, dbCon.rs.getInt("food_id")));
     of.setCount(dbCon.rs.getFloat("food_count"));
     wxOrder.addFood(of);
   }
   dbCon.rs.close();
   wxOrder.setMember(MemberDao.getByWxSerial(dbCon, staff, wxOrder.getWeixinSerial()));
 }