wzp
2021-09-16 91912ad24d477ff24be56f0a22438303a8eae552
web/web/GwSm.ashx
New file
@@ -0,0 +1,291 @@
<%@ WebHandler Language="C#" Class="GwSm" %>
using System;
using System.Web;
using Model;
using Dao;
using System.Data;
using System.Collections.Generic;
using Common;
public class GwSm : PageHandler<SysUser>
{
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
        switch (action)
        {
            case "loadGwSmPageList"://短信下发记录
                return LoadGwSmPageList(context);
            case "loadGwSmResendPageList"://短信重发记录
                return LoadGwSmResendPageList(context);
            default:
                throw new Exception("Invalid Action=" + action);
        }
    }
    GwSmDao dao = new GwSmDao();
    private JsonPageResult LoadGwSmPageList(PageContext<SysUser> context)
    {
        // context.CheckRight("401", FailedOperation.HistoryGoBack);//新加
        // string privnce = context.GetString("privnce");//新加区域
        string selectedApMID = context.GetString("SelectedApMID");
        string selectedDate = context.GetString("SelectedDate");
        if (string.IsNullOrEmpty(selectedDate))
        {
            selectedDate = DateTime.Today.ToString("yyyy-MM-dd");
        }
        string selectedContent = context.GetString("SelectedContent");
        string selectedOpStat = context.GetString("SelectedOpStat");
        string selectedOpName = context.GetString("SelectedOpName");
        string selectedDestnationID = context.GetString("SelectedDestnationID");
        string selectedSpID = context.GetString("SelectedSpID");
        string selectedClientID = context.GetString("SelectedClientID");
        string selectedBeginTime = context.GetString("BeginTime");
        if (string.IsNullOrEmpty(selectedBeginTime))
        {
            if (DateTime.Now.AddHours(-1).Day != DateTime.Now.Day)
            {
                selectedBeginTime = "00:00:00";
            }
            else
            {
                selectedBeginTime = DateTime.Now.AddHours(-1).ToString("HH:mm:ss");
            }
        }
        string selectedEndTime = context.GetString("EndTime");
        if (string.IsNullOrEmpty(selectedEndTime))
        {
            selectedEndTime = DateTime.Now.Date.AddSeconds(-1).ToString("HH:mm:ss");
        }
        int TStatus = context.GetInt("TStatus", -1);
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 20);
        int pageIndex = context.GetInt("pageIndex", 1);
        List<Model.GwSm> list = dao.LoadInfoList(selectedApMID, selectedOpName, selectedClientID, selectedSpID, selectedDestnationID, selectedDate, selectedBeginTime, selectedEndTime, selectedContent, selectedOpStat, TStatus, out recordCount, pageSize, pageIndex);
        string str = "";
        if (list != null && list.Count > 0)
        {
            int i = 0;
            foreach (Model.GwSm item in list)
            {
                i++;
                string css = string.Empty;
                string errorMsg = string.Empty;
                string InterfaceName = string.Empty;
                GetSendInfo(item.APResult, item.OPResult, item.Stat, out css, out errorMsg);
                GetInterface(item.ApID.ToString(), out InterfaceName);
                str += @"<tr>";
                str += "<td>" + item.APMID + "</td>";
                str += "<td>" + item.ClientID + "-" + item.SPID + "</td>";
                str += "<td>" + InterfaceName + " - " + item.OpName + "</td>";
                str += "<td><span>" + StringHelper.TrimEnd(item.AccessCode, item.ExtNo) + @"</span><span class=""text-danger"">" + item.ExtNo + "</span></td>";
                str += "<td>" + item.Mobile + "</td>";
                str += "<td>" + item.PkNumber + "/" + item.PkTotal + "/" + item.Tpudhi + "/" + item.MsgFormat + "/" + item.MsgLength + "</td>";
                string resendStatusText = "<span class='text-muted'>正常</span>";
                if (item.ResendStatus == 1 && item.ResendFlag == 1) { resendStatusText = "<span class='text-danger'>失败短信已补发</span>"; }
                if (item.ResendStatus == 1 && item.ResendFlag == 0) { resendStatusText = "<span class='text-success'>补发记录</span>"; }
                str += "<td>" + resendStatusText + "</td>";
                if (item.OpDeliverTime.ToString() == "0001/1/1 0:00:00" || item.OpDeliverTime == null)
                {
                    str += "<td>" + "无法计算" + "</td>";
                }
                else
                {
                    str += "<td>" + (item.OpDeliverTime - item.SubmitTime).TotalSeconds + "</td>";
                }
                str += "<td>" + item.APFeeCount + "/" + item.OPFeeCount + "</td>";
                str += "<td>" + item.APResult + "/" + item.OPResult + "</td>";
                str += @"<td class=""text-right"">" + (item.SubmitTime == DateTime.MinValue ? string.Empty : item.SubmitTime.ToString("yy-MM-dd HH:mm:ss")) + "</td>";
                str += @"<td  class=""text-right"">" + (item.OpSubmitTime == DateTime.MinValue ? string.Empty : item.OpSubmitTime.ToString("yy-MM-dd HH:mm:ss")) + "</td>";
                str += @"</tr>";
                str += @"<tr>";
                str += @"<td>" + item.OPMID + "</td>";
                str += @"<td><span class=""label " + css + @""">" + errorMsg + "</span></td>";
                str += @"<td colspan=""9"" class=""text-right"">" + item.MsgContent + "</td>";
                str += @"<td class=""text-right text-info"">" + (item.OpDeliverTime == DateTime.MinValue ? string.Empty : item.OpDeliverTime.ToString("yy-MM-dd HH:mm:ss")) + "</td>";
                str += "</tr>";
            }
        }
        else
        {
            str += "<tr><td colspan=\"22\" style=\"padding-left:5px;\">暂无信息</td></tr>";
        }
        return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = recordCount });
    }
    /// <summary>
    /// 短信重发记录
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult LoadGwSmResendPageList(PageContext<SysUser> context)
    {
        // context.CheckRight("401", FailedOperation.HistoryGoBack);//新加
        // string privnce = context.GetString("privnce");//新加区域
        string selectedApMID = context.GetString("SelectedApMID");
        string selectedDate = context.GetString("SelectedDate");
        if (string.IsNullOrEmpty(selectedDate))
        {
            selectedDate = DateTime.Today.ToString("yyyy-MM-dd");
        }
        string selectedContent = context.GetString("SelectedContent");
        string selectedOpStat = context.GetString("SelectedOpStat");
        string selectedOpName = context.GetString("SelectedOpName");
        string selectedDestnationID = context.GetString("SelectedDestnationID");
        string selectedSpID = context.GetString("SelectedSpID");
        string selectedClientID = context.GetString("SelectedClientID");
        string selectedBeginTime = context.GetString("BeginTime");
        if (string.IsNullOrEmpty(selectedBeginTime))
        {
            if (DateTime.Now.AddHours(-1).Day != DateTime.Now.Day)
            {
                selectedBeginTime = "00:00:00";
            }
            else
            {
                selectedBeginTime = DateTime.Now.AddHours(-1).ToString("HH:mm:ss");
            }
        }
        string selectedEndTime = context.GetString("EndTime");
        if (string.IsNullOrEmpty(selectedEndTime))
        {
            selectedEndTime = DateTime.Now.Date.AddSeconds(-1).ToString("HH:mm:ss");
        }
        int TStatus = context.GetInt("TStatus", -1);
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 20);
        int pageIndex = context.GetInt("pageIndex", 1);
        List<Model.GwSm> list = dao.LoadInfoList(selectedApMID, selectedOpName, selectedClientID, selectedSpID, selectedDestnationID, selectedDate, selectedBeginTime, selectedEndTime, selectedContent, selectedOpStat, TStatus, out recordCount, pageSize, pageIndex, "ReSend");
        string str = "";
        if (list != null && list.Count > 0)
        {
            int i = 0;
            int j = 0;
            foreach (Model.GwSm item in list)
            {
                if (item.ResendStatus == 1 && item.ResendFlag == 0)
                {
                    i++;
                    string css = string.Empty;
                    string errorMsg = string.Empty;
                    string InterfaceName = string.Empty;
                    GetSendInfo(item.APResult, item.OPResult, item.Stat, out css, out errorMsg);
                    GetInterface(item.ApID.ToString(), out InterfaceName);
                    str += @"<tr>";
                    str += "<td>" + item.APMID + "</td>";
                    str += "<td>" + item.ClientID + "-" + item.SPID + "</td>";
                    str += "<td>" + InterfaceName + " - " + item.OpName + "</td>";
                    str += "<td><span>" + StringHelper.TrimEnd(item.AccessCode, item.ExtNo) + @"</span><span class=""text-danger"">" + item.ExtNo + "</span></td>";
                    str += "<td>" + item.Mobile + "</td>";
                    str += "<td>" + item.PkNumber + "/" + item.PkTotal + "/" + item.Tpudhi + "/" + item.MsgFormat + "/" + item.MsgLength + "</td>";
                    string resendStatusText = "<span class='text-muted'>正常</span>";
                    if (item.ResendStatus == 1 && item.ResendFlag == 1) { resendStatusText = "<span class='text-danger'>失败短信已补发</span>"; }
                    if (item.ResendStatus == 1 && item.ResendFlag == 0) { resendStatusText = "<span class='text-success'>补发记录</span>"; }
                    str += "<td>" + resendStatusText + "</td>";
                    str += "<td>" + (item.OpDeliverTime - item.SubmitTime).TotalSeconds + "</td>";
                    str += "<td>" + item.APFeeCount + "/" + item.OPFeeCount + "</td>";
                    str += "<td>" + item.APResult + "/" + item.OPResult + "</td>";
                    str += @"<td class=""text-right"">" + (item.SubmitTime == DateTime.MinValue ? string.Empty : item.SubmitTime.ToString("yy-MM-dd HH:mm:ss")) + "</td>";
                    str += @"<td  class=""text-right"">" + (item.OpSubmitTime == DateTime.MinValue ? string.Empty : item.OpSubmitTime.ToString("yy-MM-dd HH:mm:ss")) + "</td>";
                    str += @"</tr>";
                    str += @"<tr>";
                    str += @"<td>" + item.OPMID + "</td>";
                    str += @"<td><span class=""label " + css + @""">" + errorMsg + "</span></td>";
                    str += @"<td colspan=""9"" class=""text-right"">" + item.MsgContent + "</td>";
                    str += @"<td class=""text-right text-info"">" + (item.OpDeliverTime == DateTime.MinValue ? string.Empty : item.OpDeliverTime.ToString("yy-MM-dd HH:mm:ss")) + "</td>";
                    str += "</tr>";
                }//补发状态显示
            }
        }
        else
        {
            str += "<tr><td colspan=\"22\" style=\"padding-left:5px;\">暂无信息</td></tr>";
        }
        return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = recordCount });
    }
    /// <summary>
    /// 获取账号的提交的接口信息
    /// </summary>
    /// <param name="apid"></param>
    /// <param name="InterfaceName"></param>
    private void GetInterface(string apid, out string InterfaceName)
    {
        switch (apid)
        {
            case "230000": InterfaceName = "HTTP"; break;
            case "230001": InterfaceName = "CMPP"; break;
            case "230002": InterfaceName = "HTTP"; break;
            default: InterfaceName = "未知"; break;
        }
    }
    /// <summary>
    /// 获取发送结果
    /// </summary>
    /// <param name="apStatus"></param>
    /// <param name="opStatus"></param>
    /// <param name="stat"></param>
    /// <param name="css"></param>
    /// <param name="errMsg"></param>
    private void GetSendInfo(long apStatus, long opStatus, string stat, out string css, out string errMsg)
    {
        if (apStatus != 0)
        {
            css = "label-danger";
            errMsg = string.Format("AP提交失败({0})", apStatus);
        }
        else if (opStatus != 0)
        {
            css = "label-danger";
            errMsg = string.Format("OP提交失败({0})", opStatus);
        }
        else if (opStatus == 0 && apStatus == 0 && stat == "")
        {
            css = "label";
            errMsg = string.Format("未知");
        }
        else if (stat != "DELIVRD")
        {
            css = "label-warning";
            errMsg = string.Format("发送失败({0})", stat);
        }
        else
        {
            css = "label-primary";
            errMsg = string.Format("发送成功({0})", stat);
        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}