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
namespace AsiaINFO.SMS.BusinessFactory
{
    using AsiaINFO.SMS.DBFactory;
    using AsiaINFO.SMS.Entity;
    using Common;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
 
    public class MTBusiness
    {
        public static void AddReportWait(ReportInfo report, int ismg)
        {
            try
            {
                MTFactory.AddReportWait(report, ismg);
            }
            catch (Exception exception)
            {
                throw new Exception("[MTBusiness.AddReportWait] " + exception.Message);
            }
        }
 
 
        public static void DeleteMTWait(MTWaitInfo mtwait, int ismg)
        {
            try
            {
                switch (ismg)
                {
                    case 1:
                        MTFactory.Delete_MTWait_CM(mtwait.Guid);
                        return;
 
                    case 2:
                        MTFactory.Delete_MTWait_CU(mtwait.Guid);
                        return;
 
                    case 3:
                        MTFactory.Delete_MTWait_TEL(mtwait.Guid);
                        return;
                }
            }
            catch (Exception exception)
            {
                throw new Exception("[MTBusiness.DeleteMTWait] " + exception.Message);
            }
        }
 
        public static List<MTWaitInfo> GetMTWaitList(int rows, int ismg, string out_gateway_id)
        {
           
            List<MTWaitInfo> list = null;
            DataTable table = null;
            try
            {
                SetSendToWait();
                switch (ismg)
                {
                    case 1:
                        table = MTFactory.GetItemList_MTWait_CM(rows);
                        goto Label_0050;
 
                    case 2:
                        table = MTFactory.GetItemList_MTWait_CU(rows);
                        goto Label_0050;
 
                    case 3:
                        table = MTFactory.GetItemList_MTWait_TEL(rows);
                        goto Label_0050;
                }
            }
            catch (Exception exception)
            {
                throw new Exception("[MTBusiness.GetMTWaitList_1] " + exception.Message);
            }
        Label_0050:
            list = (table == null) ? new List<MTWaitInfo>() : new List<MTWaitInfo>(table.Rows.Count);
            foreach (DataRow row in table.Rows)
            {
                try
                {
                    string guid = row["GUID"].ToString().Trim();
                    string longSvrNo = row["LONG_SERV_NO"].ToString().Trim();
                    string svrCode = row["SERV_CODE"].ToString().Trim();
                    string mobileNo = row["MOBILE_NO"].ToString().Trim();
                    int num = Utils.StrToInt(row["MOBILE_NO_TYPE"].ToString().Trim(), 1);
                    string str5 = row["FEE_TYPE"].ToString().Trim();
                    string fee = row["FEE"].ToString().Trim();
                    string str7 = row["SMS_CONTENT"].ToString();
                    string linkId = row["LINK_ID"].ToString().Trim();
                    string wapurl = row["WAPURL"].ToString().Trim();
                    uint msgSum = (uint)Utils.StrToInt(row["MSGSUM"].ToString().Trim(), 1);
                    uint msgSub = (uint)Utils.StrToInt(row["MSGSUB"].ToString().Trim(), 1);
                    MTWaitInfo item = new MTWaitInfo(guid, longSvrNo, svrCode, mobileNo, num, str5, fee, str7, linkId, wapurl, msgSum, msgSub);
                    list.Add(item);
                    continue;
                }
                catch (Exception exception2)
                {
                    throw new Exception("[MTBusiness.GetMTWaitList_2] " + exception2.Message);
                }
            }
            try
            {
                switch (ismg)
                {
                    case 1:
                        foreach (MTWaitInfo info2 in list)
                        {
                            MTFactory.Update_MTWait_CM(info2.Guid, out_gateway_id);
                        }
                        return list;
 
                    case 2:
                        foreach (MTWaitInfo info3 in list)
                        {
                            MTFactory.Update_MTWait_CU(info3.Guid, out_gateway_id);
                        }
                        return list;
 
                    case 3:
                        break;
 
                    default:
                        return list;
                }
                foreach (MTWaitInfo info4 in list)
                {
                    MTFactory.Update_MTWait_TEL(info4.Guid, out_gateway_id);
                }
            }
            catch (Exception exception3)
            {
                throw new Exception("[MTBusiness.GetMTWaitList_3] " + exception3.Message);
            }
            return list;
        }
        /// <summary>
        /// from SMS_Send to SMS_MT and SMS_MT to SMS_CM_WAIT
        /// </summary>
        public static void SetSendToWait()
        {
            try
            {
                DataTable sendMsgDt = MTFactory.GetSendMsg();
                foreach (DataRow dr in sendMsgDt.Rows)
                {
                    int batchid = Int32.Parse(dr["batchid"].ToString());
                    string smscontent = dr["smscontent"].ToString();
                    string sendtime = dr["sendtime"].ToString();
                    string subnumber = dr["subnumber"].ToString();
                    int priority = Int32.Parse(dr["Priority"].ToString());
                    //string svrCode = dr["SER_CODE"].ToString();
                    DataTable sendMsgNODt = MTFactory.GetSendMsgNo(batchid);
                    List<string> numberArr = new List<string>();
                    foreach (DataRow numberDr in sendMsgNODt.Rows)
                    {
                        numberArr.Add(numberDr["mobileNo"].ToString());
                    }
                    
                    MTFactory.AddSMSInfo(smscontent, numberArr.ToArray(), subnumber, "",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),subnumber,sendtime,batchid,priority);
                    MTFactory.UpdateSendMsg(batchid);
                }
                MTFactory.SendMTTOWait();
            }
            catch(Exception ex) {
                log4netService.Error("send±í²åÈëmt±íÒì³£:"+ex.Message);
                throw new Exception("[MTBusiness.SetSendToWait] " + ex.Message);
            
            }
        }
        public static Dictionary<int, string> SplitSmsIfOverLength(string smsContent)
        {
            Func<char, int> func = null;
            Action<string> action = null;
            Dictionary<int, string> dict = new Dictionary<int, string>();
            if ((smsContent != null) && (smsContent.Length <= 70))
            {
                dict.Add(1, smsContent);
                return dict;
            }
            int i = -1;
            int index = 0;
            if (smsContent != null)
            {
                if (func == null)
                {
                    func = s => ++i / 70;
                }
                if (action == null)
                {
                    action = delegate(string s)
                    {
                        dict.Add(++index, s);
                    };
                }
                (from g in Enumerable.GroupBy<char, int>(smsContent, func) select new string(g.ToArray<char>())).ToList<string>().ForEach(action);
            }
            return dict;
        }
 
