wzp
2021-09-16 91912ad24d477ff24be56f0a22438303a8eae552
web/web/GwSp.ashx
New file
@@ -0,0 +1,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")));
    }
}