/** * Delete the wx order to 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 amount to wx order deleted * @throws SQLException throws if failed to execute any SQL statement */ public static int deleteByCond(DBCon dbCon, Staff staff, ExtraCond extraCond) throws SQLException { int amount = 0; for (WxOrder wxOrder : getByCond(dbCon, staff, extraCond, null)) { if (OrderDao.getByCond( dbCon, staff, new OrderDao.ExtraCond(DateType.TODAY).setOrderId(wxOrder.getOrderId()), null) .isEmpty()) { String sql; // Delete the wx order. sql = " DELETE FROM " + Params.dbName + ".weixin_order WHERE wx_order_id = " + wxOrder.getId(); dbCon.stmt.executeUpdate(sql); // Delete the associated order food. sql = " DELETE FROM " + Params.dbName + ".weixin_order_food WHERE wx_order_id = " + wxOrder.getId(); dbCon.stmt.executeUpdate(sql); amount++; } } return amount; }
/** * Insert the new weixin order for inside according to builder {@link * WxOrder#InsertBuilder4Inside} * * @param dbCon the database connection * @param staff the staff to perform this action * @param builder the builder {@link WxOrder#InsertBuilder4Inside} * @return the id to weixin order just inserted * @throws SQLException throws if failed to execute any SQL statement * @throws BusinessException throws if the member to this weixin serial does NOT exist */ public static int insert(DBCon dbCon, Staff staff, WxOrder.InsertBuilder4Inside builder) throws SQLException, BusinessException { WxOrder wxOrder = builder.build(); // Make the previous inside committed orders invalid. for (WxOrder order : getByCond( dbCon, staff, new ExtraCond() .setWeixin(wxOrder.getWeixinSerial()) .setType(WxOrder.Type.INSIDE) .addStatus(WxOrder.Status.COMMITTED), null)) { try { update( dbCon, staff, new WxOrder.UpdateBuilder(order.getId()).setStatus(WxOrder.Status.INVALID)); } catch (BusinessException ignored) { ignored.printStackTrace(); } } // Insert the new inside order. return insert(dbCon, staff, wxOrder); }
/** * Update the wx order according to specific builder {@link WxOrder#UpdateBuilder}. * * @param dbCon the database connection * @param staff the staff to perform this action * @param builder the update builder {@link WxOrder#UpdateBuilder} * @throws SQLException throws if failed to execute any SQL statement * @throws BusinessException throws if the wx order to update does NOT exist */ public static void update(DBCon dbCon, Staff staff, WxOrder.UpdateBuilder builder) throws SQLException, BusinessException { WxOrder wxOrder = builder.build(); String sql; sql = " UPDATE " + Params.dbName + ".weixin_order SET " + " wx_order_id = " + wxOrder.getId() + (builder.isStatusChanged() ? " ,status = " + wxOrder.getStatus().getVal() : "") + (builder.isOrderChanged() ? " ,order_id = " + wxOrder.getOrderId() : "") + " WHERE wx_order_id = " + wxOrder.getId(); if (dbCon.stmt.executeUpdate(sql) == 0) { throw new BusinessException(WxOrderError.WX_ORDER_NOT_EXIST); } }
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())); }