BiDecision_SN_SIMService.cs
10.3 KB
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
using Hh.Mes.Common;
using Hh.Mes.Common.log;
using Hh.Mes.POJO.ApiEntity.BiDecision;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.WebEntity;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hh.Mes.Service
{
public partial class BiDecisionService : RepositorySqlSugar<sys_user>
{
/// <summary>
/// 决策支持 SN统计
/// </summary>
public dynamic GetSNInfo(DateTime begin)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
CalculateDateRanges(begin, out DateTime monthStart7, out DateTime monthEnd7, out DateTime monthStart, out DateTime monthEnd, out DateTime monthStart90, out DateTime monthEnd90);
// SN申请、授权统计 mysql数据库
var lincenseSql = $@"select sn from sninfo where Created >= @monthStart&&Created<=@monthEnd;
select sn from sninfo where Created >= @monthStart90&&Created<=@monthEnd90;
select sn from licenseinfo where Created >= @monthStart&&Created<=@monthEnd;
select sn from licenseinfo where Created >= @monthStart90&&Created<=@monthEnd90";
var licenseDs = ContextLicense.Ado.GetDataSetAll(lincenseSql, new List<SugarParameter>(){
new("@monthStart", monthStart),
new("@monthEnd", monthEnd),
new("@monthStart90", monthStart90),
new("@monthEnd90", monthEnd90),
});
// 注册sn
//var regSn = licenseDs.Tables[0].AsEnumerable()
// .Select(r => $"'{r["sn"].ToString()}'")
// .Distinct();
//var regSnList = string.Join(",", regSn);
// IOT设备信息批量查询 微软数据库 daq_equipment_status_record_history 表数据库大需要注意
var iotSql = $@" select equipmentCode as sn from base_equipment t1 where createTime >= @monthStart and createTime<=@monthEnd
select equipmentCode as sn from base_equipment t1 where createTime >= @monthStart90 and createTime<=@monthEnd90
select distinct EquipmentCode as sn from daq_equipment_alarm_record where CreateTime >= @monthStart and CreateTime<=@monthEnd
select distinct EquipmentCode as sn from daq_equipment_alarm_record where CreateTime >= @monthStart90 and CreateTime<=@monthEnd90";
var iotResults = Context.Ado.GetDataSetAll(iotSql, new List<SugarParameter>(){
new("@monthStart", monthStart),
new("@monthEnd", monthEnd),
new("@monthStart90", monthStart90),
new("@monthEnd90", monthEnd90)
});
// 处理数据
var processor = new SnDataProcessor();
var snDetail = processor.ProcessAndMergeData(licenseDs.Tables[0], licenseDs.Tables[2], iotResults.Tables[0], iotResults.Tables[2]);
var snDetail90 = processor.ProcessAndMergeData(licenseDs.Tables[1], licenseDs.Tables[3], iotResults.Tables[1], iotResults.Tables[3]);
response.Result = new
{
regSnMonth = licenseDs.Tables[0].Rows.Count,
regSnMonth90 = licenseDs.Tables[1].Rows.Count,
authMonth = licenseDs.Tables[2].Rows.Count,
authMonth90 = licenseDs.Tables[3].Rows.Count,
AccessIotMonth = iotResults.Tables[0].Rows.Count,
AccessIotMonth90 = iotResults.Tables[1].Rows.Count,
alarmMonth = iotResults.Tables[2].Rows.Count,
alarmMonth90 = iotResults.Tables[3].Rows.Count,
snDetail = snDetail,
snDetail90 = snDetail90,
param = new
{
monthStart7 = monthStart7.ToString("yyyy-MM-dd"),
monthEnd7 = monthEnd7.ToString("MM-dd"),
monthStart = monthStart.ToString("yyyy-MM-dd"),
monthEnd = monthEnd.ToString("MM-dd"),
monthStart90 = monthStart90.ToString("yyyy-MM-dd"),
monthEnd90 = monthEnd90.ToString("MM-dd")
}
};
response.Count = licenseDs.Tables[0].Rows.Count;
return response;
}, catchRetrunValue: "list");
}
public Response<SimInfoReport> GetSimInfo(DateTime begin, int type = 0)
{
var response = new Response<SimInfoReport>();
try
{
CalculateDateRanges(begin, out DateTime weekStartTime, out DateTime weekEndTime, out DateTime monthStartTime, out DateTime monthEndTime, out DateTime quarterStartTime, out DateTime quarterEndTime);
var temp = Context.Queryable<base_gateway, base_gateway_vpnsim_rel, base_sim>((g, r, s) => new JoinQueryInfos
(
JoinType.Inner, g.gatewayKey == r.gatewayKey,
JoinType.Inner, r.simKey == s.simKey
)).Where((g, r, s) => s.getCardDate >= quarterStartTime && s.getCardDate <= quarterEndTime)
.GroupBy((g, r, s) => new
{
s.suppliersInfo,
s.getCardDate,
}).Select((g, r, s) => new
{
s.suppliersInfo,
s.getCardDate,
Count = SqlFunc.AggregateCount(s.id)
}).ToList();
var month = new EquipmentReadinessRateArea();
month.KunShan = temp.Where(x => x.suppliersInfo.Contains("昆山") && x.getCardDate >= monthStartTime && x.getCardDate <= monthEndTime).Sum(x => x.Count);
month.XuZhou = temp.Where(x => x.suppliersInfo.Contains("徐州") && x.getCardDate >= monthStartTime && x.getCardDate <= monthEndTime).Sum(x => x.Count);
month.ChangSha = temp.Where(x => x.suppliersInfo.Contains("长沙") && x.getCardDate >= monthStartTime && x.getCardDate <= monthEndTime).Sum(x => x.Count);
month.Total = month.KunShan + month.XuZhou + month.ChangSha;
var quarter = new EquipmentReadinessRateArea();
quarter.KunShan = temp.Where(x => x.suppliersInfo.Contains("昆山")).Sum(x => x.Count);
quarter.XuZhou = temp.Where(x => x.suppliersInfo.Contains("徐州")).Sum(x => x.Count);
quarter.ChangSha = temp.Where(x => x.suppliersInfo.Contains("长沙")).Sum(x => x.Count);
quarter.Total = quarter.KunShan + quarter.XuZhou + quarter.ChangSha;
var startTime = monthStartTime;
var endTime = monthEndTime;
if (type != 0)
{
startTime = quarterStartTime;
endTime = quarterEndTime;
}
var dataList = Context.Queryable<base_gateway, base_gateway_vpnsim_rel, base_sim>((g, r, s) => new JoinQueryInfos
(
JoinType.Inner, g.gatewayKey == r.gatewayKey,
JoinType.Inner, r.simKey == s.simKey
)).Where((g, r, s) => s.getCardDate >= startTime && s.getCardDate <= endTime)
.Select((g, r, s) => new
{
g.gatewaySerialNumber,
s.gatewayClient,
s.suppliersInfo,
s.getCardUser,
s.debugDate,
s.getCardDate,
}).ToList();
response.Result = new SimInfoReport
{
Month = month,
Quarter = quarter,
KunShan = dataList.Where(x => x.suppliersInfo.Contains("昆山")).Select(x => new SimInfoReportDetail
{
GatewaySerialNumber = x.gatewaySerialNumber,
GatewayClient = x.gatewayClient,
GetCardUser = x.getCardUser,
DebugDate = x.debugDate?.ToString("yyyy-MM-dd HH:mm:ss"),
GetCardDate = x.getCardDate?.ToString("yyyy-MM-dd HH:mm:ss"),
}).ToList(),
XuZhou = dataList.Where(x => x.suppliersInfo.Contains("徐州")).Select(x => new SimInfoReportDetail
{
GatewaySerialNumber = x.gatewaySerialNumber,
GatewayClient = x.gatewayClient,
GetCardUser = x.getCardUser,
DebugDate = x.debugDate?.ToString("yyyy-MM-dd HH:mm:ss"),
GetCardDate = x.getCardDate?.ToString("yyyy-MM-dd HH:mm:ss"),
}).ToList(),
ChangSha = dataList.Where(x => x.suppliersInfo.Contains("长沙")).Select(x => new SimInfoReportDetail
{
GatewaySerialNumber = x.gatewaySerialNumber,
GatewayClient = x.gatewayClient,
GetCardUser = x.getCardUser,
DebugDate = x.debugDate?.ToString("yyyy-MM-dd HH:mm:ss"),
GetCardDate = x.getCardDate?.ToString("yyyy-MM-dd HH:mm:ss"),
}).ToList(),
};
return response;
}
catch (Exception ex)
{
response.ResponseErr(ex.Message);
return response;
}
}
}
}