wangsheng
2021-12-01 5944b55b1486943c696a3beb004d564dceb81cf2
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
<%@ WebHandler Language="C#" Class="GwSpHandler" %>
 
using Common;
using Dao;
using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
 
public class GwSpHandler : PageHandler<SysUser>
{
    private GwSpDao _Dao = new GwSpDao();
    private GwSpDao _GwSpDao = new GwSpDao();
    private List<GwOp> _OpList;
    private List<GwOpGroup> _GroupList;
    private List<GwClient> _ClientList;
    private List<GwDiverter> _DiverterList;
    private List<GwAp> _APList;
    private List<GwStrategy> _StrategyList;
 
    private List<GwOp> OpList
    {
        get
        {
            if (this._OpList == null)
            {
                using (GwOpDao gwOpDao = new GwOpDao())
                    this._OpList = gwOpDao.LoadInfoList();
            }
            return this._OpList;
        }
    }
 
    private List<GwOpGroup> GroupList
    {
        get
        {
            if (this._GroupList == null)
            {
                using (GwOpGroupDao gwOpGroupDao = new GwOpGroupDao())
                    this._GroupList = gwOpGroupDao.GetGroupList();
            }
            return this._GroupList;
        }
    }
 
    private List<GwClient> ClientList
    {
        get
        {
            if (this._ClientList == null)
            {
                using (GwClientDao gwClientDao = new GwClientDao())
                    this._ClientList = gwClientDao.LoadInfoList("", "", "", "");
            }
            return this._ClientList;
        }
    }
 
    private List<GwDiverter> DiverterList
    {
        get
        {
            if (this._DiverterList == null)
            {
                using (GwDiverterDao gwDiverterDao = new GwDiverterDao())
                    this._DiverterList = gwDiverterDao.LoadList();
            }
            return this._DiverterList;
        }
    }
 
    private List<GwAp> APList
    {
        get
        {
            if (this._APList == null)
            {
                using (GwApDao gwApDao = new GwApDao())
                    this._APList = gwApDao.LoadInfoList();
            }
            return this._APList;
        }
    }
 
    private List<GwStrategy> StrategyList
    {
        get
        {
            if (this._StrategyList == null)
            {
                using (GwStrategyDao gwStrategyDao = new GwStrategyDao())
                    this._StrategyList = gwStrategyDao.LoadInfoList(string.Empty, string.Empty);
            }
            return this._StrategyList;
        }
    }
 
