wzp
2021-11-30 f0a773e75016d08684a5c1fdd70d81f68141845d
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
<%@ WebHandler Language="C#" Class="GwStatisV3" %>
 
using System;
using System.Web;
using Model;
using Dao;
using System.Collections.Generic;
using System.Linq;
 
public class GwStatisV3 : PageHandler<SysUser> 
{
    private GwStatisV3Dao _Dao = new GwStatisV3Dao();
    
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
 
        switch (action)
        {
            case "loadStatisV3":
                return LoadStatisV3(context);
            case "getRealtimeStatis5m":
                return GetRealtimeStatis5m(context);
            default:
                throw new Exception("Invalid Action=" + action);
        }
    }
    
    private JsonPageResult GetRealtimeStatis5m(PageContext<SysUser> context)
    {
        var oplist = _Dao.GetRealtimeStatis5mOut();
        var aplist = _Dao.GetRealtimeStatis5mIn();
        
        return new JsonPageResult(true, new { ApList = aplist, OpList = oplist } );
    }
    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.ClientName);
    }
 
    
    //加载统计报表
    private JsonPageResult LoadStatisV3(PageContext<SysUser> context)
    {
        DateTime beginTime =  context.GetDateTime("begintime");
        DateTime endTime = context.GetDateTime("endtime"); 
        string clientID = context.GetString("clientid");
        string spID = context.GetString("spid");
        string apID = context.GetString("apid");
        string opID = context.GetString("opid");
        string statistype = context.GetString("statistype");
        StatisOption statisoption = (StatisOption)context.GetInt("statisoption");
 
        List<GwOp> opList;
        
        using (GwOpDao dao = new GwOpDao())
        {
             opList = dao.LoadInfoList();
        }
        
        List<GwClient> clientList;
        
        using (GwClientDao dao = new GwClientDao())
        {
             clientList = dao.LoadInfoList("", "", "", "");
        }
        
        List<GwAp> apList;
        
        using (GwApDao dao = new GwApDao())
        {
            int recordCount = 0;
 
             apList = dao.LoadInfoList("", "", "", out recordCount, 99999, 1);
        }
        
        
        var list = _Dao.Query(beginTime, endTime, clientID, spID, apID, opID, statistype, (StatisOption)statisoption);
 
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
 
 
        sb.Append(@"<tr class=""header"">");
        sb.Append(@"<th >时间</th>");
        if ((statisoption & StatisOption.APID) == StatisOption.APID)
        {
            sb.Append(@"<th >接入点</th>");
        }
        if ((statisoption & StatisOption.OPID) == StatisOption.OPID)
        {
            sb.Append(@"<th >通道</th>");
        }
 
        if ((statisoption & StatisOption.SpID) == StatisOption.SpID)
        {
            sb.Append(@"<th >账户</th>");
        }
        if ((statisoption & StatisOption.ClientID) == StatisOption.ClientID)
        {
            sb.Append(@"<th >客户</th>");
        }
 
        sb.Append(@"<th >AP接收总量</th>");
        sb.Append(@"<th >AP客户提交失败</th>");
        sb.Append(@"<th >AP未转发</th>");
        sb.Append(@"<th >AP失败</th>");
        sb.Append(@"<th >AP未知</th>");
        sb.Append(@"<th >AP需返还量</th>");
        
        sb.Append(@"<th >OP提交总量</th>");
        sb.Append(@"<th >OP失败</th>");
        sb.Append(@"<th >OP未知</th>");
        sb.Append(@"<th >OP成功</th>");
        sb.Append(@"<th >OP成功率</th>");
        sb.Append(@"<th >OP报告率</th>");
 
 
        sb.Append(@"</tr>");
 
        int i = 0;
 
        foreach (GwStatisV3Item item in list)
        {
            sb.AppendFormat("<tr>");
 
            sb.AppendFormat("<td>{0}</td>", item.Title);
 
            if ((statisoption & StatisOption.APID) == StatisOption.APID)
            {
                sb.AppendFormat("<td>{0}</td>", GetApName(apList,item.APID));
            }
            if ((statisoption & StatisOption.OPID) == StatisOption.OPID)
            {
                sb.AppendFormat("<td>{0}</td>", GetOpName(opList,item.OPID));
            }
            if ((statisoption & StatisOption.SpID) == StatisOption.SpID)
            {
                sb.AppendFormat("<td>{0}</td>", item.SpID);
            }
            if ((statisoption & StatisOption.ClientID) == StatisOption.ClientID)
            {
                sb.AppendFormat("<td>{0}</td>", 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;
 
            sb.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>",
                apTotal, item.APStatus1,item.APStatus0);
 
            sb.AppendFormat(@"<td>{0}</td>", item.APStatus3 + item.APStatus5);
            sb.AppendFormat(@"<td>{0}</td>", item.APStatus2);
            sb.AppendFormat(@"<td>{0}</td>", item.APStatus3 + item.APStatus2 + item.APStatus5 + item.APStatus0);
 
            sb.AppendFormat(@"<td>{0}</td>",opTotal);
            
            sb.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>",
                item.OPStatus5, 
                item.OPStatus2,
                item.OPStatus4);
 
            sb.AppendFormat(@"<td>{0}%</td>", Divide(item.OPStatus4 * 100, opTotal));
            sb.AppendFormat(@"<td>{0}%</td>", 100 - Divide(item.OPStatus2 * 100, opTotal));
 
            
            sb.AppendFormat("</tr>");
        }
 
        return new JsonPageResult(true, sb.ToString());
    }
 
 
    public decimal Divide(decimal v, decimal total)
    {
        if (total == 0)
        {
            return 0;
        }
 
        return Math.Round(v / total, 2);
    }
    
    
    
    
}