BaseGatewayService.cs
11.7 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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using Hh.Mes.Common.Infrastructure;
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.WebEntity;
using NPOI.POIFS.FileSystem;
namespace Hh.Mes.Service.Base
{
/// <summary>
/// 网关信息
/// </summary>
public class BaseGatewayService : RepositorySqlSugar<base_gateway>
{
public dynamic Load(PageReq pageReq, base_gateway entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var result = new Response();
var expression = LinqWhere(entity);
//先组合查询表达式(多表查询查看IOT 设备列表案例)
var query = Context.Queryable<base_gateway, base_gateway_vpnsim_rel, base_sim, base_vpn>(
(g, r, s, v) => new JoinQueryInfos
(
JoinType.Left, g.gatewayKey == r.gatewayKey,
JoinType.Left, r.simKey==s.simKey,
JoinType.Left, r.vpnKey==v.vpnKey
))
.Where(expression)
.Select((g, r, s, v) => new
{
g.id,
g.gatewayKey,
g.gatewaySerialNumber,
g.gateway,
g.password,
g.remark,
g.createTime,
g.createBy,
g.updateTime,
g.updateBy,
g.isUse,
s.simKey,
s.simId,
s.simNumber,
s.simIP,
s.suppliersInfo,
s.gatewayClient,
s.getCardDate,
s.getCardUser,
s.debugDate,
s.factoryDate,
s.isDelete,
s.isVirtual,
s.simRemark,
v.vpnKey,
v.vpnNumber,
v.vpnIP,
v.virtualIP,
v.vpnRemark
});
//Exel false 分页
if (!entity.Exel)
{
int total = 0;
result.Result = query.ToOffsetPage(pageReq.page, pageReq.limit, ref total);
result.Count = total;
}
else
{
result.Result = query.ToList();
result.Count = result.Result.Count;
}
return result;
}, catchRetrunValue: "list");
}
public dynamic Ins(base_gateway entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
//网关信息录入
var gatewayKey = Guid.NewGuid();
entity.gatewayKey = gatewayKey;
entity.createBy = sysWebUser.Account;
entity.createTime = DateTime.Now;
Context.Insertable<base_gateway>(entity).AddQueue();
base_sim sim = new base_sim();
var simKey = Guid.NewGuid();
sim.simKey = simKey;
sim.simId = entity.simNumber;
sim.simNumber = entity.simNumber;
sim.simIP = entity.simIP;
sim.suppliersInfo = entity.suppliersInfo;
sim.isVirtual = entity.isVirtual;
sim.isDelete = entity.isDelete;
sim.gatewayClient = entity.gatewayClient;
sim.factoryDate = entity.factoryDate;
sim.simRemark = entity.simRemark;
sim.createTime = DateTime.Now;
sim.createBy = sysWebUser.Account;
Context.Insertable<base_sim>(sim).AddQueue();
base_vpn vpn = new base_vpn();
vpn.vpnKey = Guid.NewGuid();
vpn.vpnNumber = entity.vpnNumber;
vpn.vpnIP = entity.vpnIP;
vpn.virtualIP = entity.virtualIP;
vpn.vpnRemark = entity.vpnRemark;
vpn.createTime = DateTime.Now;
vpn.createBy = sysWebUser.Account;
Context.Insertable<base_vpn>(vpn).AddQueue();
base_gateway_vpnsim_rel rel = new base_gateway_vpnsim_rel();
rel.gatewayKey = gatewayKey;
rel.vpnKey = vpn.vpnKey;
rel.simKey = sim.simKey;
Context.Insertable<base_gateway_vpnsim_rel>(rel).AddQueue();
bool result = Context.SaveQueuesAsync().Result > 0;
response.Status = result;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
public dynamic Upd(base_gateway entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
entity.updateBy = sysWebUser.Account;
entity.updateTime = DateTime.Now;
Context.Updateable(entity).AddQueue();
var gatewayRel = Context.Queryable<base_gateway_vpnsim_rel>().Where(x => x.gatewayKey == entity.gatewayKey).First();
var simKey = gatewayRel.simKey;
var vpnKey = gatewayRel.vpnKey;
base_sim sim = new base_sim();
sim.simKey = simKey;
sim.simId = entity.simNumber;
sim.simNumber = entity.simNumber;
sim.simIP = entity.simIP;
sim.suppliersInfo = entity.suppliersInfo;
sim.isVirtual = entity.isVirtual;
sim.isDelete = entity.isDelete;
sim.gatewayClient = entity.gatewayClient;
sim.factoryDate = entity.factoryDate;
sim.simRemark = entity.simRemark;
sim.updateTime = DateTime.Now;
sim.updateBy = sysWebUser.Account;
sim.debugDate = entity.debugDate;
sim.getCardDate=entity.getCardDate;
sim.getCardUser=entity.getCardUser;
sim.gatewayClient=entity.gatewayClient;
Context.Updateable(sim).Where(i=>i.simKey==simKey).AddQueue();
base_vpn vpn = new base_vpn();
vpn.vpnKey = vpnKey;
vpn.vpnNumber = entity.vpnNumber;
vpn.vpnIP = entity.vpnIP;
vpn.virtualIP = entity.virtualIP;
vpn.vpnRemark = entity.vpnRemark;
vpn.updateTime = DateTime.Now;
vpn.updateBy = sysWebUser.Account;
Context.Updateable<base_vpn>(vpn).Where(i=>i.vpnKey==vpnKey).AddQueue();
response.Status = Context.SaveQueuesAsync().Result > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
public dynamic DelByIds(int[] ids)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
foreach (int id in ids)
{
var gatewayKey = Context.Queryable<base_gateway>().Where(x => x.id == id).First().gatewayKey;
var gatewayRel = Context.Queryable<base_gateway_vpnsim_rel>().Where(x => x.gatewayKey == gatewayKey).First();
var simKey = gatewayRel.simKey;
var vpnKey = gatewayRel.vpnKey;
Context.Deleteable<base_gateway>().Where(i=>i.id==id).AddQueue();
Context.Deleteable<base_vpn>().Where(i=>i.vpnKey==vpnKey).AddQueue();
Context.Deleteable<base_sim>().Where(i=>i.simKey==simKey).AddQueue();
Context.Deleteable<base_gateway_vpnsim_rel>(gatewayRel).AddQueue();
}
response.Status = Context.SaveQueuesAsync().Result > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
public Response ExportData(base_gateway entity)
{
return Load(null, entity);
}
public Expression<Func<base_gateway, base_gateway_vpnsim_rel, base_sim, base_vpn, bool>> LinqWhere(base_gateway model)
{
try
{
var exp = Expressionable.Create<base_gateway, base_gateway_vpnsim_rel, base_sim, base_vpn>();
//数据过滤条件
if (!string.IsNullOrWhiteSpace(model.gatewaySerialNumber))
{
exp.And((g, r, s, v) => g.gatewaySerialNumber.Contains(model.gatewaySerialNumber));
}
if (!string.IsNullOrWhiteSpace(model.virtualIP))
{
exp.And((g, r, s, v) => v.virtualIP.Contains(model.virtualIP));
}
if (!string.IsNullOrWhiteSpace(model.gatewayClient))
{
exp.And((g, r, s, v) => s.gatewayClient.Contains(model.gatewayClient));
}
return exp.ToExpression();//拼接表达式
}
catch (Exception ex)
{
throw new Exception($"{ex.Message}");
}
}
/// <summary>
/// 领卡操作 更新字段 领卡日期、调试日期、网关客户信息
/// </summary>
/// <param name="ids"></param>
/// <param name="getCardDate"></param>
/// <param name="debugDate"></param>
/// <param name="client"></param>
/// <returns></returns>
public dynamic Use(base_gateway entity)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var gatewayKey = Context.Queryable<base_gateway>().Where(i => i.id == entity.id).First().gatewayKey;
var simKey=Context.Queryable<base_gateway_vpnsim_rel>().Where(i=>i.gatewayKey==gatewayKey).First().simKey;
base_sim sim = new base_sim();
sim.getCardDate = DateTime.Now;
sim.getCardUser=entity.getCardUser;
sim.debugDate=entity.debugDate;
sim.gatewayClient=entity.gatewayClient;
Context.Updateable(sim).UpdateColumns("getCardDate", "getCardUser", "debugDate", "gatewayClient").Where(i => i.simKey == simKey).AddQueue();
base_gateway g=new base_gateway();
g.isUse= true;
Context.Updateable(g).UpdateColumns("isUse").Where(i=>i.id==entity.id).AddQueue();
var status = Context.SaveQueuesAsync().Result > 0;
response.Status = status;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
}
}