    public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context)
    {
        string @string = context.GetString("action");
        switch (@string)
        {
            case "updateSpStatus":
                return this.UpdateSpStatus(context);
            case "getGwspDetailed":
                return this.GetGwspDetailed(context);
            case "loadChargeLogPageList":
                return this.LoadChargeLogPageList(context);
            case "batchUpdateOp":
                return this.BatchUpdateOp(context);
            case "charge":
                return this.Charge(context);
            case "loadChargeLog":
                return this.LoadChargeLog(context);
            case "payMentDetails":
                return this.PayMentDetails(context);
            case "delete":
                return this.Delete(context);
            case "add":
                return this.Add(context);
            case "loadGwSpPageList":
                return this.LoadGwSpPageList(context);
            case "loadGwSpAccountPageList"://加载账号列表
                return this.LoadGwSpAccountPageList(context);
            case "update":
                return this.Update(context);
            case "getSignatureInfo":
                return this.GetSignatureInfo(context);
            case "updateSignature":
                return this.UpdateSignature(context);
            case "updatePattern":
                return this.UpdatePattern(context);
            case "getPatternInfo":
                return this.GetPatternInfo(context);
            case "loadPrePatternList":
                return this.LoadPrePatternList(context);
            case "updatePrePatternStatus":
                return this.UpdatePrePatternStatus(context);
            case "getPrePattern":
                return this.GetPrePattern(context);
            default:
                throw new Exception("Invalid Action=" + @string);
        }
    }
 
    //新加
 
    private JsonPageResult UpdateSpStatus(PageContext<SysUser> context)
    {
        string @string = context.GetString("spid");
        int @int = context.GetInt("status");
        if (string.IsNullOrEmpty(@string))
            throw new ArgumentException("获取客户账号参数SPID失败");
        if (!this._GwSpDao.UpdateSpStatus(@string, @int))
            throw new ArgumentNullException("修改失败!");
        // WriteSysLogHelper.WriteSysLog(context.SessionObject.Account, 3023, 302, string.Format("通道账号{0}由{2}状态修改为{1}状态", (object)@string, @int != 1 ? (object)"停用" : (object)"启用", @int == 1 ? (object)"停用" : (object)"启用"), context.ClientIP);
        return new JsonPageResult(true, (object)"更改账号状态成功!");
    }
 
    //结束  
 
    private JsonPageResult GetGwspDetailed(PageContext<SysUser> context)
    {
        string @string = context.GetString("spID");
        if (string.IsNullOrEmpty(@string))
            throw new ArgumentException("获取SPID错误");
        using (GwSpDao gwSpDao = new GwSpDao())
        {
            GwSp gwSp = gwSpDao.Get(@string);
            string[] strArray = gwSp.McExpression.Split(new char[1]
            {
        ';'
            }, StringSplitOptions.RemoveEmptyEntries);
            string str = (Convert.ToInt32(strArray[0]) != 0 ? strArray[0] + "条/1分钟;" : "") + (Convert.ToInt32(strArray[1]) != 0 ? strArray[1] + "条/5分钟;" : "") + (Convert.ToInt32(strArray[2]) != 0 ? strArray[2] + "条/10分钟;" : "") + (Convert.ToInt32(strArray[3]) != 0 ? strArray[3] + "条/半小时;" : "") + (Convert.ToInt32(strArray[4]) != 0 ? strArray[4] + "条/1小时;" : "") + (Convert.ToInt32(strArray[5]) != 0 ? strArray[5] + "条/4小时;" : "") + (Convert.ToInt32(strArray[6]) != 0 ? strArray[6] + "条/6小时;" : "") + (Convert.ToInt32(strArray[7]) != 0 ? strArray[7] + "条/12小时;" : "") + (Convert.ToInt32(strArray[8]) != 0 ? strArray[8] + "条/24小时;" : "");
            return new JsonPageResult(true, (object)new
            {
                Get = gwSp,
                McExpression = str
            });
        }
    }
 
    private JsonPageResult LoadChargeLogPageList(PageContext<SysUser> context)
    {
        string string1 = context.GetString("SpID");
        string string2 = context.GetString("ClientID");
        string string3 = context.GetString("ClientName");
        string str1 = context.GetString("sDate");
        string str2 = context.GetString("EndTime");
        int recordcount = 0;
        int int1 = context.GetInt("pageSize", 20);
        int int2 = context.GetInt("pageIndex", 1);
        if (string.IsNullOrEmpty(str1))
            str1 = DateTime.Now.AddDays(-1.0).ToString("yyyy-MM-dd");
        if (string.IsNullOrEmpty(str2))
            str2 = DateTime.Now.ToString("yyyy-MM-dd");
        List<GwChargeLog> list = new GwChargeLogDao().LoadInfoList(string2, string3, string1, Convert.ToDateTime(str1), Convert.ToDateTime(str2).AddDays(1.0), out recordcount, int1, int2);
        string str3 = "";
        if (list != null && list.Count > 0)
        {
            int num = 0;
            UserDao userDao = new UserDao();
            foreach (GwChargeLog gwChargeLog in list)
            {
                ++num;
                str3 = str3 + (object)"<tr class=\"row-" + (object)(num % 2) + "\" ><td>" + (object)gwChargeLog.ChargeID + "</td><td>" + gwChargeLog.ClientID + "</td><td>" + gwChargeLog.ClientName + "</td><td>" + gwChargeLog.SpID + "</td><td>" + (object)gwChargeLog.OccurTime + "</td>";
                str3 = string.Concat(new object[4]
                {
          (object) str3,
          (object) "<td>",
          (object) ((double) gwChargeLog.Amount / 1000.0),
          (object) "元</td>"
                });
                str3 = str3 + "<td>" + gwChargeLog.OperatorID + "</td>";
                string str4 = "<font color='red'>待处理</font>";
                if (gwChargeLog.Flag == 1)
                    str4 = "已处理";
                str3 = str3 + "<td>" + str4 + "</td>";
                string str5 = gwChargeLog.FlushTime.ToString("yyyy-MM-dd HH:mm:ss");
                if (str5.IndexOf("0001") > 0)
                    str5 = "";
                str3 = str3 + "<td>" + str5 + "</td>";
                str3 = str3 + "<td>" + gwChargeLog.Remark + "</td>";
                str3 += "</tr>";
            }
        }
        else
            str3 += "<tr><td colspan=\"10\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
        return new JsonPageResult(true, (object)new
        {
            Table = str3.ToString(),
            TotalCount = recordcount
        });
    }
 
    private JsonPageResult UpdatePattern(PageContext<SysUser> context)
    {
        this._Dao.UpdatePattern(context.GetString("spid"), context.GetInt("enabled"), context.GetString("pattern"), context.OperatorID);
        return new JsonPageResult(true, (object)"账户免审内容报备更新成功!");
    }
 
    private JsonPageResult GetPatternInfo(PageContext<SysUser> context)
    {
        return new JsonPageResult(true, (object)this._Dao.GetPattern(context.GetString("spid")));
    }
 
    private JsonPageResult UpdateSignature(PageContext<SysUser> context)
    {
        string string1 = context.GetString("spid");
        int @int = context.GetInt("signatureMode");
        string string2 = context.GetString("signatures");
        this._Dao.UpdateSignature(new SpSignatureInfo()
        {
            SpID = string1,
            SignatureMode = @int,
            Signatures = string2
        });
        return new JsonPageResult(true, (object)"账户签名更新成功!");
    }
 
    private JsonPageResult GetSignatureInfo(PageContext<SysUser> context)
    {
        return new JsonPageResult(true, (object)this._Dao.GetSignature(context.GetString("spid")));
    }
 
 
    /// <summary>
    /// 加载账号页面列表
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult LoadGwSpAccountPageList(PageContext<SysUser> context)
    {
        string string1 = context.GetString("apID");
        string clientId = context.GetString("clientID");
        string string2 = context.GetString("spID");
        string string3 = context.GetString("opID");
        int int1 = context.GetInt("routerType");
        string string4 = context.GetString("clientName");
        int int2 = context.GetInt("chargeType");
        int recordCount = 0;
        int int3 = context.GetInt("pageSize", 20);
        int int4 = context.GetInt("pageIndex", 1);
        int int5 = context.GetInt("resendStatus", 1);
        if (!string.IsNullOrEmpty(string3) && int1 <= 0)
            throw new ArgumentException("请选择通道组路由模式");
        GwSpDao gwSpDao = new GwSpDao();
        string apId = "0";
        if (this.IsInt(string1))
            apId = string1;
        if (string.IsNullOrEmpty(clientId) && !string.IsNullOrEmpty(string4))
            clientId = new GwClientDao().GetClientName(string4).ClientID;
        //加载账号列表信息
        List<GwSp> list = gwSpDao.LoadInfoList(string2, apId, clientId, int1, string3, int2, int4, int3, int5.ToString(),out recordCount);
        string str1 = "";
        if (list != null && list.Count > 0)
        {
            foreach (GwSp gwSp in list)
            {
                str1 = str1 + "<tr><td  rowspan=\"1\" ><input type=\"checkbox\"name=\"checkbox\" value=\"" + gwSp.SpID + "\"/></td><td rowspan=\"1\">" + gwSp.SpID + "<div class=\"text-muted\">" + this.GetAPName(gwSp.ApID) + "</div><div class=\"text-muted\">" + this.GetClientName(gwSp.ClientID) + "</div>";
                str1 += "</td>";
                if (gwSp.RouterType == 1)
                {
                    str1 += "<td rowspan=\"1\"><div class=\"btn  btn-primary btn-xs\">点路由</div>";
                    str1 += string.Format("<div>移动:{0}</div><div>电信:{1}</div><div>联通:{2}</div>", (object)this.GetOpName(gwSp.CMOPID), (object)this.GetOpName(gwSp.CTOPID), (object)this.GetOpName(gwSp.UNOPID));
                }
                else if (gwSp.RouterType == 3)
                {
                    str1 += "<td rowspan=\"1\"><div class=\"btn  btn-success  btn-xs\">组路由</div>";
                    str1 += string.Format("<div>移动:{0}</div><div>电信:{1}</div><div>联通:{2}</div>", (object)this.GetGroupName(gwSp.CMGroupID), (object)this.GetGroupName(gwSp.CTGroupID), (object)this.GetGroupName(gwSp.CUGroupID));
                }
 
                if (gwSp.RESEND_STATUS == 1)
                {
                    str1 += "<td rowspan=\"1\"><div class=\"btn  btn-primary  btn-xs\">启用失败补发</div>";
                    //str1 += string.Format("<div>移动:{0}</div><div>电信:{1}</div><div>联通:{2}</div>", (object)this.GetGroupName(gwSp.RESEND_CM_GROUPID), (object)this.GetGroupName(gwSp.RESEND_CU_GROUPID), (object)this.GetGroupName(gwSp.RESEND_CT_GROUPID));
                    //账户页面显示补发通道具体的通道
                }
                else
                {
                    str1 += "<td rowspan=\"1\"><div class=\"btn  btn-danger  btn-xs\">停用失败补发</div>";
                }
 
 
                string str2 = "<div class=\"text-muted\">" + gwSp.ChargerTypeText + "</div>";
                if (gwSp.ChargerTypeText == "后付费")
                    str2 = "<div  style=\"color:red\">" + gwSp.ChargerTypeText + "</div>";
                str1 = str1 + (object)"<td><div class=\"text-muted\">" + (object)(gwSp.Balance / (long)gwSp.Price) + "条/" + (object)((double)gwSp.Balance / 1000.0) + "元</div>";
                str1 = str1 + (object)str2 + "<div class=\"text-muted\">" + (object)((double)gwSp.Price / 1000.0) + "元/条</div>";
                if (context.HasRight("3021"))
                    str1 += string.Format(" <a class=\"btn btn-xs btn-success action-modal-charge\"  data-id=\"{0}\"><i class=\"fa fa-cny\"></i> 充值</a>", (object)gwSp.SpID);
                if (context.HasRight("3022"))
                    str1 += string.Format(" <a class=\" btn btn-success btn-xs action-modal-Acctunchargelog\"  data-id=\"{0}\"><i class=\"fa fa-list-alt\"></i> 充值日志</a>", (object)gwSp.SpID);
                if (gwSp.BalanceThreshold > 0 && !string.IsNullOrEmpty(gwSp.AlarmMobile))
                    str1 = str1 + (object)"<div class=\"text-danger\">" + (object)(gwSp.BalanceThreshold / 1000) + "元(" + gwSp.AlarmMobile + ")</div>";
                str1 += "</td>";
                str1 = str1 + "<td>" + this.GetDiverterName(gwSp.DiverterID);
                str1 = str1 + "<div class=\"text-muted\">" + this.GetStratedyName(gwSp.StrategyID) + "</div>";
                str1 = str1 + "<div class=\"text-muted\"><font color=\"red\">" + this.GwSPAuditingName(gwSp.AuditingMode) + "</font></div>";
                str1 = str1 + "<div class=\"text-muted\">全局黑名单" + gwSp.BlackModeText + "</div>";
                str1 += "</td>";
                str1 = str1 + "<td>" + gwSp.AccessCode;
                str1 = str1 + "<div class=\"text-muted\">" + (gwSp.ExtnoExtensionMode == 1 ? "禁止客户扩展" : "允许客户扩展") + "</div>";
                str1 = str1 + "<div>" + (gwSp.AccessCodeMode == 1 ? "通道直连模式" : "虚拟接入模式") + "</div></td>";
                str1 = str1 + "<td>" + this.FormatIpHtml(gwSp.ClientIp) + "</td>";
                // str1 = str1 + "<td>" + this.GetStatusText(gwSp.Status);
                str1 = str1 + "<td>" + this.GetStatusText(gwSp.Status, gwSp.SpID);
                str1 += "</td>";
                str1 += "<td rowspan=\"1\" class=\"text-right\">";
                if (context.HasRight("3023"))
                    str1 += string.Format(" <a class=\"btn-block btn btn-primary btn-xs action-modal-edit\" data-id=\"{0}\"><i class=\"fa fa-edit\"></i>  编辑</a>", (object)gwSp.SpID);
                str1 += string.Format(" <a class=\"btn-block btn btn-success btn-xs action-create-summary\" data-id=\"{0}\">账号摘要</a>", (object)gwSp.SpID);
                if (context.HasRight("3024"))
                    str1 += string.Format(" <a class=\"btn-block btn btn-xs btn-default action-delete\"  data-id=\"{0}\"><i class=\"fa fa-trash\"></i> 删除</a>", (object)gwSp.SpID);
                str1 += "</td>";
                str1 += "</tr>";
            }
        }
        else
            str1 += "<tr><td colspan=\"14\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
        return new JsonPageResult(true, (object)new
        {
            Table = str1.ToString(),
            TotalCount = recordCount
        });
    }
 
    private string GwSPAuditingName(int auditingMode)
    {
        string str = "";
        switch (auditingMode)
        {
            case 0:
                str = "免审模式";
                break;
            case 1:
                str = "手工审核模式";
                break;
            case 2:
                str = "内容报备优先";
                break;
            case 3:
                str = "拦截策略+内容报备";
                break;
        }
        return str;
    }
 
    public bool IsInt(string input)
    {
        for (int index = 0; index < input.Length; ++index)
        {
            if (!char.IsNumber(input, index))
                return false;
        }
        return true;
    }
 
    private string GetAPName(int apID)
    {
        if (this.APList == null)
            return string.Empty;
        GwAp gwAp = this.APList.Find((Predicate<GwAp>)(op => op.ApID == apID));
        if (gwAp != null)
        {
            //return string.Format("{0}-{1}", (object)gwAp.ApID, (object)gwAp.ApName);//2021.2.24.wzp变更,后续可以删除
            return string.Format("接入协议:{0}", (object)gwAp.ApName);
        }
        return string.Empty;
    }
 
    private string GetOpName(int opID)
    {
        if (this.OpList == null)
            return string.Empty;
        GwOp gwOp = this.OpList.Find((Predicate<GwOp>)(op => op.OpID == opID));
        if (gwOp != null)
            return string.Format("{0}-{1}", (object)gwOp.OpID, (object)gwOp.OpName);
        return string.Empty;
    }
 
    private string GetGroupName(int groupID)
    {
        if (this.GroupList == null)
            return string.Empty;
        GwOpGroup gwOpGroup = this.GroupList.Find((Predicate<GwOpGroup>)(group => group.GroupID == groupID));
        if (gwOpGroup != null)
            return string.Format("{0}-{1}", (object)gwOpGroup.GroupID, (object)gwOpGroup.GroupName);
        return string.Empty;
    }
 
    private string GetClientName(string clientID)
    {
        if (this.ClientList == null)
            return string.Empty;
        GwClient gwClient = this.ClientList.Find((Predicate<GwClient>)(client => client.ClientID == clientID));
        if (gwClient != null)
            return string.Format("{0}<div class=\"text-muted\">{1}</div>", (object)gwClient.ClientID, (object)gwClient.ClientName);
        return string.Format("{0}", (object)clientID);
    }
 
    private string FormatIpHtml(string p)
    {
        if (string.IsNullOrEmpty(p))
            return string.Empty;
        return p.Replace("|", "<br/>");
    }
 
    //private string GetStatusText(int status)
    //{
    //  return status == 0 ? "<span class=\"btn btn-xs \">已停用</span>" : "<span class=\"btn btn-xs  btn-success\">已启用</span>";
    //}
 
 
    //新加客户账号状态开启关闭
    private string GetStatusText(int status, string spid)
    {
        if (status == 0)
            return string.Format("<span class=\"action-updateStatus btn btn-xs btn-default\" data-status=\"1\" data-spid=\"{0}\">已停用</span>", (object)spid);
        return string.Format("<span class=\"action-updateStatus btn btn-xs  btn-success \" data-status=\"0\" data-spid=\"{0}\">已启用</span>", (object)spid);
    }
    //
 
    private string GetStratedyName(int strategyID)
    {
        GwStrategy gwStrategy = this.StrategyList.Find((Predicate<GwStrategy>)(dv => dv.StrategyId == strategyID));
        if (gwStrategy == null)
            return "未设置拦截策略";
        return "【" + gwStrategy.StrategyName + "】拦截策略";
    }
 
    protected string GetDiverterName(int diverterID)
    {
        GwDiverter gwDiverter = this.DiverterList.Find((Predicate<GwDiverter>)(dv => dv.DiverterID == diverterID));
        if (gwDiverter == null)
            return "未设置导流";
        return "【" + gwDiverter.DiverterName + "】导流策略";
    }
 
    private JsonPageResult LoadGwSpPageList(PageContext<SysUser> context)
    {
        string string1 = context.GetString("SelectedSpID");
        string string2 = context.GetString("SelectedClientID");
        int recordCount = 0;
        int int1 = context.GetInt("pageSize", 20);
        int int2 = context.GetInt("pageIndex", 1);
        StringBuilder stringBuilder = new StringBuilder();
        using (GwSpDao gwSpDao = new GwSpDao())
        {
            List<SpSignatureInfo> signatureInfoList = gwSpDao.GetSignatureInfoList(string2, string1, out recordCount, int2, int1);
            List<SpCTPatternInfo> patternList = gwSpDao.GetPatternList();
            if (signatureInfoList != null && signatureInfoList.Count > 0)
            {
                foreach (SpSignatureInfo spSignatureInfo in signatureInfoList)
                {
                    stringBuilder.AppendFormat("<tr><td>{0}({1})</td><td>{3}</td><td>\r\n                    <a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-signature btn-xs btn btn-warning\">{2}</a>\r\n                    </td></tr>", (object)spSignatureInfo.SpID, (object)spSignatureInfo.ClientID, (object)SpSignatureInfo.GetSignatureModeText(spSignatureInfo.SignatureMode), (object)spSignatureInfo.Signatures);
                    SpCTPatternInfo pattern = this.GetPattern(patternList, spSignatureInfo.SpID);
                    stringBuilder.AppendFormat("<tr><td></td><td>{1}</td><td>\r\n                    <a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-pattern btn-xs btn btn-primary\">{2}</a>\r\n                    </td></tr>", (object)spSignatureInfo.SpID, (object)pattern.Pattern, pattern.Enabled == 1 ? (object)"免审内容启用" : (object)"免审内容未启用");
                }
            }
            else
                stringBuilder.AppendFormat("<tr><td colspan=\"8\" style=\"text-align: center;\">暂时无数据</td></tr>");
        }
        return new JsonPageResult(true, (object)new
        {
            Table = stringBuilder.ToString(),
            TotalCount = recordCount
        });
    }
 
    private SpCTPatternInfo GetPattern(List<SpCTPatternInfo> patternList, string spid)
    {
        return patternList.Find((Predicate<SpCTPatternInfo>)(sp => sp.SpID == spid)) ?? new SpCTPatternInfo();
    }
 
 
    //保存更新后的账号信息
    private JsonPageResult Update(PageContext<SysUser> context)
    {
        GwSp o = new GwSp();
        o.SpID = context.GetString("SpID");
        o.ApID = context.GetInt("ApID");
        o.CombinationMode = context.GetInt("CombinationMode");
        o.ClientID = context.GetString("ClientID");
        o.StrategyID = context.GetInt("StrategyID", 0);
        o.ChannelType = context.GetString("ChannelType");
        o.Password = context.GetString("Password");
        o.ClientIp = context.GetString("ClientIp");
        o.ClientPort = context.GetInt("ClientPort", 0);
        o.AccessCode = context.GetString("AccessCode");
        o.Priority = context.GetInt("Priority", 0);
        o.Price = Math.Max((int)(context.GetDecimal("Price", new Decimal(4, 0, 0, false, (byte)2)) * new Decimal(1000)), 1);
        o.ChargeType = context.GetInt("ChargeType", 0);
        o.Threshold = Math.Max(context.GetInt("Threshold", 10), 10);
        o.MaxConnCount = context.GetInt("MaxConnCount", 1);
        o.Remark = context.GetString("Remark");
        o.TimePermitting = context.GetString("TimePermitting");
        o.DefishingTimeout = context.GetInt("DefishingTimeout", 0);
        o.DefishingThreshold = context.GetInt("DefishingThreshold", 0);
        o.RejectIfForbidden = context.GetInt("RejectIfForbidden", 0);
        o.RejectIfNoSignature = context.GetInt("RejectIfNoSignature", 0);
        o.RefundIfUndelivered = context.GetInt("RefundIfUndelivered", 0);
        o.Signatures = context.GetString("Signatures");
        o.AuditingMode = context.GetInt("AuditingMode");
        o.DeductPercent = context.GetInt("DeductPercent");
        if (context.GetInt("RouterType", 1) == 1)
        {
            o.CMOPID = context.GetInt("CMOPID");
            o.CTOPID = context.GetInt("CTOPID");
            o.UNOPID = context.GetInt("UNOPID");
        }
        else
        {
            o.CMOPID = 0;
            o.CTOPID = 0;
            o.UNOPID = 0;
        }
        o.DefishingOPID = context.GetInt("DefishingOPID");
        o.RouterType = context.GetInt("RouterType", 1);
        o.CUextparams = context.GetString("CDparams");
        o.CMextparms = context.GetString("CMparams");
        o.CTextparams = context.GetString("CTparams");
        o.Status = context.GetInt("Status", 1);
        o.AccessCodeMode = context.GetInt("accessCodeMode", 0);
        o.ExtnoExtensionMode = context.GetInt("extnoExtensionMode", 0);
        o.FeeShortLength = context.GetInt("FeeShortLength", 67);
        o.FeeLongLength = context.GetInt("FeeLongLength", 67);
        o.BlackMode = context.GetInt("BlackMode", 1);
        o.MCPM = 10;
        if (context.GetInt("MCPM1") > context.GetInt("MCPM2"))
            throw new ArgumentException("单号码当前设置不能大于后面一个设置的数值");
        string str = context.GetInt("MCPM1") + ";" + context.GetInt("MCPM2") + ";" + context.GetInt("MCPM3") + ";" + context.GetInt("MCPM4") + ";" + context.GetInt("MCPM5") + ";" + context.GetInt("MCPM6") + ";" + context.GetInt("MCPM7") + ";" + context.GetInt("MCPM8") + ";" + context.GetInt("MCPM9");
        o.McExpression = str;
        o.DiverterID = context.GetInt("DiverterID");
        if (context.GetInt("RouterType", 1) == 3)
        {
            o.CMGroupID = context.GetInt("CMGroupID");
            o.CUGroupID = context.GetInt("CUGroupID");
            o.CTGroupID = context.GetInt("CTGroupID");
        }
        else
        {
            o.CMGroupID = 0;
            o.CUGroupID = 0;
            o.CTGroupID = 0;
        }
        o.BalanceThreshold = context.GetInt("BalanceThreshold") * 1000;
        o.AlarmMobile = context.GetString("AlarmMobile");
        o.ForceSignFlag = context.GetInt("ForceSignFlag");
        o.ForceSign = context.GetString("ForceSign");
        o.SignatureMode = context.GetInt("signatureMode");
        o.Signatures = context.GetInt("signatureMode") == 0 ? o.Signatures : context.GetString("signatures");
 
        o.VerCodeMode = context.GetInt("VerCodeMode", 0);
        o.ProvincialNetworkMode = context.GetInt("ProvincialNetworkMode", 0);
 
        //补发通道
        o.RESEND_STATUS = context.GetInt("resendEnabled", 0);
        if (o.RESEND_STATUS == 1)
        {
            o.RESEND_CM_GROUPID = context.GetInt("ReSendCmGroupID", 0);
            o.RESEND_CU_GROUPID = context.GetInt("ReSendCuGroupID", 0);
            o.RESEND_CT_GROUPID = context.GetInt("ReSendCtGroupID", 0);
        }
 
        //携号转网配置
        o.TransferFlag = context.GetInt("TransferFlag",0);
 
        SpCTPatternInfo cTPattern = new SpCTPatternInfo();
        cTPattern.SpID = context.GetString("SpID");
        cTPattern.Enabled = context.GetInt("enabled");
        cTPattern.Pattern = context.GetString("patternContent");
        if (!Regex.IsMatch(o.SpID, "^\\d{6}$"))
            throw new Exception("账号必须为6位数字!");
        if (o.AccessCodeMode == 1)
        {
            if (o.DiverterID != 0)
                throw new Exception("通道直连模式下无法进行导流");
            if (o.RouterType == 3)
                throw new Exception("通道直连模式下无法使用通道组路由模式");
        }
        if (!string.IsNullOrEmpty(o.AccessCode) && !Regex.IsMatch(o.AccessCode, "^[0-9]*$"))
            throw new Exception("扩展号必须为数字");
        if (o.CMOPID == 0 && o.UNOPID == 0 && (o.CTOPID == 0 && o.RouterType == 1))
            throw new ArgumentException("至少为账号指定一个通道!");
        if (o.CMGroupID == 0 && o.CUGroupID == 0 && (o.CTGroupID == 0 && o.RouterType == 3))
            throw new ArgumentException("至少为账号指定一个通道组!");
        if (!string.IsNullOrEmpty(o.AlarmMobile) && !Regex.IsMatch(o.AlarmMobile, "1\\d{10}"))
            throw new Exception("告警号码格式不正确!");
        if (string.IsNullOrEmpty(o.ClientID))
            throw new Exception("请选择账号所属客户!");
        if (string.IsNullOrEmpty(o.Password))
            throw new Exception("账号密码不能为空");
        this._Dao.Update(o);
        this._Dao.UpdatePattern(cTPattern, context.OperatorID); //更新账号里面的报备内容
        return new JsonPageResult(true, (object)("账户" + o.SpID + "修改成功!"));
    }
 
    private JsonPageResult Add(PageContext<SysUser> context)
    {
        GwSp o = new GwSp();
        o.SpID = context.GetString("SpID");
        o.ApID = context.GetInt("ApID");
        o.CombinationMode = context.GetInt("CombinationMode");
        o.ClientID = context.GetString("ClientID");
        o.StrategyID = context.GetInt("StrategyID", 0);
        o.ChannelType = context.GetString("ChannelType");
        o.Password = context.GetString("Password");
        o.ClientIp = context.GetString("ClientIp");
        o.ClientPort = context.GetInt("ClientPort", 0);
        o.AccessCode = context.GetString("AccessCode");
        o.Priority = context.GetInt("Priority", 0);
        o.Price = Math.Max((int)(context.GetDecimal("Price", new Decimal(4, 0, 0, false, (byte)2)) * new Decimal(1000)), 1);
        o.ChargeType = context.GetInt("ChargeType", 0);
        o.Threshold = Math.Max(context.GetInt("Threshold", 10), 10);
        o.MaxConnCount = context.GetInt("MaxConnCount", 1);
        o.Remark = context.GetString("Remark");
        o.TimePermitting = context.GetString("TimePermitting");
        o.DefishingTimeout = context.GetInt("DefishingTimeout", 0);
        o.DefishingThreshold = context.GetInt("DefishingThreshold", 0);
        o.RejectIfForbidden = context.GetInt("RejectIfForbidden", 0);
        o.RejectIfNoSignature = context.GetInt("RejectIfNoSignature", 0);
        o.RefundIfUndelivered = context.GetInt("RefundIfUndelivered", 0);
        o.Signatures = context.GetString("Signatures");
        o.AuditingMode = context.GetInt("AuditingMode");
        o.DeductPercent = context.GetInt("DeductPercent");
        o.CMOPID = context.GetInt("CMOPID");
        o.CTOPID = context.GetInt("CTOPID");
        o.UNOPID = context.GetInt("UNOPID");
        o.DefishingOPID = context.GetInt("DefishingOPID");
        o.RouterType = context.GetInt("RouterType", 1);
        o.CUextparams = context.GetString("CDparams");
        o.CMextparms = context.GetString("CMparams");
        o.CTextparams = context.GetString("CTparams");
        o.Status = context.GetInt("Status", 1);
        o.FeeShortLength = context.GetInt("FeeShortLength", 67);
        o.FeeLongLength = context.GetInt("FeeLongLength", 67);
        o.BlackMode = context.GetInt("BlackMode", 1);
        o.MCPM = 10;
        string str = context.GetString("MCPM1") + ";" + context.GetString("MCPM2") + ";" + context.GetString("MCPM3") + ";" + context.GetString("MCPM4") + ";" + context.GetString("MCPM5") + ";" + context.GetString("MCPM6") + ";" + context.GetString("MCPM7") + ";" + context.GetString("MCPM8") + ";" + context.GetString("MCPM9");
        o.McExpression = str;
        o.DiverterID = context.GetInt("DiverterID");
        o.CMGroupID = context.GetInt("CMGroupID");
        o.CUGroupID = context.GetInt("CUGroupID");
        o.CTGroupID = context.GetInt("CTGroupID");
        o.ForceSignFlag = context.GetInt("ForceSignFlag");
        o.ForceSign = context.GetString("ForceSign");
        o.SignatureMode = context.GetInt("signatureMode");
        o.Signatures = context.GetString("signatures");
        string string1 = context.GetString("SpID");
        int @int = context.GetInt("enabled");
 
        o.VerCodeMode = context.GetInt("VerCodeMode");
        o.ProvincialNetworkMode = context.GetInt("ProvincialNetworkMode");
 
 
        //补发通道
        o.RESEND_STATUS = context.GetInt("resendEnabled", 0);
        if (o.RESEND_STATUS == 1)
        {
            o.RESEND_CM_GROUPID = context.GetInt("ReSendCmGroupID", 0);
            o.RESEND_CM_GROUPID = context.GetInt("ReSendCuGroupID", 0);
            o.RESEND_CM_GROUPID = context.GetInt("ReSendCtGroupID", 0);
        }
 
        string string2 = context.GetString("patternContent");
        if (!Regex.IsMatch(o.SpID, "^\\d{6}$"))
            throw new Exception("账号必须为6位数字");
        if (!string.IsNullOrEmpty(o.AccessCode) && !Regex.IsMatch(o.AccessCode, "^[0-9]*$"))
            throw new Exception("扩展号必须为数字");
        if (string.IsNullOrEmpty(o.ClientID))
            throw new Exception("请选择账号所属客户!");
        if (string.IsNullOrEmpty(o.Password))
            throw new Exception("账号密码不能为空");
        if (o.CMOPID == 0 && o.UNOPID == 0 && (o.CTOPID == 0 && o.RouterType == 1))
            throw new ArgumentException("至少为账号指定一个通道!");
        if (o.CMGroupID == 0 && o.CUGroupID == 0 && (o.CTGroupID == 0 && o.RouterType == 3))
            throw new ArgumentException("至少为账号指定一个通道组!");
        if (!string.IsNullOrEmpty(o.AlarmMobile) && !Regex.IsMatch(o.AlarmMobile, "1\\d{10}"))
            throw new Exception("告警号码格式不正确!");
        if (this._Dao.IsSpIDExists(o.SpID))
            throw new Exception("SPID已经存在,请重新填写!");
        this._Dao.Add(o);
        this._Dao.UpdatePattern(string1, @int, string2, context.OperatorID);//添加账号的时候配置报备
        return new JsonPageResult(true, (object)("账户" + o.SpID + "添加成功!"));
    }
 
    private JsonPageResult Delete(PageContext<SysUser> context)
    {
        string @string = context.GetString("spid");
        if (string.IsNullOrEmpty(@string))
            throw new ArgumentException("SPID参数异常!");
        this._Dao.Delete(@string);
        return new JsonPageResult(true, (object)("账号" + @string + "删除成功!"));
    }
 
    private JsonPageResult LoadChargeLog(PageContext<SysUser> context)
    {
        string @string = context.GetString("spid");
        int int1 = context.GetInt("payLogID");
        int recordCount = 0;
        context.GetInt("pageSize");
        int int2 = context.GetInt("pageSize", 20);
        int int3 = context.GetInt("pageIndex", 1);
        if (string.IsNullOrEmpty(@string))
            throw new ArgumentNullException("SPID参数异常!");
        using (GwChargeLogDao gwChargeLogDao = new GwChargeLogDao())
            return new JsonPageResult(true, (object)new
            {
                Table = gwChargeLogDao.GetChargeLog(@string, int1, out recordCount, int2, int3),
                TotalCount = recordCount
            });
    }
 
    private JsonPageResult PayMentDetails(PageContext<SysUser> context)
    {
        string @string = context.GetString("payID");
        if (string.IsNullOrEmpty(@string))
            throw new ArgumentException("获取订单参数ID出错");
        using (GwClientPayLogDao gwClientPayLogDao = new GwClientPayLogDao())
            return new JsonPageResult(true, (object)gwClientPayLogDao.GetPay(@string));
    }
 
    private JsonPageResult Charge(PageContext<SysUser> context)
    {
        string string1 = context.GetString("spid");
        long num = Convert.ToInt64(context.GetDecimal("amount", new Decimal(0)) * new Decimal(1000));
        string string2 = context.GetString("remark");
        GwSp gwSp = this._Dao.Get(string1);
        if (gwSp == null)
            throw new ArgumentException("SPID不存在");
        GwClient gwClient = new GwClient();
        using (GwClientDao gwClientDao = new GwClientDao())
            gwClient = gwClientDao.Get(gwSp.ClientID);
        using (GwChargeLogDao gwChargeLogDao = new GwChargeLogDao())
            gwChargeLogDao.Add(new GwChargeLog()
            {
                Amount = num,
                Remark = string2,
                OperatorID = context.OperatorID,
                SpID = string1,
                ClientID = gwSp.ClientID,
                ClientName = gwClient.ClientName,
                Flag = 0,
                OccurTime = DateTime.Now,
                PayMentType = 0,
                PayLogID = 0
            });
        return new JsonPageResult(true, (object)("账户" + string1 + "充值请求提交成功!"));
    }
 
    private JsonPageResult BatchUpdateOp(PageContext<SysUser> context)
    {
        int int1 = context.GetInt("cmopID");
        int int2 = context.GetInt("unopID");
        int int3 = context.GetInt("ctopID");
        int int4 = context.GetInt("cmGroupID");
        int int5 = context.GetInt("cuGroupID");
        int int6 = context.GetInt("ctGroupID");
        foreach (string spid in JsonConvert.DeserializeObject<string[]>(context.GetString("idArray")))
            this._Dao.UpdateSingleOP(spid, int1, int3, int2, int4, int5, int6);
        return new JsonPageResult(true, (object)"批量修改通道成功!");
    }
 
    private JsonPageResult LoadPrePatternList(PageContext<SysUser> context)
    {
        string string1 = context.GetString("spID");
        string string2 = context.GetString("clientID");
        int recordCount = 0;
        int int1 = context.GetInt("pageIndex", 1);
        int int2 = context.GetInt("pageSize", 20);
        StringBuilder stringBuilder = new StringBuilder();
        List<Dao.GwSpPrePattern> spPrePatternList = new GwSpPrePatternDao().GetSpPrePatternList(string1, -1, string2, out recordCount, int2, int1);
        if (spPrePatternList.Count > 0)
        {
            foreach (Dao.GwSpPrePattern gwSpPrePattern in spPrePatternList)
            {
                string str1 = gwSpPrePattern.AuditStatus == 0 ? "label-default" : (gwSpPrePattern.AuditStatus == 1 ? "label-primary" : (gwSpPrePattern.AuditStatus == 2 ? "label-warning" : "label-success"));
                string str2 = gwSpPrePattern.AuditStatus == 0 ? "待审核" : (gwSpPrePattern.AuditStatus == 1 ? "已通过" : (gwSpPrePattern.AuditStatus == 2 ? "未通过" : "待重新审核"));
                stringBuilder.AppendFormat("<tr>");
                stringBuilder.AppendFormat("   <td><input type='checkbox' name='checkbox' value=" + (object)gwSpPrePattern.PatternID + " /></td>");
                stringBuilder.AppendFormat("   <td>" + gwSpPrePattern.ClientID + "</td>");
                stringBuilder.AppendFormat("   <td>" + gwSpPrePattern.SpID + "</td>");
                stringBuilder.AppendFormat("   <td>" + gwSpPrePattern.PatternContent + "</td>");
                stringBuilder.AppendFormat("   <td>" + (object)gwSpPrePattern.CreateTime + "</td>");
                stringBuilder.AppendFormat("   <td><span class='label " + str1 + "'>" + str2 + "</span></td>");
                stringBuilder.AppendFormat("   <td>" + (gwSpPrePattern.AuditTime.ToString() == "0001/1/1 0:00:00" ? "" : gwSpPrePattern.AuditTime.ToString()) + "</td>");
                stringBuilder.AppendFormat("   <td>" + gwSpPrePattern.AuditRemark + "</td>");
                stringBuilder.AppendFormat("   <td>" + gwSpPrePattern.OperateAccount + "</td>");
                stringBuilder.AppendFormat("   <td>");
                if (gwSpPrePattern.AuditStatus == 0 || gwSpPrePattern.AuditStatus == 3)
                    stringBuilder.AppendFormat("         <a href=\"javascript:;\" data-id='" + (object)gwSpPrePattern.PatternID + "' class='action-update-status btn-xs btn btn-primary'><li class='fa fa-gavel'></li>&nbsp;审核</a>");
                stringBuilder.AppendFormat("   </td>");
                stringBuilder.AppendFormat("</tr>");
            }
        }
        else
            stringBuilder.AppendFormat("<td colspan='10' style='text-align: center;'>暂无数据</td>");
        return new JsonPageResult(true, (object)new
        {
            Table = stringBuilder.ToString(),
            TotalCount = recordCount
        });
    }
 
 
    /// <summary>
    /// 更新报备审核状态
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult UpdatePrePatternStatus(PageContext<SysUser> context)
    {
        bool flag = false;
        int @int = context.GetInt("auditStatus");
        string @string = context.GetString("auditRemark");
        string[] strArray = JsonConvert.DeserializeObject<string[]>(context.GetString("idArray"));
        GwSpPrePatternDao gwSpPrePatternDao = new GwSpPrePatternDao();
        foreach (string str in strArray)
        {
            Dao.GwSpPrePattern gwSpPrePattern1 = gwSpPrePatternDao.Get(str.ToString());
            if (gwSpPrePattern1.AuditStatus == 0 || gwSpPrePattern1.AuditStatus == 3)
                flag = gwSpPrePatternDao.UpdateSpPrePatternStatus(TypeConvert.ToInt32((object)str), @int, @string, context.OperatorID);
            Dao.GwSpPrePattern gwSpPrePattern2 = gwSpPrePatternDao.Get(str.ToString());
            if (flag && gwSpPrePattern2.AuditStatus == 1)
            {
                SpCTPatternInfo pattern = this._Dao.GetPattern(gwSpPrePattern2.SpID);
                this._Dao.UpdatePattern(pattern.SpID, pattern.Enabled, pattern.Pattern + "\r\n" + gwSpPrePattern2.PatternContent, context.OperatorID);
            }
            flag = false;
        }
        return new JsonPageResult(true, (object)"账号报备审核处理成功!");
    }
 
    private JsonPageResult GetPrePattern(PageContext<SysUser> context)
    {
        return new JsonPageResult(true, (object)new GwSpPrePatternDao().Get(context.GetString("patternID")));
    }
}