<%@ WebHandler Language="C#" Class="GwOpHandler" %>
|
using Dao;
|
using Model;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Web;
|
|
public class GwOpHandler : PageHandler<SysUser>
|
{
|
private GwOpDao _Dao = new GwOpDao();
|
private GwSpDao _GwSpDao = new GwSpDao();
|
private GwOpGroupDao _GwOpGroupDao = new GwOpGroupDao();
|
|
public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context)
|
{
|
string @string = context.GetString("action");
|
switch (@string)
|
{
|
case "delete":
|
return this.Delete(context);
|
case "update":
|
return this.Update(context);
|
case "add":
|
return this.Add(context);
|
case "status":
|
return this.Status(context);
|
case "saveAlarmSetting":
|
return this.SaveAlarmSetting(context);
|
case "getAlarmSetting":
|
return this.GetAlarmSetting(context);
|
case "test":
|
return this.Test(context);
|
case "getList":
|
return this.GetList(context);
|
case "getOp":
|
return this.GetOp(context);
|
case "getOpRate":
|
return this.GetOpRate(context);
|
case "loadToGwOpPageList"://加载通道信息//通道开启
|
return this.LoadToGwOpPageList(context);
|
case "loadToGwOpPageListStop":
|
return this.LoadToGwOpPageListStop(context);
|
|
|
default:
|
throw new Exception("Invalid Action=" + @string);
|
}
|
}
|
|
//加载启用通道信息
|
private JsonPageResult LoadToGwOpPageList(PageContext<SysUser> context)
|
{
|
string string1 = context.GetString("opID");
|
string opName = context.GetString("opName");
|
int opstatus = context.GetInt("opstatus");
|
context.GetInt("operror");
|
int recordCount = 0;
|
int pageSize = context.GetInt("pageSize", 50);
|
int pageIndex = context.GetInt("pageIndex", 1);
|
using (GwOpDao gwOpDao = new GwOpDao())
|
{
|
string opID = "0";
|
if (this.IsInt(string1))
|
opID = string1;
|
List<GwOp> list = gwOpDao.LoadInfoList(opID, opName, opstatus, pageSize, pageIndex, out recordCount);
|
string str1 = "";
|
if (list != null && list.Count > 0)
|
{
|
|
int num = 0;
|
foreach (GwOp gwOp in list)
|
{
|
++num;
|
str1 = str1 + (object) "<tr><td>" + (object) gwOp.OpID;
|
str1 = str1 + "</td><td>" + gwOp.OpName + "</td>";
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.Threshold,
|
"</td>"
|
});
|
str1 += string.Format("<td rate-id=\"{0}\">{1}</td>", (object) gwOp.OpID, (object) gwOp.CurrentRate);
|
str1 = str1 + "<td>" + GwOp.ToClassNameText(gwOp.ClassName) + "</td>";
|
str1 = str1 + "<td>" + gwOp.AccessCode + "</td>";
|
str1 = str1 + "<td>" + gwOp.ServerIp + "</td>";
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.ServerPort,
|
"</td>"
|
});
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.LocalPort,
|
"</td>"
|
});
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.MaxConn,//并发量
|
"</td>"
|
});
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.ClearFixMode,//抹签名
|
"</td>"
|
});
|
//str1 = string.Concat(new object[4]
|
//{
|
// str1,
|
// "<td>",
|
// (object) ((double) gwOp.Price / 1000.0), // gwOp.Price/1000.00,//通道成本价格
|
// "</td>"
|
//});
|
|
str1 += string.Format("<td>{0}元/条</td>", (object)(Convert.ToDecimal(gwOp.Price) / new Decimal(1000)));
|
|
str1 = str1 + (object) "<td remark-id=\"" + (object) gwOp.OpID + "\">" + this.FormatOpError(gwOp.OpStatus, gwOp.OpError, gwOp.Remark) + "</td>";
|
str1 += "<td class=\"text-right\">";
|
str1 = gwOp.OpStatus != 0 ? str1 + string.Format("<a href=\"javascript:;\" data-id=\"{0}\" data-status=\"0\" class=\"action-update-status btn btn-primary btn-xs\"><i class=\"fa fa-toggle-off\"></i> 停用</a> ", (object) gwOp.OpID) : str1 + string.Format("<a href=\"javascript:;\" data-id=\"{0}\" data-status=\"1\" class=\"action-update-status btn btn-default btn-xs\"><i class=\"fa fa-toggle-on\"/></i> 启用</a> ", (object) gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-alarm btn btn-warning btn-xs\"><i class=\"fa fa-bell\"></i> 告警</a> ", (object) gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-edit btn btn-success btn-xs\"><i class=\"fa fa-edit\"></i> 编辑</a> ", (object) gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-delete btn btn-default btn-xs\"><i class=\"fa fa-trash\"></i> 删除</a> ", (object) gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-test btn btn-danger btn-xs\"><i class=\"fa fa-gavel\"></i> 测试</a> ", (object) gwOp.OpID);
|
str1 += "</td>";
|
str1 += "</tr>";
|
if (!string.IsNullOrEmpty(gwOp.AlarmSetting))
|
{
|
JToken jtoken = JsonConvert.DeserializeObject<JToken>(gwOp.AlarmSetting);
|
if (jtoken.Value<int>((object) "opOutThreshold") > 0 || jtoken.Value<int>((object) "opReportRatioThreshold") > 0 || jtoken.Value<int>((object) "opSuccessRatioThreshold") > 0)
|
{
|
string str2 = string.Format(" <div class=\"text-muted \">告警条件:通道流出速度门限低于 <span class='label label-success'>{0}条/5分钟</span>;5分钟内报告率低于 <span class='label label-success'>{1}%</span>;5分钟内成功率门限低于 <span class='label label-success'>{2}%</span>;</div>", (object) jtoken.Value<int>((object) "opOutThreshold"), (object) jtoken.Value<int>((object) "opReportRatioThreshold"), (object) jtoken.Value<int>((object) "opSuccessRatioThreshold"));
|
str1 = str1 + "<tr><td colspan=\"12\">" + str2 + "</td><td></td></tr>";
|
}
|
}
|
}
|
}
|
else
|
str1 += "<tr><td colspan=\"13\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
|
return new JsonPageResult(true, new
|
{
|
Table = str1.ToString(),
|
TotalCount = recordCount
|
});
|
}
|
}
|
|
|
//加载停用通道信息
|
private JsonPageResult LoadToGwOpPageListStop(PageContext<SysUser> context)
|
{
|
string string1 = context.GetString("opID");
|
string opName = context.GetString("opName");
|
int opstatus = context.GetInt("opstatus");
|
context.GetInt("operror");
|
int recordCount = 0;
|
int pageSize = context.GetInt("pageSize", 50);
|
int pageIndex = context.GetInt("pageIndex", 1);
|
using (GwOpDao gwOpDao = new GwOpDao())
|
{
|
string opID = "0";
|
if (this.IsInt(string1))
|
opID = string1;
|
List<GwOp> list = gwOpDao.LoadInfoListStop(opID, opName, opstatus, pageSize, pageIndex, out recordCount);
|
string str1 = "";
|
if (list != null && list.Count > 0)
|
{
|
|
int num = 0;
|
foreach (GwOp gwOp in list)
|
{
|
++num;
|
str1 = str1 + (object)"<tr><td>" + (object)gwOp.OpID;
|
str1 = str1 + "</td><td>" + gwOp.OpName + "</td>";
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.Threshold,
|
"</td>"
|
});
|
str1 += string.Format("<td rate-id=\"{0}\">{1}</td>", (object)gwOp.OpID, (object)gwOp.CurrentRate);
|
str1 = str1 + "<td>" + GwOp.ToClassNameText(gwOp.ClassName) + "</td>";
|
str1 = str1 + "<td>" + gwOp.AccessCode + "</td>";
|
str1 = str1 + "<td>" + gwOp.ServerIp + "</td>";
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.ServerPort,
|
"</td>"
|
});
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.LocalPort,
|
"</td>"
|
});
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.MaxConn,//并发量
|
"</td>"
|
});
|
str1 = string.Concat(new object[4]
|
{
|
str1,
|
"<td>",
|
gwOp.ClearFixMode,//抹签名
|
"</td>"
|
});
|
//str1 = string.Concat(new object[4]
|
//{
|
// str1,
|
// "<td>",
|
// (object) ((double) gwOp.Price / 1000.0), // gwOp.Price/1000.00,//通道成本价格
|
// "</td>"
|
//});
|
|
str1 += string.Format("<td>{0}元/条</td>", (object)(Convert.ToDecimal(gwOp.Price) / new Decimal(1000)));
|
|
str1 = str1 + (object)"<td remark-id=\"" + (object)gwOp.OpID + "\">" + this.FormatOpError(gwOp.OpStatus, gwOp.OpError, gwOp.Remark) + "</td>";
|
str1 += "<td class=\"text-right\">";
|
str1 = gwOp.OpStatus != 0 ? str1 + string.Format("<a href=\"javascript:;\" data-id=\"{0}\" data-status=\"0\" class=\"action-update-status btn btn-primary btn-xs\"><i class=\"fa fa-toggle-off\"></i> 停用</a> ", (object)gwOp.OpID) : str1 + string.Format("<a href=\"javascript:;\" data-id=\"{0}\" data-status=\"1\" class=\"action-update-status btn btn-default btn-xs\"><i class=\"fa fa-toggle-on\"/></i> 启用</a> ", (object)gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-alarm btn btn-warning btn-xs\"><i class=\"fa fa-bell\"></i> 告警</a> ", (object)gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-edit btn btn-success btn-xs\"><i class=\"fa fa-edit\"></i> 编辑</a> ", (object)gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-delete btn btn-default btn-xs\"><i class=\"fa fa-trash\"></i> 删除</a> ", (object)gwOp.OpID);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-test btn btn-danger btn-xs\"><i class=\"fa fa-gavel\"></i> 测试</a> ", (object)gwOp.OpID);
|
str1 += "</td>";
|
str1 += "</tr>";
|
if (!string.IsNullOrEmpty(gwOp.AlarmSetting))
|
{
|
JToken jtoken = JsonConvert.DeserializeObject<JToken>(gwOp.AlarmSetting);
|
if (jtoken.Value<int>((object)"opOutThreshold") > 0 || jtoken.Value<int>((object)"opReportRatioThreshold") > 0 || jtoken.Value<int>((object)"opSuccessRatioThreshold") > 0)
|
{
|
string str2 = string.Format(" <div class=\"text-muted \">告警条件:通道流出速度门限低于 <span class='label label-success'>{0}条/5分钟</span>;5分钟内报告率低于 <span class='label label-success'>{1}%</span>;5分钟内成功率门限低于 <span class='label label-success'>{2}%</span>;</div>", (object)jtoken.Value<int>((object)"opOutThreshold"), (object)jtoken.Value<int>((object)"opReportRatioThreshold"), (object)jtoken.Value<int>((object)"opSuccessRatioThreshold"));
|
str1 = str1 + "<tr><td colspan=\"12\">" + str2 + "</td><td></td></tr>";
|
}
|
}
|
}
|
}
|
else
|
str1 += "<tr><td colspan=\"13\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
|
return new JsonPageResult(true, new
|
{
|
Table = str1.ToString(),
|
TotalCount = recordCount
|
});
|
}
|
}
|
|
private string FormatOpError(int opStatus, int opError, string remark)
|
{
|
StringBuilder stringBuilder = new StringBuilder();
|
if (opStatus == 0)
|
{
|
stringBuilder.Append("<span class=\"label label-default\">已停用</span>");
|
}
|
else
|
{
|
stringBuilder.Append("<a data-html=\"true\" data-content=\"<pre style='width:200px;height:160px;'>" + HttpUtility.HtmlEncode(remark) + "</pre>\" type=\"button\" class=\"btn-xs\" data-trigger=\"click\" data-toggle=\"popover\" data-placement=\"left\">");
|
if (opError == 0)
|
stringBuilder.Append("<span class=\"label label-primary\">正常</span>");
|
else if (opError == 5)
|
stringBuilder.Append("<span class=\"label label-danger\">异常</span>");
|
else
|
stringBuilder.Append("NA");
|
stringBuilder.Append("</a>");
|
}
|
return stringBuilder.ToString();
|
}
|
|
public bool IsInt(string input)
|
{
|
for (int index = 0; index < input.Length; ++index)
|
{
|
if (!char.IsNumber(input, index))
|
return false;
|
}
|
return true;
|
}
|
|
private JsonPageResult GetOp(PageContext<SysUser> context)
|
{
|
return new JsonPageResult(true, this._Dao.GetOP(context.GetInt("opid")));
|
}
|
|
private JsonPageResult GetList(PageContext<SysUser> context)
|
{
|
return new JsonPageResult(true, this._Dao.LoadInfoList());
|
}
|
|
private JsonPageResult GetOpRate(PageContext<SysUser> context)
|
{
|
return new JsonPageResult(true, this._Dao.GetOpRateList());
|
}
|
|
private JsonPageResult Test(PageContext<SysUser> context)
|
{
|
string string1 = context.GetString("mobile");
|
string string2 = context.GetString("content");
|
string string3 = context.GetString("extNo");
|
int @int = context.GetInt("opID");
|
string string4 = context.GetString("extParams");
|
string apID = "230001";
|
if (!Regex.IsMatch(string1, "1\\d{10}"))
|
throw new ArgumentException("手机号码格式不正确,请重新输入!");
|
if (string.IsNullOrEmpty(string2))
|
throw new ArgumentException("短信内容不能为空,请重新输入!");
|
using (GwAuditCacheDao gwAuditCacheDao = new GwAuditCacheDao())
|
{
|
if (!gwAuditCacheDao.MakeTest(apID, @int, string3, string4, string1, string2))
|
throw new Exception(string.Format("通道:{0},手机号码:{1},提交信息入库失败!", (object) @int, (object) string1));
|
}
|
return new JsonPageResult(true, (object) string.Format("通道:{0},手机号码:{1},提交信息成功,请到下行日志中查询发送详情!", (object) @int, (object) string1));
|
}
|
|
private JsonPageResult GetAlarmSetting(PageContext<SysUser> context)
|
{
|
string str = this._Dao.GetAlarmSetting(context.GetInt("opID"));
|
if (string.IsNullOrEmpty(str))
|
str = "{isAlarmEnabled:0,opOutThreshold:0,opReportRatioThreshold:0,opSuccessRatioThreshold:0}";
|
return new JsonPageResult(true, JsonConvert.DeserializeObject(str));
|
}
|
|
private JsonPageResult SaveAlarmSetting(PageContext<SysUser> context)
|
{
|
int @int = context.GetInt("opid");
|
var fAnonymousType1 = new
|
{
|
opOutThreshold = context.GetInt("opOutThreshold"),
|
opReportRatioThreshold = context.GetInt("opReportRatioThreshold"),
|
opSuccessRatioThreshold = context.GetInt("opSuccessRatioThreshold")
|
};
|
this._Dao.UpdateAlarmSetting(@int, JsonConvert.SerializeObject((object) fAnonymousType1));
|
return new JsonPageResult(true, "告警设置保存成功!");
|
}
|
|
private JsonPageResult Delete(PageContext<SysUser> context)
|
{
|
|
|
//int @int = context.GetInt("id");
|
//if (this._Dao.gwsptableid(@int))
|
// throw new Exception("通道信息正在被客户账号使用中,不能删除!");
|
//this._Dao.Delete(context.GetInt("id"));
|
//return new JsonPageResult(true, "删除通道信息成功!");
|
|
|
|
int @int = context.GetInt("id");
|
|
if (this._GwSpDao.GwOpCount(@int) > 0)
|
throw new ArgumentException("通道信息正在被客户账号使用中,无法删除!");
|
if (this._GwOpGroupDao.OpItemCount(@int) > 0)
|
throw new ArgumentException("当前通道正在通道组中使用,无法删除!");
|
this._Dao.Delete(@int);
|
return new JsonPageResult(true, "删除通道信息成功!");
|
|
|
}
|
|
private JsonPageResult Status(PageContext<SysUser> context)
|
{
|
this._Dao.UpdateOpStatus(context.GetInt("id"), context.GetInt("status"));
|
return new JsonPageResult(true, "删除节点成功!");
|
}
|
|
private JsonPageResult Add(PageContext<SysUser> context)
|
{
|
int int1 = context.GetInt("opID");
|
string string1 = context.GetString("opName");
|
int int2 = context.GetInt("threshold");
|
string string2 = context.GetString("accessCode");
|
string string3 = context.GetString("serverIp");
|
int int3 = context.GetInt("serverPort");
|
string string4 = context.GetString("spID");
|
string string5 = context.GetString("password");
|
int int4 = context.GetInt("localPort");
|
int int5 = context.GetInt("feeShortLength", 70);
|
int int6 = context.GetInt("feeLongLength", 67);
|
int int7 = context.GetInt("splitLength", 70);
|
string string6 = context.GetString("className");
|
string string7 = context.GetString("extParams");
|
string string8 = context.GetString("userName");
|
int int8 = context.GetInt("priority");
|
string string9 = context.GetString("whiteSegments");
|
string string10 = context.GetString("blackSegments");
|
int int9 = context.GetInt("udhiMode");
|
int int10 = context.GetInt("msgFormat");
|
int int11 = context.GetInt("maxConn", 1);
|
int int12 = context.GetInt("clearFixMode", 0);
|
int int13 = context.GetInt("splitMode", 0);
|
int num = Math.Max((int) (context.GetDecimal("price", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 1);
|
int int14 = context.GetInt("blackpool", 0);
|
if (int1 == 0 || int1 < 600000 || int1 > 999999)
|
throw new ArgumentException("通道编号不能为空,且必须在600000-999999之间");
|
if (this._Dao.IsIDExists(int1))
|
throw new ArgumentException("通道OPID已经存在,请重新输入!");
|
if (string.IsNullOrEmpty(string1))
|
throw new ArgumentException("通道名称不能为空!");
|
if (this._Dao.IsNameEixsts(string1, int1))
|
throw new ArgumentException("通道名称已经存在,请重新输入!");
|
if (string.IsNullOrEmpty(string3))
|
throw new ArgumentException("服务器IP地址不能为空!");
|
if (string.IsNullOrEmpty(string4))
|
throw new ArgumentException("SpID不能为空!");
|
if (string.IsNullOrEmpty(string5))
|
throw new ArgumentException("密码不能为空!");
|
if (string.IsNullOrEmpty(string6))
|
throw new ArgumentException("请选择通道类型!");
|
this._Dao.Add(new GwOp()
|
{
|
OpID = int1,
|
OpName = string1,
|
Threshold = int2,
|
AccessCode = string2,
|
ServerIp = string3,
|
ServerPort = int3,
|
SpID = string4,
|
Password = string5,
|
LocalPort = int4,
|
FeeShortLength = int5,
|
FeeLongLength = int6,
|
SplitLength = int7,
|
ClassName = string6,
|
ExtParams = string7,
|
UserName = string8,
|
Priority = int8,
|
WhiteSegments = string9,
|
BlackSegments = string10,
|
UdhiMode = int9,
|
MsgFormat = int10,
|
MaxConn = int11,
|
ClearFixMode = int12,
|
SplitMode = int13,
|
Price = num,
|
BlackPoolID = int14
|
});
|
return new JsonPageResult(true, "添加通道成功!");
|
}
|
|
private JsonPageResult Update(PageContext<SysUser> context)
|
{
|
int int1 = context.GetInt("opID");
|
string string1 = context.GetString("opName");
|
int int2 = context.GetInt("threshold", 10);
|
string string2 = context.GetString("accessCode");
|
string string3 = context.GetString("serverIp");
|
int int3 = context.GetInt("serverPort");
|
string string4 = context.GetString("spID");
|
string string5 = context.GetString("password");
|
int int4 = context.GetInt("localPort");
|
int int5 = context.GetInt("feeShortLength", 70);
|
int int6 = context.GetInt("feeLongLength", 67);
|
int int7 = context.GetInt("splitLength", 70);
|
string string6 = context.GetString("className");
|
string string7 = context.GetString("extParams");
|
string string8 = context.GetString("userName");
|
int int8 = context.GetInt("priority");
|
string string9 = context.GetString("whiteSegments");
|
string string10 = context.GetString("blackSegments");
|
int int9 = context.GetInt("udhiMode");
|
int int10 = context.GetInt("msgFormat");
|
int int11 = context.GetInt("maxConn", 1);
|
int int12 = context.GetInt("clearFixMode", 0);
|
int int13 = context.GetInt("splitMode", 0);
|
int num = Math.Max((int) (context.GetDecimal("price", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 1);
|
int int14 = context.GetInt("blackpool", 0);
|
if (string.IsNullOrEmpty(string1))
|
throw new ArgumentException("通道名称不能为空!");
|
if (this._Dao.IsNameEixsts(string1, int1))
|
throw new ArgumentException("通道名称已经存在,请重新输入!");
|
if (string.IsNullOrEmpty(string3))
|
throw new ArgumentException("服务器IP地址不能为空!");
|
if (string.IsNullOrEmpty(string4))
|
throw new ArgumentException("SpID不能为空!");
|
if (string.IsNullOrEmpty(string5))
|
throw new ArgumentException("密码不能为空!");
|
if (string.IsNullOrEmpty(string6))
|
throw new ArgumentException("请选择通道类型!");
|
this._Dao.Update(new GwOp()
|
{
|
OpID = int1,
|
OpName = string1,
|
Threshold = int2,
|
AccessCode = string2,
|
ServerIp = string3,
|
ServerPort = int3,
|
SpID = string4,
|
Password = string5,
|
LocalPort = int4,
|
FeeShortLength = int5,
|
FeeLongLength = int6,
|
SplitLength = int7,
|
ClassName = string6,
|
ExtParams = string7,
|
UserName = string8,
|
Priority = int8,
|
WhiteSegments = string9,
|
BlackSegments = string10,
|
UdhiMode = int9,
|
MsgFormat = int10,
|
MaxConn = int11,
|
ClearFixMode = int12,
|
SplitMode = int13,
|
Price = num,
|
BlackPoolID = int14
|
});
|
return new JsonPageResult(true, "通道参数更新成功!");
|
}
|
}
|