        public static bool UpdateMTInfo(ReportInfo report)
        {
            bool flag;
            try
            {
                if (MTFactory.UpdateMTInfo(report) > 0)
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception)
            {
                
                throw new Exception("[MTBusiness.UpdateMTInfo2] " + exception.Message+exception.StackTrace);
            }
            return flag;
        }
 
        public static void UpdateMTInfo(SubmitInfo submit)
        {
            try
            {
                MTFactory.UpdateMTInfo(submit);
            }
            catch (Exception exception)
            {
                throw new Exception("[MTBusiness.UpdateMTInfo1] " + exception.Message);
            }
        }
 
        public static void UpdateMTWait(string out_gateway_id, int ismg)
        {
            try
            {
                switch (ismg)
                {
                    case 1:
                        MTFactory.Update_MTWait_CM_REPLACE(out_gateway_id, "");
                        return;
 
                    case 2:
                        MTFactory.Update_MTWait_CU_REPLACE(out_gateway_id, "");
                        return;
 
                    case 3:
                        MTFactory.Update_MTWait_TEL_REPLACE(out_gateway_id, "");
                        return;
                }
            }
            catch (Exception exception)
            {
                throw new Exception("[MTBusiness.UpdateMTWait] " + exception.Message);
            }
        }
 
        //ÖØÐ·¢ËÍ
        public static void UpdateUnSendMsg()
        {
            MTFactory.UpdateUnSendMsg();
        }
    }
}