namespace AsiaINFO.SMS.DBFactory { using AsiaINFO.DBHelpers.MSSqlDB; using AsiaINFO.SMS.Entity; using DBFactory; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; public class MTFactory { private static bool checkPhoneNumberFormat(string phoneNumber) { bool flag = true; return (((phoneNumber != null) && (phoneNumber.Length == 11)) && flag); } public static List GetSMSInfo(string smsContent, string[] phoneNumberArray, string subNumber, string wapPushAddr, string sendTime, string subnumber, string needdowntime, int batchid, int priority) { List result = new List(); int sign = System.Configuration.ConfigurationManager.AppSettings["signlen"] == null ? 0 : Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["signlen"].ToString()); if ((smsContent.Length + sign) <= 70) { foreach (string str in phoneNumberArray) { if (checkPhoneNumberFormat(str)) { SMS_MT_INFO smsInfo = new SMS_MT_INFO(priority, batchid, Guid.NewGuid().ToString(), str, '1', smsContent, subNumber, wapPushAddr, sendTime, 1, 1, NEED_DOWN_TIME: needdowntime); result.Add(smsInfo); } } } else { Dictionary dictionary = SplitSmsContent(smsContent, 0x43, sign); foreach (string str2 in phoneNumberArray) { if (checkPhoneNumberFormat(str2)) { foreach (KeyValuePair pair in dictionary) { SMS_MT_INFO info2 = new SMS_MT_INFO(priority, batchid, Guid.NewGuid().ToString(), str2, '1', pair.Value, subNumber, wapPushAddr, sendTime, dictionary.Count, pair.Key); result.Add(info2); } } } } return result; } //public static void AddSMSInfo(string smsContent, string[] phoneNumberArray, string subNumber, string wapPushAddr, string sendTime, string subnumber, string needdowntime, int batchid,int priority) //{ // int sign = System.Configuration.ConfigurationManager.AppSettings["signlen"] == null ? 0 : Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["signlen"].ToString()); // if ((smsContent.Length + sign) <= 70) // { // foreach (string str in phoneNumberArray) // { // if (checkPhoneNumberFormat(str)) // { // SMS_MT_INFO smsInfo = new SMS_MT_INFO(priority,batchid, Guid.NewGuid().ToString(), str, '1', smsContent, subNumber, wapPushAddr, sendTime, 1, 1, NEED_DOWN_TIME: needdowntime); // AddSMSInfo(smsInfo); // } // } // } // else // { // Dictionary dictionary = SplitSmsContent(smsContent, 0x43, sign); // foreach (string str2 in phoneNumberArray) // { // if (checkPhoneNumberFormat(str2)) // { // foreach (KeyValuePair pair in dictionary) // { // SMS_MT_INFO info2 = new SMS_MT_INFO(priority, batchid, Guid.NewGuid().ToString(), str2, '1', pair.Value, subNumber, wapPushAddr, sendTime, dictionary.Count, pair.Key); // AddSMSInfo(info2); // } // } // } // } //} public static void AddSMSInfo(string smsContent, string[] phoneNumberArray, string subNumber, string wapPushAddr, string sendTime, string subnumber, string needdowntime, int batchid, int priority) { //´Ë´¦²»³¤¶ÌÐŵķָî foreach (string str in phoneNumberArray) { if (checkPhoneNumberFormat(str)) { SMS_MT_INFO smsInfo = new SMS_MT_INFO(priority, batchid, Guid.NewGuid().ToString(), str, '1', smsContent, subNumber, wapPushAddr, sendTime, 1, 1, NEED_DOWN_TIME: needdowntime); AddSMSInfo(smsInfo); } } } public static int AddReportWait(ReportInfo report, int ismg) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, Guid.NewGuid().ToString()), DBHelper.MakeInParam("@MSGID", SqlDbType.VarChar, 50, report.MSGID), DBHelper.MakeInParam("@MOBILE_NO", SqlDbType.VarChar, 0x15, report.MOBILE_NO), DBHelper.MakeInParam("@MOBILE_NO_TYPE", SqlDbType.Char, 1, ismg), DBHelper.MakeInParam("@REPORT_SUCCESS", SqlDbType.VarChar, 1, Convert.ToInt32(report.SUCCESS)), DBHelper.MakeInParam("@REPORT_TIME", SqlDbType.DateTime, 20, report.REPORT_TIME), DBHelper.MakeInParam("@REPORT_STAT", SqlDbType.VarChar, 20, report.STAT) }; string commandText = "INSERT INTO SMS_REPORT_WAIT(GUID,MSGID,MOBILE_NO,MOBILE_NO_TYPE,REPORT_SUCCESS,REPORT_TIME,REPORT_STAT) VALUES(@GUID,@MSGID,@MOBILE_NO,@MOBILE_NO_TYPE,@REPORT_SUCCESS,@REPORT_TIME,@REPORT_STAT)"; return DBHelper.ExecuteNonQuery(CommandType.Text, commandText, commandParameters); } public static void Delete_MTWait_CM(string guid) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, guid) }; string commandText = "usp_del_MT_CM"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Delete_MTWait_CU(string guid) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, guid) }; string commandText = "usp_del_MT_CU"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Delete_MTWait_TEL(string guid) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, guid) }; string commandText = "usp_del_MT_TEL"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static DataTable GetItemList_MTWait_CM(int rows) { //first string commandText = "usp_getMT_CM"; //log4netService.Info("»ñÈ¡´ý·¢ËÍÊý¾Ý£ºÐÐÊý:" + rows); return DBHelper.ExecuteDataset(CommandType.StoredProcedure, commandText).Tables[0]; } public static DataTable GetSendMsg() { string commandText = "usp_getSend"; return DBHelper.ExecuteDataset(CommandType.StoredProcedure, commandText).Tables[0]; } public static void UpdateSendMsg(int batchid) { string commandText = "usp_updteSend"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, new SqlParameter[] { new SqlParameter("@batchid", batchid) }); } public static void SendMTTOWait() { string commandText = @"usp_addMTTOWAIT"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText); } public static DataTable GetSendMsgNo(int batchid) { string commandText = "usp_getSendNo"; SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@batchid", batchid) }; return DBHelper.ExecuteDataset(CommandType.StoredProcedure, commandText, commandParameters).Tables[0]; } private static Dictionary SplitSmsContent(string smsContent, int eachSmsLength, int sign) { Func func = null; Dictionary dict = new Dictionary(); int i = -1; int index = 0; List list = (from s in smsContent group s by ++i / eachSmsLength into g select new string(g.ToArray())).ToList(); string str = list[list.Count - 1]; if ((str.Length + sign) > 0x43) { if (func == null) { func = s => ++i / (eachSmsLength - sign); } List list2 = (from g in Enumerable.GroupBy(str, func) select new string(g.ToArray())).ToList(); list.RemoveAt(list.Count - 1); foreach (string str2 in list2) { list.Add(str2); } } list.ForEach(delegate(string s) { dict.Add(++index, s); }); return dict; } public static void AddSMSInfo(DBFactory.SMS_MT_INFO smsInfo) { string commandText = @"usp_addSmsInfo"; SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, smsInfo.Guid), DBHelper.MakeInParam("@SERV_NO", SqlDbType.VarChar, 8, smsInfo.SubNumber), DBHelper.MakeInParam("@MOBILE_NO", SqlDbType.VarChar, 0x15, smsInfo.PhoneNumber), DBHelper.MakeInParam("@MOBILE_NO_TYPE", SqlDbType.Char, 1, smsInfo.MobileNoType), DBHelper.MakeInParam("@SMS_CONTENT", SqlDbType.VarChar, 1000, smsInfo.SmsContent), DBHelper.MakeInParam("@INTO_TIME", SqlDbType.DateTime, 50, smsInfo.SendTime), DBHelper.MakeInParam("@WAPURL", SqlDbType.VarChar, 0xff, smsInfo.WapPushAddr), DBHelper.MakeInParam("@MSGSUM", SqlDbType.Int, 0x10, smsInfo.MsgSum), new SqlParameter("@LONG_SERV_NO",smsInfo.LONG_SERV_NO), new SqlParameter("@SERV_CODE",smsInfo.SERV_CODE), new SqlParameter("@NEED_DOWN_TIME",smsInfo.NEED_DOWN_TIME), new SqlParameter("@batchid",smsInfo.BatchID), new SqlParameter("@Priority",smsInfo.Priority), DBHelper.MakeInParam("@MSGSUB", SqlDbType.Int, 0x10, smsInfo.MsgSub) }; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } /// /// /// /// /// public static void SendSMS(string smscontent, string mobile) { string sql = @" insert into SMS_send(smscontent,sendtime,submittime,subnumber,status) values(@content,getdate(),GETDATE(),'01',0) declare @batchid int set @batchid=@@identity --¸ü¶àµÄÊÖ»úºÅÂë insert into [SMS_SEND_NO](batchid,mobileNo) values(@batchid,@mobile)"; SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@content", SqlDbType.VarChar, 500, smscontent), DBHelper.MakeInParam("@mobile", SqlDbType.VarChar, 50, mobile) }; DBHelper.ExecuteNonQuery(CommandType.Text, sql, commandParameters); } public static DataTable GetItemList_MTWait_CU(int rows) { string commandText = "usp_getMT_CU"; return DBHelper.ExecuteDataset(CommandType.StoredProcedure, commandText).Tables[0]; } public static DataTable GetItemList_MTWait_TEL(int rows) { string commandText = "usp_getMT_TEL"; return DBHelper.ExecuteDataset(CommandType.StoredProcedure, commandText).Tables[0]; } public static void Update_MTWait_CM(string guid, string out_gateway_id) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@OUT_GATEWAY_ID", SqlDbType.VarChar, 20, out_gateway_id), DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, guid) }; string commandText = "usp_updateCMWAIT"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Update_MTWait_CM_REPLACE(string out_gateway_id_src, string out_gateway_id_des) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@OUT_GATEWAY_ID_DES", SqlDbType.VarChar, 20, out_gateway_id_des), DBHelper.MakeInParam("@OUT_GATEWAY_ID_SRC", SqlDbType.VarChar, 20, out_gateway_id_src) }; string commandText = "usp_updateCMWAITReplace"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Update_MTWait_CU(string guid, string out_gateway_id) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@OUT_GATEWAY_ID", SqlDbType.VarChar, 20, out_gateway_id), DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, guid) }; string commandText = "usp_updateCU"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Update_MTWait_CU_REPLACE(string out_gateway_id_src, string out_gateway_id_des) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@OUT_GATEWAY_ID_DES", SqlDbType.VarChar, 20, out_gateway_id_des), DBHelper.MakeInParam("@OUT_GATEWAY_ID_SRC", SqlDbType.VarChar, 20, out_gateway_id_src) }; string commandText = "usp_updateCUReplace"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Update_MTWait_TEL(string guid, string out_gateway_id) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@OUT_GATEWAY_ID", SqlDbType.VarChar, 20, out_gateway_id), DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, guid) }; string commandText = "usp_updateTEL"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void Update_MTWait_TEL_REPLACE(string out_gateway_id_src, string out_gateway_id_des) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@OUT_GATEWAY_ID_DES", SqlDbType.VarChar, 20, out_gateway_id_des), DBHelper.MakeInParam("@OUT_GATEWAY_ID_SRC", SqlDbType.VarChar, 20, out_gateway_id_src) }; string commandText = "usp_updateTELReplace"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static int UpdateMTInfo(ReportInfo report) { //log4netService.Debug(Newtonsoft.Json.JsonConvert.SerializeObject(report)); if ((report.MOBILE_NO != null) && (report.MOBILE_NO.Length > 0)) { //log4netService.Debug("start to running updatereortmobile..."); SqlParameter[] parameterArray = new SqlParameter[] { DBHelper.MakeInParam("@REPORT_SUCCESS", SqlDbType.VarChar, 1, Convert.ToInt32(report.SUCCESS)), DBHelper.MakeInParam("@REPORT_TIME", SqlDbType.DateTime, 20, report.REPORT_TIME), DBHelper.MakeInParam("@REPORT_STAT", SqlDbType.VarChar, 20, report.STAT), DBHelper.MakeInParam("@REPORT_DONWTIME", SqlDbType.VarChar, 20, report.DONE_TIME), DBHelper.MakeInParam("@MSGID", SqlDbType.VarChar, 50, report.MSGID), DBHelper.MakeInParam("@MOBILE_NO", SqlDbType.VarChar, 320, report.MOBILE_NO) }; //log4netService.Debug(Newtonsoft.Json.JsonConvert.SerializeObject(parameterArray)); string str = "usp_updateReportMobile"; return DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, str, parameterArray); } SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@REPORT_SUCCESS", SqlDbType.VarChar, 1, Convert.ToInt32(report.SUCCESS)), DBHelper.MakeInParam("@REPORT_TIME", SqlDbType.DateTime, 20, report.REPORT_TIME), DBHelper.MakeInParam("@REPORT_STAT", SqlDbType.VarChar, 20, report.STAT), DBHelper.MakeInParam("@REPORT_DONWTIME", SqlDbType.VarChar, 20, report.DONE_TIME), DBHelper.MakeInParam("@MSGID", SqlDbType.VarChar, 50, report.MSGID) }; string commandText = "usp_updateReport"; return DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void UpdateMTInfo(SubmitInfo submit) { SqlParameter[] commandParameters = new SqlParameter[] { DBHelper.MakeInParam("@MSGID", SqlDbType.VarChar, 50, submit.RespMsgID), DBHelper.MakeInParam("@FACT_DOWN_TIME", SqlDbType.DateTime, 20, submit.SubmitTime), DBHelper.MakeInParam("@SUBMIT_RESULT", SqlDbType.Int, 0x20, submit.Result), DBHelper.MakeInParam("@SUBMIT_RESEND", SqlDbType.Int, 0x20, submit.ReSend), DBHelper.MakeInParam("@GUID", SqlDbType.VarChar, 50, submit.MTWait.Guid) }; string commandText = "usp_updateMTSubmit"; DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, commandText, commandParameters); } public static void UpdateUnSendMsg() { string sql = "UPDATE SMS_MT_CM_WAIT set OUT_GATEWAY_ID=NULL,updatetime=getdate() where OUT_GATEWAY_ID IS NOT NULL and OUT_GATEWAY_ID!='' and datediff(mi,DOWN_TIME,getdate())>=5"; DBHelper.ExecuteNonQuery(CommandType.Text, sql); } public static Dictionary SplitContent(string smsContent) { int sign = System.Configuration.ConfigurationManager.AppSettings["signlen"] == null ? 0 : Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["signlen"].ToString()); return SplitSmsContent(smsContent, 0x43, sign); } public static bool checkSplitSMSContent(string smsContent) { int sign = System.Configuration.ConfigurationManager.AppSettings["signlen"] == null ? 0 : Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["signlen"].ToString()); if ((smsContent.Length + sign) <= 70) { return false; } else { return true; //Dictionary dictionary = SplitSmsContent(smsContent, 0x43, sign); } } } }