/** * Get the weixin order according to specific extra condition{@link ExtraCond}. * * @param dbCon the database connection * @param staff the staff to perform this action * @param extraCond the extra condition {@link ExtraCond} * @return the result to wx order * @throws SQLException throws if failed to execute any SQL statement */ public static List<WxOrder> getByCond( DBCon dbCon, Staff staff, ExtraCond extraCond, String orderClause) throws SQLException { String sql; sql = " SELECT * FROM " + Params.dbName + ".weixin_order " + " WHERE 1 = 1 " + " AND restaurant_id = " + staff.getRestaurantId() + (extraCond != null ? extraCond.toString() : " ") + (orderClause != null ? orderClause : ""); dbCon.rs = dbCon.stmt.executeQuery(sql); List<WxOrder> result = new ArrayList<WxOrder>(); while (dbCon.rs.next()) { WxOrder wxOrder = new WxOrder(dbCon.rs.getInt("wx_order_id")); wxOrder.setRestaurant(dbCon.rs.getInt("restaurant_id")); wxOrder.setStatus(WxOrder.Status.valueOf(dbCon.rs.getInt("status"))); wxOrder.setType(WxOrder.Type.valueOf(dbCon.rs.getInt("type"))); if (wxOrder.getType() == WxOrder.Type.TAKE_OUT) { TakeoutAddress address = new TakeoutAddress(dbCon.rs.getInt("address_id")); address.setAddress(dbCon.rs.getString("address")); wxOrder.setTakoutAddress(address); } wxOrder.setCode(dbCon.rs.getInt("code")); wxOrder.setOrderId(dbCon.rs.getInt("order_id")); wxOrder.setBirthDate(dbCon.rs.getTimestamp("birth_date").getTime()); wxOrder.setWeixinSerial(dbCon.rs.getString("weixin_serial")); result.add(wxOrder); } dbCon.rs.close(); return result; }
@Override public String toString() { StringBuilder extraCond = new StringBuilder(); if (id != 0) { extraCond.append(" AND wx_order_id = " + id); } if (code != 0) { extraCond.append(" AND code = " + code); } if (orderId != 0) { extraCond.append(" AND order_id = " + orderId); } if (weixinSerial != null) { extraCond.append( " AND weixin_serial = '" + weixinSerial + "' AND weixin_serial_crc = CRC32('" + weixinSerial + "')"); } if (type != null) { extraCond.append(" AND type = " + type.getVal()); } final StringBuilder statusCond = new StringBuilder(); for (WxOrder.Status s : status) { if (statusCond.length() == 0) { statusCond.append(s.getVal()); } else { statusCond.append("," + s.getVal()); } } if (statusCond.length() != 0) { extraCond.append(" AND status IN ( " + statusCond.toString() + ")"); } return extraCond.toString(); }