wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
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<SMS_MT_INFO> GetSMSInfo(string smsContent, string[] phoneNumberArray, string subNumber, string wapPushAddr, string sendTime, string subnumber, string needdowntime, int batchid, int priority)
        {
            List<SMS_MT_INFO> result = new List<SMS_MT_INFO>();
            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<int, string> dictionary = SplitSmsContent(smsContent, 0x43, sign);
                foreach (string str2 in phoneNumberArray)
                {
                    if (checkPhoneNumberFormat(str2))
                    {
                        foreach (KeyValuePair<int, string> 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<int, string> dictionary = SplitSmsContent(smsContent, 0x43, sign);
        //        foreach (string str2 in phoneNumberArray)
        //        {
        //            if (checkPhoneNumberFormat(str2))
        //            {
        //                foreach (KeyValuePair<int, string> 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<int, string> SplitSmsContent(string smsContent, int eachSmsLength, int sign)
        {
            Func<char, int> func = null;
            Dictionary<int, string> dict = new Dictionary<int, string>();
            int i = -1;
            int index = 0;
            List<string> list = (from s in smsContent
                                 group s by ++i / eachSmsLength into g
                                 select new string(g.ToArray<char>())).ToList<string>();
            string str = list[list.Count - 1];
            if ((str.Length + sign) > 0x43)
            {
                if (func == null)
                {
                    func = s => ++i / (eachSmsLength - sign);
                }
                List<string> list2 = (from g in Enumerable.GroupBy<char, int>(str, func) select new string(g.ToArray<char>())).ToList<string>();
                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);
        }
 
 
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="smscontent"></param>
        /// <param name="mobile"></param>
        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<int, string> 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<int, string> dictionary = SplitSmsContent(smsContent, 0x43, sign);
            }
        }
    }
}