private static int insert(DBCon dbCon, Staff staff, WxOrder wxOrder)
      throws SQLException, BusinessException {

    String sql;

    // Check to see whether the member to this weixin serial exist.
    if (MemberDao.getByCond(
            dbCon,
            staff,
            new MemberDao.ExtraCond().setWeixinSerial(wxOrder.getWeixinSerial()),
            null)
        .isEmpty()) {
      throw new BusinessException("微信序列号对应的会员不存在", MemberError.MEMBER_NOT_EXIST);
    }

    // Generate the operation code.
    sql =
        " SELECT IFNULL(MAX(code) + 1, 100) FROM "
            + Params.dbName
            + ".weixin_order WHERE restaurant_id = "
            + staff.getRestaurantId();
    dbCon.rs = dbCon.stmt.executeQuery(sql);
    int code = 0;
    if (dbCon.rs.next()) {
      code = dbCon.rs.getInt(1);
    }
    dbCon.rs.close();

    // Insert the weixin order.
    sql =
        " INSERT INTO "
            + Params.dbName
            + ".`weixin_order` "
            + " (restaurant_id, weixin_serial, weixin_serial_crc, birth_date, status, type, code) "
            + " VALUES( "
            + staff.getRestaurantId()
            + ","
            + "'"
            + wxOrder.getWeixinSerial()
            + "',"
            + "CRC32('"
            + wxOrder.getWeixinSerial()
            + "'),"
            + " NOW(), "
            + wxOrder.getStatus().getVal()
            + ","
            + wxOrder.getType().getVal()
            + ","
            + code
            + " ) ";
    dbCon.stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
    dbCon.rs = dbCon.stmt.getGeneratedKeys();
    int wxOrderId;
    if (dbCon.rs.next()) {
      wxOrderId = dbCon.rs.getInt(1);
    } else {
      throw new SQLException("The id to wx order is NOT generated successfully.");
    }
    dbCon.rs.close();

    // Insert the associated order foods.
    for (OrderFood of : wxOrder.getFoods()) {
      sql =
          " INSERT INTO "
              + Params.dbName
              + ".weixin_order_food "
              + " (wx_order_id, food_id, food_count) VALUES( "
              + wxOrderId
              + ","
              + of.getFoodId()
              + ","
              + of.getCount()
              + ")";
      dbCon.stmt.executeUpdate(sql);
    }

    return wxOrderId;
  }