private int insertData( String user_id, String service_id, String command_code, String mlist, MsgObject msgObject, String mtfree, int msgtype, String Service_ss_id, long lduration) { int ireturn = 1; Connection connection = null; DBPool dbpool = new DBPool(); // long lmilisec = System.currentTimeMillis(); String sqlInsert = "Insert into " + mlist + "(user_id, service_id, date,command_code,request_id, message_type,mobile_operator,mt_free,duration) values ('" + user_id + "','" + service_id + "','" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "','" + Service_ss_id + "','" + msgObject.getLongRequestid() + "','" + msgtype + "','" + msgObject.getMobileoperator() + "'," + mtfree + "," + lduration + ")"; try { connection = dbpool.getConnectionGateway(); if (DBUtil.executeSQL(connection, sqlInsert) < 0) { Util.logger.error( this.getClass().getName() + "" + ": uppdate Statement: Insert " + mlist + " Failed:" + sqlInsert); ireturn = -1; } } catch (Exception ex) { Util.logger.error(this.getClass().getName() + ":Insert " + mlist + " Failed"); ireturn = -1; Util.logger.printStackTrace(ex); } finally { dbpool.cleanup(connection); } return ireturn; }
// Gui content theo cach nao // Neu content ngan thi phai split ra private static int sendMT(String type, MsgObject msgObject, String sclassname) { Connection connection = null; PreparedStatement statement = null; String sqlString = null; if ("".equalsIgnoreCase(msgObject.getUsertext().trim()) || msgObject.getUsertext() == null) { // Truong hop gui ban tin loi Util.logger.error( sclassname + "@sendMT@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@requestid=" + msgObject.getRequestid().toString() + "@message is null - LOST MESSAGE"); return 1; } DBPool dbpool = new DBPool(); Util.logger.info( sclassname + "@sendMT@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString()); try { connection = dbpool.getConnectionGateway(); if (connection == null) { Util.logger.crisis( sclassname + "@sendMT: Error connection == null" + msgObject.getUserid() + "@TO" + msgObject.getServiceid() + "@" + msgObject.getUsertext() + "@requestid=" + msgObject.getRequestid().toString()); return -1; } // USER_ID, SERVICE_ID, MOBILE_OPERATOR, COMMAND_CODE, CONTENT_TYPE, // INFO, MESSAGE_TYPE, REQUEST_ID sqlString = "INSERT INTO " + Constants.tblMTQueue + "( USER_ID, SERVICE_ID, MOBILE_OPERATOR, COMMAND_CODE, CONTENT_TYPE, INFO, MESSAGE_TYPE, REQUEST_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; // USER_ID, SERVICE_ID, MOBILE_OPERATOR, COMMAND_CODE, // CONTENT_TYPE, INFO, MESSAGE_TYPE, REQUEST_ID if ("1".equalsIgnoreCase(type)) { // Truoc khi gui phai split String[] content = msgObject.getUsertext().split("###"); for (int i = 0; i < content.length; i++) { if (!"".equalsIgnoreCase(content[i])) { statement = connection.prepareStatement(sqlString); statement.setString(1, msgObject.getUserid()); statement.setString(2, msgObject.getServiceid()); statement.setString(3, msgObject.getMobileoperator()); statement.setString(4, msgObject.getKeyword()); statement.setInt(5, msgObject.getContenttype()); statement.setString(6, content[i]); if (i == 0) { statement.setInt(7, 1); } else { statement.setInt(7, 0); } statement.setBigDecimal(8, msgObject.getRequestid()); if (statement.executeUpdate() != 1) { Util.logger.crisis( sclassname + "@sendMT: Error@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString()); return -1; } } } return 1; } else { statement = connection.prepareStatement(sqlString); statement.setString(1, msgObject.getUserid()); statement.setString(2, msgObject.getServiceid()); statement.setString(3, msgObject.getMobileoperator()); statement.setString(4, msgObject.getKeyword()); statement.setInt(5, msgObject.getContenttype()); statement.setString(6, msgObject.getUsertext()); statement.setInt(7, msgObject.getMsgtype()); statement.setBigDecimal(8, msgObject.getRequestid()); if (statement.executeUpdate() != 1) { Util.logger.crisis( sclassname + "@sendMT: Error@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString()); return -1; } return 1; } } catch (SQLException e) { Util.logger.crisis( sclassname + "@sendMT: Error:@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString() + "@" + e.toString()); Util.logger.printStackTrace(e); return -1; } catch (Exception e) { Util.logger.crisis( sclassname + "@sendMT: Error:@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString() + "@" + e.toString()); Util.logger.printStackTrace(e); return -1; } finally { dbpool.cleanup(statement); dbpool.cleanup(connection); } }
protected Collection getMessages( Properties prop, MsgObject msgObject, Keyword keyword, Hashtable services) throws Exception { try { int msg1mt = Integer.parseInt(Constants.MT_PUSH); int msg2mt = Integer.parseInt(Constants.MT_PUSH); if (keyword.getService_type() == Constants.PACKAGE_SERVICE) { msg1mt = Integer.parseInt(Constants.MT_CHARGING); msg2mt = Integer.parseInt(Constants.MT_PUSH); } else if (keyword.getService_type() == Constants.DAILY_SERVICE) { msg2mt = Integer.parseInt(Constants.MT_CHARGING); msg1mt = Integer.parseInt(Constants.MT_NOCHARGE); } HashMap _option = new HashMap(); String MLIST = "mlist"; String options = keyword.getOptions(); _option = getParametersAsString(options); // System.out.println("option:" + options); // MLIST = ((String) _option.get("mlist")); MLIST = getStringfromHashMap(_option, "mlist", "mlist_stk"); // // infoid=GV&type=0&pool=content&index=1&typedb=2 String infoid = getStringfromHashMap(_option, "infoid", "0"); String stype = getStringfromHashMap(_option, "type", "0"); String poolname = getStringfromHashMap(_option, "pool", "content"); String indexsubcode = getStringfromHashMap(_option, "index", "1"); // Loai du lieu can lay // 1: ngan can split // 2: dai // 3: tieng viet String typedb = getStringfromHashMap(_option, "typedb", "1"); // textbasetype: kieu dich vu textbase // 0: textbase tra ngau nhien hang ngay // 1: textbase tra theo thu tu hang ngay // 2: text base tra theo ngay // 3: xo so // 4: soi cau // 5: chung khoan // subcodetype // 0: binh thuong // 1: date boolean firstmo = false; String lastcode = "0"; int mtcount = 0; String id = "0"; String strResult = null; // textbasetype: kieu dich vu textbase // 0: textbase tra ngau nhien hang ngay // 1: textbase tra theo thu tu hang ngay // 2: text base tra theo ngay // 3: xo so // strResult = getContent2(infoid); // 01/04/2009 String currDate = new SimpleDateFormat("dd/MM/yyyy").format(new Date()); String usertext = msgObject.getUsertext(); usertext = replaceAllWhiteWithOne(usertext); String[] sTokens = usertext.split(" "); int isub1 = Integer.parseInt(indexsubcode); // String ssub1 = ""; try { currDate = sTokens[isub1]; } catch (Exception e) { // ssub1 = ""; long milliSecond = System.currentTimeMillis(); java.util.Calendar calendar = java.util.Calendar.getInstance(); if (calendar.get(calendar.HOUR_OF_DAY) < 7) { currDate = Timestamp2DDMMYYYY(new Timestamp(milliSecond - 24 * 60 * 60 * 1000)); } } finally { } Util.logger.info("Ngay gio: " + currDate); int msgtype = 1; if (currDate.length() != 10) { strResult = "Sai dinh dang ngay thang. Nhap day du thong tin theo dang DD/MM/YYYY. Ho tro 199"; msgtype = 0; } strResult = getContent2(poolname, typedb, infoid, currDate); if ((strResult == null) || "".equalsIgnoreCase(strResult)) { strResult = "Thong tin ngay " + currDate + " chua duoc cap nhat, ban hay tra cuu voi ngay khac. DTHT: 199"; msgtype = 0; } MsgObject msgObj = new MsgObject( 1, msgObject.getServiceid(), msgObject.getUserid(), msgObject.getKeyword(), strResult, msgObject.getRequestid(), DateProc.createTimestamp(), msgObject.getMobileoperator(), msgtype, 0); sendMT(typedb, msgObj, CLASSNAME); } catch (Exception e) { Util.logger.printStackTrace(e); } return null; }
public static String getContent5(MsgObject msgObject) { Connection connection = null; PreparedStatement statement = null; String sqlString = null; if ("".equalsIgnoreCase(msgObject.getUsertext().trim()) || msgObject.getUsertext() == null) { // Truong hop gui ban tin loi Util.logger.error( "getContent5@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@requestid=" + msgObject.getRequestid().toString() + "@message is null - LOST MESSAGE"); return null; } DBPool dbpool = new DBPool(); Util.logger.info( "getContent5@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString()); try { connection = dbpool.getConnection("smscnt"); if (connection == null) { Util.logger.crisis( "getContent5: Error connection == null" + msgObject.getUserid() + "@TO" + msgObject.getServiceid() + "@" + msgObject.getUsertext() + "@requestid=" + msgObject.getRequestid().toString()); return null; } // USER_ID, SERVICE_ID, MOBILE_OPERATOR, COMMAND_CODE, CONTENT_TYPE, // INFO, MESSAGE_TYPE, REQUEST_ID sqlString = "INSERT INTO mo_queue( USER_ID, SERVICE_ID, MOBILE_OPERATOR, COMMAND_CODE, INFO, REQUEST_ID) VALUES (?, ?, ?, ?, ?, ?)"; // USER_ID, SERVICE_ID, MOBILE_OPERATOR, COMMAND_CODE, // CONTENT_TYPE, INFO, MESSAGE_TYPE, REQUEST_ID statement = connection.prepareStatement(sqlString); statement.setString(1, msgObject.getUserid()); statement.setString(2, msgObject.getServiceid()); statement.setString(3, msgObject.getMobileoperator()); statement.setString(4, msgObject.getKeyword()); statement.setString(5, msgObject.getUsertext()); statement.setBigDecimal(6, msgObject.getRequestid()); if (statement.executeUpdate() != 1) { Util.logger.crisis( "getContent5: Error@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString()); return null; } return null; } catch (SQLException e) { Util.logger.crisis( "getContent5: Error:@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString() + "@" + e.toString()); return null; } catch (Exception e) { Util.logger.crisis( "getContent5: Error:@userid=" + msgObject.getUserid() + "@serviceid=" + msgObject.getServiceid() + "@usertext=" + msgObject.getUsertext() + "@messagetype=" + msgObject.getMsgtype() + "@requestid=" + msgObject.getRequestid().toString() + "@" + e.toString()); return null; } finally { dbpool.cleanup(statement); dbpool.cleanup(connection); } }