wzp
2023-03-02 374ce4ffd0c459bb4067e8d5765f972668aff9b1
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<%@ 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();
    private GwOrderDao orderDao = new GwOrderDao();
    private GwSpPrePatternDao spPrePatternDao = new GwSpPrePatternDao();
    private GwAuditCacheDao gwAuditCacheDao = new GwAuditCacheDao();
    private GwEventLogDao gwEventLogDao = new GwEventLogDao();
        
    private int _userId = -1;
    private string _userType = "";
    private string _account = "";
    
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
        _userId = context.SessionObject.UserID;
        _userType = context.SessionObject.UserType;
        _account = context.SessionObject.Account;
 
        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)
    {
 
        string permissionsSQL = new GwClientDao().GetClientPermissions(_userId, _userType, null);
 
        var oplist = _Dao.GetRealtimeStatis5mOut();
        var aplist = _Dao.GetRealtimeStatis5mIn();
            
            //活动客户:客户-发送量【当日】
        var activeClientDayList = _Dao.GetActiveClientDay(permissionsSQL);
            //通道-发送量【当日】
        var opSendDayList = _Dao.GetOpSendDay(permissionsSQL);
            //产品-发送量【当日】
        var productSendDayList = _Dao.GetProductSendDay(permissionsSQL);
            //订单:今日已完成订单
        var orderDayList = orderDao.GetOrderDay(permissionsSQL);
            //订单:待审核订单
        var orderAuditList = orderDao.GetOrderAudit(permissionsSQL);
            //发送内容:待审核
        var sendAuditList = gwAuditCacheDao.GetSendAudit(permissionsSQL);
            //发送内容:二次待审核
        var sendAuditTowList = gwAuditCacheDao.GetSendAuditTow(permissionsSQL);
            //账号报备内容:待审核
        var spPrePatternAuditList = spPrePatternDao.GetSpPrePatternAudit(permissionsSQL);
            //通道状态
        var opStatusList = gwEventLogDao.GetOpStatus(permissionsSQL);
 
            
        
        return new JsonPageResult(true, new { 
            ApList = aplist,
            OpList = oplist,
            ActiveClientDayList = activeClientDayList,
            OpSendDayList = opSendDayList,
            ProductSendDayList = productSendDayList,
            OrderDayList = orderDayList,
            OrderAuditList = orderAuditList,
            SendAuditList = sendAuditList,
            SendAuditTowList = sendAuditTowList,
            SpPrePatternAuditList = spPrePatternAuditList,
            OpStatusList = opStatusList
        } );
    }
    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");
            
        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);
        }
 
        //var list = _Dao.Query(beginTime, endTime, clientID, spID, apID, opID, statistype, (StatisOption)statisoption);
        
        //根据系统用户获取有权限客户
        var list = _Dao.Query(beginTime, endTime, clientID, spID, apID, opID, statistype, permissionsSQL, (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>");
 
        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);
    }
    
    
    
    
}