using Dao;
|
using Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Web;
|
using System.Web.Profile;
|
using System.Web.SessionState;
|
using System.Reflection;
|
|
public partial class ExportDocument : PageBase<SysUser>, IRequiresSessionState
|
{
|
|
private int _userId = -1;
|
private string _userType = "";
|
private string _account = "";
|
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
_userId = this.AppContext.SessionObject.UserID;
|
_userType = this.AppContext.SessionObject.UserType;
|
_account = this.AppContext.SessionObject.Account;
|
|
switch (this.AppContext.GetString("action"))
|
{
|
case "exPortGwSp":
|
this.ExPortGwSp();
|
break;
|
case "exPortGwSm":
|
this.ExportGwSmData();
|
break;
|
case "exportGwStatisV3"://导出统计报表
|
this.ExprortGwStatisV3();
|
break;
|
case "exportGwClient": //导出客户信息
|
this.ExportGwClientData();
|
break;
|
}
|
}
|
|
#region 统计报表导出
|
/// <summary>
|
/// 统计报表导出
|
/// </summary>
|
private void ExprortGwStatisV3()
|
{
|
string apMid = this.AppContext.GetString("ApMID");
|
string opid = this.AppContext.GetString("OPID");
|
string spid = this.AppContext.GetString("SpID");
|
string clientId = this.AppContext.GetString("ClientID");
|
string beginTime = this.AppContext.GetString("BeginTime");
|
if (string.IsNullOrEmpty(beginTime))
|
beginTime = DateTime.Now.AddHours(-1.0).Day == DateTime.Now.Day ? DateTime.Now.AddHours(-1.0).ToString("HH:mm:ss") : "00:00:00";
|
string endTime = this.AppContext.GetString("EndTime");
|
string statistype = this.AppContext.GetString("Statistype");
|
StatisOption statisoption = (StatisOption)this.AppContext.GetInt("Statisoption");
|
|
string permissionsSQL = new GwClientDao().GetClientPermissions(_userId, _userType, null);
|
|
List<GwOp> opList;
|
|
using (GwOpDao dao = new GwOpDao())
|
{
|
opList = dao.LoadInfoList();
|
}
|
|
List<GwClient> clientList;
|
|
using (GwClientDao dao = new GwClientDao())
|
{
|
clientList = dao.LoadInfoList("", "", "", "", permissionsSQL);
|
}
|
|
List<GwAp> apList;
|
|
using (GwApDao dao = new GwApDao())
|
{
|
int recordCount = 0;
|
|
apList = dao.LoadInfoList("", "", "", out recordCount, 99999, 1);
|
}
|
|
|
GwStatisV3Dao _Dao = new GwStatisV3Dao();
|
var list = _Dao.Query(Convert.ToDateTime(beginTime), Convert.ToDateTime(endTime), clientId, spid, apMid, opid, statistype, permissionsSQL, (StatisOption)statisoption);
|
|
List<Model.GwStatisV3> statisList = new List<Model.GwStatisV3>();
|
foreach (GwStatisV3Item item in list)
|
{
|
Model.GwStatisV3 ss = new Model.GwStatisV3();
|
|
if ((statisoption & StatisOption.APID) == StatisOption.APID)
|
{
|
ss.ApName = GetApName(apList, item.APID);
|
}
|
if ((statisoption & StatisOption.OPID) == StatisOption.OPID)
|
{
|
ss.OpName = GetOpName(opList, item.OPID);
|
}
|
if ((statisoption & StatisOption.SpID) == StatisOption.SpID)
|
{
|
ss.SpId = item.SpID;
|
}
|
if ((statisoption & StatisOption.ClientID) == StatisOption.ClientID)
|
{
|
ss.ClientId = GetClientName(clientList, item.ClientID);
|
}
|
|
int opTotal = item.OPStatus0 + item.OPStatus1 + item.OPStatus2 + item.OPStatus3 + item.OPStatus4 + item.OPStatus5;
|
int apTotal = item.APStatus0 + item.APStatus1 + item.APStatus2 + item.APStatus3 + item.APStatus4 + item.APStatus5;
|
|
ss.ApReciveTotal = apTotal.ToString();
|
ss.OpSubTotal = opTotal.ToString();
|
|
ss.ApSubFailed = item.APStatus1.ToString();
|
ss.ApNotForwarded = item.APStatus0.ToString();
|
|
ss.ApFailed = (item.APStatus3 + item.APStatus5).ToString();
|
ss.ApUnkown = item.APStatus3.ToString();
|
ss.ApNeedReturn = (item.APStatus3 + item.APStatus2 + item.APStatus5 + item.APStatus0).ToString();
|
|
ss.OpFailed = item.OPStatus5.ToString();
|
ss.OpUnkown = item.OPStatus2.ToString();
|
ss.OpSuccess = item.OPStatus4.ToString();
|
|
ss.OpSuccessRate = Divide(item.OPStatus4 * 100, opTotal).ToString()+"%";
|
|
ss.OpReportRate = (100 - Divide(item.OPStatus2 * 100, opTotal)).ToString() + "%";
|
ss.Date = item.Title;
|
|
statisList.Add(ss);
|
}
|
|
if (statisList.Count > 0)
|
{
|
DataTable dt = ToDataTable<Model.GwStatisV3>(statisList);
|
WebTool webtool = new WebTool();
|
Dictionary<string, string> dicTitle = new Dictionary<string, string>();
|
dicTitle["日期"] = "Date";
|
dicTitle["接入点"] = "ApName";
|
dicTitle["通道"] = "OpName";
|
dicTitle["账号"] = "SpId";
|
dicTitle["客户"] = "ClientId";
|
dicTitle["AP接收总量"] = "ApReciveTotal";
|
dicTitle["AP提交失败"] = "ApSubFailed";
|
dicTitle["AP未转发"] = "ApNotForwarded";
|
dicTitle["AP失败"] = "ApFailed";
|
dicTitle["AP未知"] = "ApUnkown";
|
dicTitle["AP需返还"] = "ApNeedReturn";
|
dicTitle["OP提交总量"] = "OpSubTotal";
|
dicTitle["OP失败"] = "OpFailed";
|
dicTitle["OP未知"] = "OpUnkown";
|
dicTitle["OP成功"] = "OpSuccess";
|
dicTitle["OP成功率"] = "OpSuccessRate";
|
dicTitle["OP状态率"] = "OpReportRate";
|
webtool.Export(dt,dicTitle,"统计报表",this.Context.Response);
|
}
|
|
}
|
|
|
public decimal Divide(decimal v, decimal total)
|
{
|
if (total == 0)
|
{
|
return 0;
|
}
|
|
return Math.Round(v / total, 2);
|
}
|
|
private string GetApName(List<GwAp> aplist, int apID)
|
{
|
if (aplist == null)
|
return string.Empty;
|
|
Model.GwAp x = aplist.Find(delegate(Model.GwAp ap) { return ap.ApID == apID; });
|
|
return x == null ? string.Empty : string.Format("{0}-{1}", x.ApID, x.ApName);
|
}
|
|
private string GetOpName(List<GwOp> oplist, int opID)
|
{
|
if (oplist == null)
|
return string.Empty;
|
|
Model.GwOp x = oplist.Find(delegate(Model.GwOp op) { return op.OpID == opID; });
|
|
return x == null ? string.Empty : string.Format("{0}-{1}", x.OpID, x.OpName);
|
}
|
|
private string GetClientName(List<GwClient> clientlist, string clientID)
|
{
|
if (clientlist == null)
|
return string.Empty;
|
|
Model.GwClient x = clientlist.Find(delegate(Model.GwClient client) { return client.ClientID == clientID; });
|
|
return x == null ? string.Format("{0}", clientID) : string.Format("{0}-{1}", x.ClientID, x.Company);
|
}
|
|
|
|
//=================================================
|
/// <summary>
|
/// Convert a List{T} to a DataTable.
|
/// </summary>
|
private DataTable ToDataTable<T>(List<T> items)
|
{
|
var tb = new DataTable(typeof(T).Name);
|
|
PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
|
foreach (PropertyInfo prop in props)
|
{
|
Type t = GetCoreType(prop.PropertyType);
|
tb.Columns.Add(prop.Name, t);
|
}
|
|
foreach (T item in items)
|
{
|
var values = new object[props.Length];
|
|
for (int i = 0; i < props.Length; i++)
|
{
|
values[i] = props[i].GetValue(item, null);
|
}
|
|
tb.Rows.Add(values);
|
}
|
|
return tb;
|
}
|
|
/// <summary>
|
/// Determine of specified type is nullable
|
/// </summary>
|
public static bool IsNullable(Type t)
|
{
|
return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>));
|
}
|
|
/// <summary>
|
/// Return underlying type if type is Nullable otherwise return the type
|
/// </summary>
|
public static Type GetCoreType(Type t)
|
{
|
if (t != null && IsNullable(t))
|
{
|
if (!t.IsValueType)
|
{
|
return t;
|
}
|
else
|
{
|
return Nullable.GetUnderlyingType(t);
|
}
|
}
|
else
|
{
|
return t;
|
}
|
}
|
|
//=============================end===================================
|
#endregion
|
|
|
private void ExPortGwSp()
|
{
|
string string1 = this.AppContext.GetString("SpID");
|
string string2 = this.AppContext.GetString("ApID");
|
string string3 = this.AppContext.GetString("ClientID");
|
using (GwSpDao gwSpDao = new GwSpDao())
|
{
|
DataTable dataTable = gwSpDao.LoadSpDataTable(string1, string2, string3);
|
WebTool webTool = new WebTool();
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
dictionary["客户编码"] = "CLIENT_ID";
|
dictionary["账号"] = "SP_ID";
|
dictionary["余额"] = "BALANCE";
|
dictionary["单价"] = "PRICE";
|
dictionary["付款方式"] = "CHARGE_TYPE";
|
dictionary["鉴权地址"] = "CLIENT_IP";
|
dictionary["门限"] = "THRESHOLD";
|
dictionary["密码"] = "PASSWORD";
|
webTool.Export(dataTable, dictionary, "SP_" + (object)DateTime.Now.Ticks, this.Context.Response);
|
}
|
}
|
|
private void ExportGwSmData()
|
{
|
string apMid = this.AppContext.GetString("ApMID");
|
string sDate = this.AppContext.GetString("QueryDate");
|
if (string.IsNullOrEmpty(sDate))
|
sDate = DateTime.Today.ToString("yyyy-MM-dd");
|
string content = this.AppContext.GetString("Content");
|
string opstat = this.AppContext.GetString("OpStat");
|
string opName = this.AppContext.GetString("OPName");
|
string mobile = this.AppContext.GetString("DestnationID");
|
string spid = this.AppContext.GetString("SpID");
|
string clientId = this.AppContext.GetString("ClientID");
|
string beginTime = this.AppContext.GetString("BeginTime");
|
if (string.IsNullOrEmpty(beginTime))
|
beginTime = DateTime.Now.AddHours(-1.0).Day == DateTime.Now.Day ? DateTime.Now.AddHours(-1.0).ToString("HH:mm:ss") : "00:00:00";
|
string endTime = this.AppContext.GetString("EndTime");
|
if (string.IsNullOrEmpty(endTime))
|
endTime = DateTime.Now.Date.AddSeconds(-1.0).ToString("HH:mm:ss");
|
int @int = this.AppContext.GetInt("TStatus", -1);
|
using (GwSmDao gwSmDao = new GwSmDao())
|
{
|
int recordcount = 0;
|
if (gwSmDao.LoadInfoListcount(apMid, opName, clientId, spid, mobile, sDate, beginTime, endTime, content, opstat, @int, out recordcount).Count > 1000000)
|
{
|
this.Response.Write("<script type='text/javascript'>alert('导出数据不能大于100万条!');location.href='GwSm.aspx';</script>");
|
this.Response.End();
|
}
|
DataTable dataTable = gwSmDao.LoadSpDataTable(apMid, opName, clientId, spid, mobile, sDate, beginTime, endTime, content, @int, opstat);
|
|
WebTool webTool = new WebTool();
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
dictionary["AP消息ID"] = "AP_MID";
|
dictionary["客户ID"] = "CLIENT_ID";
|
dictionary["账号"] = "SP_ID";
|
dictionary["接入点ID"] = "AP_ID";
|
dictionary["通道名"] = "OP_NAME";
|
dictionary["码号"] = "ACCESS_CODE";
|
dictionary["接收号码"] = "MOBILE";
|
dictionary["PKN "] = "PK_NUMBER";
|
dictionary["PKT "] = "PK_NUMBER";
|
dictionary["AP计费"] = "AP_FEE_COUNT";
|
dictionary["OP计费 "] = "OP_FEE_COUNT";
|
dictionary["UDH"] = "TPUDHI";
|
dictionary["优先级"] = "PRIORITY";
|
dictionary["FMT"] = "MSG_FORMAT";
|
dictionary["长度"] = "MSG_LENGTH";
|
dictionary["AP结果 "] = "AP_RESULT";
|
dictionary["OP消息ID "] = "OP_MID";
|
dictionary["OP结果 "] = "OP_RESULT";
|
dictionary["客户提交时间"] = "AP_SUBMIT_TIME";
|
dictionary["对外转发时间"] = "OP_SUBMIT_TIME";
|
dictionary["状态报告回执时间"] = "OP_DELIVER_TIME";
|
dictionary["内容"] = "MSG_CONTENT";
|
dictionary["状态"] = "STAT";
|
dictionary["耗时"] = "OUT_TIME";
|
webTool.Export(dataTable, dictionary, "日志_" + sDate, this.Context.Response);
|
}
|
}
|
|
//导出客户信息
|
private void ExportGwClientData()
|
{
|
|
string ClientID = this.AppContext.GetString("ClientID");
|
string Company = this.AppContext.GetString("Company");
|
string ClientName = this.AppContext.GetString("ClientName");
|
string Telephone = this.AppContext.GetString("Telephone");
|
string Salesman = this.AppContext.GetString("Salesman");
|
string SupportStaff = this.AppContext.GetString("SupportStaff");
|
string ProductId = this.AppContext.GetString("ProductId");
|
string Agent = this.AppContext.GetString("Agent");
|
int IsEnable = this.AppContext.GetInt("IsEnable", -1);
|
|
int pageIndex = this.AppContext.GetInt("pageIndex", 1);
|
int recordCount = 0;
|
int pageSize = this.AppContext.GetInt("pageSize", 999999999);
|
|
string str = "";
|
using (GwClientDao dao = new GwClientDao())
|
{
|
string permissionsSQL = dao.GetClientPermissions(_userId, _userType, "gwc");
|
var list = dao.LoadInfoList(out recordCount, pageIndex, pageSize, ClientID, ClientName, Telephone, Agent, Company, Salesman, SupportStaff, ProductId, IsEnable, permissionsSQL);
|
if (recordCount> 1000000)
|
{
|
this.Response.Write("<script type='text/javascript'>alert('导出数据不能大于100万条!');location.href='GwClient.aspx?IsEnable=" + IsEnable + "';</script>");
|
this.Response.End();
|
|
}
|
|
DataTable dataTable = dao.LoadClientDataTable(ClientID, ClientName, Telephone, Agent, Company, Salesman, SupportStaff, ProductId, IsEnable, permissionsSQL);
|
|
WebTool webTool = new WebTool();
|
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
dictionary["客户账号"] = "CLIENT_ID";
|
dictionary["公司名称"] = "COMPANY";
|
dictionary["联系人"] = "CLIENT_NAME";
|
dictionary["联系电话"] = "TELEPHONE";
|
dictionary["账户余额(元)"] = "BALANCE"; //已除以1000
|
dictionary["累计充值(元)"] = "TOP_UP_AMOUNT_TOTAL"; //已除以1000
|
dictionary["业务员"] = "SALESMAN_NAME";
|
dictionary["已分配个性产品(多个按“,”分隔) "] = "PRODUCT_IDS";
|
dictionary["状态 "] = "Is_Enable";
|
|
string isEnableStr = "";
|
if (IsEnable == 1)
|
{
|
isEnableStr = "正常";
|
}
|
else
|
{
|
isEnableStr = "停用";
|
}
|
webTool.Export(dataTable, dictionary, isEnableStr + "客户信息_" + DateTime.Now, this.Context.Response);
|
}
|
}
|
}
|