MapApp.cs
18.1 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using WebRepository;
namespace WebApp
{
/// <summary>
/// 工作流模板信息表
/// </summary>
public partial class MapApp
{
private readonly IUnitWork _unitWork;
public IRepository<Map> _app;
private IRepository<MapPageContent> _Content;
private IRepository<MapPoint> _mappoint;
private IRepository<MapStation> _mapstation;
private IRepository<MapRegion> _setInfo;
private static IHostingEnvironment _hostingEnvironment;
readonly ExcelHelper imp = new ExcelHelper(_hostingEnvironment);
public MapApp(IUnitWork unitWork, IRepository<Map> repository, IRepository<MapPageContent> repository1, IRepository<MapPoint> repository2, IRepository<MapStation> repository3, IRepository<MapRegion> repository4, IHostingEnvironment hostingEnvironment)
{
_unitWork = unitWork;
_app = repository;
_Content = repository1;
_mappoint = repository2;
_mapstation = repository3;
_setInfo = repository4;
_hostingEnvironment = hostingEnvironment;
}
public MapApp SetLoginInfo(LoginInfo loginInfo)
{
_app._loginInfo = loginInfo;
_Content._loginInfo = loginInfo;
_mappoint._loginInfo = loginInfo;
_mapstation._loginInfo = loginInfo;
_setInfo._loginInfo = loginInfo;
return this;
}
public TableData Load(PageReq pageRequest, Map entity)
{
//优化地图列表加载速度, 不加载地图及备份信息内容
var result = new TableData();
var data = Find(EntityToExpression<Map>.GetExpressions(entity));
GetData(data, result, pageRequest);
result.count = data.Count();
return result;
}
public void Ins(Map entity)
{
if (entity.IsDefault == null)
{
entity.IsDefault = 0;
}
_app.Add(entity);
}
public void Upd(Map entity)
{
if (entity.IsDefault == null)
{
entity.IsDefault = 0;
}
_app.Update(entity);
}
public void DelByIds(int[] ids)
{
_app.Delete(u => ids.Contains(u.Id.Value));
}
public Map FindSingle(Expression<Func<Map, bool>> exp)
{
return _app.FindSingle(exp);
}
public IQueryable<Map> Find(Expression<Func<Map, bool>> exp)
{
return _app.Find(exp);
}
public Response ImportIn(IFormFile excelfile)
{
Response result = new Response();
List<Map> exp = imp.ConvertToModel<Map>(excelfile);
string sErrorMsg = "";
for (int i = 0; i < exp.Count; i++)
{
try
{
Map e = exp[i];
e.Id = null;
_app.Add(e);
}
catch (Exception ex)
{
sErrorMsg += "第" + (i + 2) + "行:" + ex.Message + "<br>";
result.Message = sErrorMsg;
break;
}
}
if (sErrorMsg.Equals(string.Empty))
{
if (exp.Count == 0)
{
sErrorMsg += "没有发现有效数据, 请确定模板是否正确, 或是否有填充数据!";
result.Message = sErrorMsg;
}
else
{
result.Message = "导入完成";
}
}
else
{
result.Status = false;
result.Message = result.Message;
}
return result;
}
public TableData ExportData(Map entity)
{
return _app.ExportData(entity);
}
public TableData Query(Map entity)
{
var result = new TableData();
var data = _app.Find(EntityToExpression<Map>.GetExpressions(entity));
GetData(data, result);
result.count = data.Count();
return result;
}
public void GetData(IQueryable<Map> data, TableData result, PageReq pageRequest = null)
{
int skipPage = 0;
int takeCount = data.Count();
string odby = "";
string sfield = "";
if (data.Count() == 0) return;
if (pageRequest != null)
{
skipPage = (pageRequest.page - 1) * pageRequest.limit;
takeCount = pageRequest.limit;
odby = pageRequest.order;
sfield = pageRequest.field;
}
if (string.IsNullOrEmpty(sfield))
{
odby = "asc";
sfield = "Id";
}
bool isAsc = odby == "desc" ? false : true;
if (string.IsNullOrEmpty(sfield))
result.data = data.Skip(skipPage).Take(takeCount).Select(u => new
{
u.Id,
u.Name,
u.Width,
u.Height,
u.IsDefault,
u.BkpTime,
u.RestoreTime,
u.Description,
u.CreateTime,
u.CreateBy,
u.UpdateTime,
u.UpdateBy
}).ToList();
else
result.data = data.OrderBy(sfield, isAsc).Skip(skipPage).Take(takeCount).Select(u => new
{
u.Id,
u.Name,
u.Width,
u.Height,
u.IsDefault,
u.BkpTime,
u.RestoreTime,
u.Description,
u.CreateTime,
u.CreateBy,
u.UpdateTime,
u.UpdateBy
}).ToList();
//_app.GetData(data, result, pageRequest);
}
public Map Get(string id)
{
var result = new TableData();
Map data = _unitWork.FindSingle<Map>(u => u.Id == int.Parse(id));
var test = JsonConvert.DeserializeObject(data.MapContent);
newMapContent newMapContent = new newMapContent();
List<Region> regions = new List<Region>();
var mrs = _unitWork.Find<MapRegion>(u => u.AreaName == data.Name).ToList();
foreach (var item in mrs)
{
var rgn = new Region();
rgn.RegionId = item.RegionId;
rgn.RegionName = item.RegionName;
rgn.RegionPoint1 = item.RegionPoint1;
rgn.RegionPoint2 = item.RegionPoint2;
rgn.RegionPoint3 = item.RegionPoint3;
rgn.RegionPoint1_Id = item.RegionPoint1_Id;
rgn.RegionPoint2_Id = item.RegionPoint2_Id;
rgn.RegionPoint3_Id = item.RegionPoint3_Id;
rgn.LAY_TABLE_INDEX = item.LAY_TABLE_INDEX;
regions.Add(rgn);
}
var mapPageContent = _unitWork.Find<MapPageContent>(u => u.MapName == data.Name).ToList();//_unitWork.Find<Map_content_tab>(u => u.MapName == data.Name);
var mapPoints = _unitWork.Find<MapPoint>(u => u.AreaType == data.Name).ToList();
List<NewArea> newAreas = new List<NewArea>();
foreach (var item in mapPageContent)
{
var nar = new NewArea();
nar.setInfo = new newSetInfo();
nar.name = item.Name;
nar.left = item.Left;
nar.top = item.Top;
nar.color = item.Color;
nar.id = item.aid;
nar.width = item.Width;
nar.height = item.Height;
nar.alt = item.Alt;
newAreas.Add(nar);
}
if (regions.Count > 0 && newAreas.Count > 0)
{
for (int i = 0; i < regions.Count; i++)
{
for (int j = 0; j < newAreas.Count; j++)
{
if (regions[i].RegionId == newAreas[j].name)
{
regions[i].Top = newAreas[j].top;
regions[i].Left = newAreas[j].left;
regions[i].Width = newAreas[j].width;
regions[i].Height = newAreas[j].height;
}
}
}
}
if (mapPoints.Count > 0)
{
foreach (var item in mapPoints)
{
if (newAreas.Where(t => t.id == item.AID).FirstOrDefault() is var nar && nar != null)
{
nar.setInfo.Id = item.AID;
nar.setInfo.Name = item.Name;
nar.setInfo.IntXC = item.XLength.ToString();
nar.setInfo.IntYC = item.YLength.ToString();
nar.setInfo.chk_up = item.IsYPos;//Chk_up;
nar.setInfo.chk_down = item.IsYNeg;// Chk_down;
nar.setInfo.chk_left = item.IsXNeg;//Chk_left;
nar.setInfo.chk_right = item.IsXpos;//item.Chk_right;
nar.setInfo.txt_down = item.Txt_down;
nar.setInfo.txt_left = item.Txt_left;
nar.setInfo.txt_right = item.Txt_right;
nar.setInfo.point_type = ((int)item.PointType).ToString();//Point_type;
nar.setInfo.RegionName = item.RegionName;
nar.setInfo.Is_enable = item.IsEnable;
nar.setInfo.point_turn = item.Point_turn.ToString();
nar.setInfo.point_area = item.Point_area;
nar.setInfo.RFID = item.RFID;
nar.setInfo.PauseTime = item.PauseTime;
nar.setInfo.Isstop = item.IsStop.ToString();
nar.setInfo.IntStopLevel = item.IntStopLevel.ToString();
nar.setInfo.IntAgvAngle = item.IntAgvAngle;
nar.setInfo.AgvDirectionXPos = item.AgvDirectionXPos;
nar.setInfo.AgvDirectionXNeg = item.AgvDirectionXNeg;
nar.setInfo.AgvDirectionYPos = item.AgvDirectionYPos;
nar.setInfo.AgvDirectionYNeg = item.AgvDirectionYNeg;
nar.setInfo.DialDirectionXPos = item.DialDirectionXPos;
nar.setInfo.DialDirectionXNeg = item.DialDirectionXNeg;
nar.setInfo.DialDirectionYPos = item.DialDirectionYPos;
nar.setInfo.DialDirectionYNeg = item.DialDirectionYNeg;
nar.setInfo.XPosGValue = item.XPosGValue ?? 0;
nar.setInfo.XNegGValue = item.XNegGValue ?? 0;
nar.setInfo.YNegGValue = item.YNegGValue ?? 0;
nar.setInfo.YPosGValue = item.YPosGValue ?? 0;
nar.setInfo.AdjustIn = item.AdjustIn;
nar.setInfo.AdjustOut = item.AdjustOut;
nar.setInfo.SpeedXPos = item.SpeedXPos;
nar.setInfo.SpeedXNeg = item.SpeedXNeg;
nar.setInfo.SpeedYPos = item.SpeedYPos;
nar.setInfo.SpeedYNeg = item.SpeedYNeg;
nar.setInfo.RadarXPos = item.RadarXPos;
nar.setInfo.RadarXNeg = item.RadarXNeg;
nar.setInfo.RadarYPos = item.RadarYPos;
nar.setInfo.RadarYNeg = item.RadarYNeg;
nar.setInfo.ArcingLevel = item.ArcingLevel;
//如果行走方向改变的,color值需跟着一起修改
var color = "";
if (item.IsYPos == true)
{
color = "1";
}
else
{
color = "0";
}
if (item.IsXpos == true)
{
color = color + "1";
}
else
{
color = color + "0";
}
if (item.IsYNeg == true)
{
color = color + "1";
}
else
{
color = color + "0";
}
if (item.IsXNeg == true)
{
color = color + "1";
}
else
{
color = color + "0";
}
nar.color = "user_rfid_yxd_" + color;
}
}
}
var mapStations = _unitWork.Find<MapStation>(u => u.Area == data.Name).ToList();
if (mapStations.Count > 0)
{
foreach (var mapStation in mapStations)
{
if (newAreas.Where(t => t.id == mapStation.AID).FirstOrDefault() is NewArea newArea && newArea != null)
{
newArea.setInfo.Id = mapStation.AID;
newArea.setInfo.Name = mapStation.Name;
if (newArea.name != newArea.setInfo.Name && !string.IsNullOrEmpty(newArea.setInfo.Name))
{
newArea.name = newArea.setInfo.Name;
}
newArea.setInfo.Left = mapStation.Left;
newArea.setInfo.Top = mapStation.Top;
newArea.setInfo.Height = mapStation.Height;
newArea.setInfo.Width = mapStation.Width;
newArea.setInfo.RFID = mapStation.RFID;
newArea.setInfo.ListRFID = mapStation.ListRFID;
newArea.setInfo.txt_up = mapStation.Txt_up;
newArea.setInfo.txt_down = mapStation.Txt_down;
newArea.setInfo.txt_left = mapStation.Txt_left;
newArea.setInfo.txt_right = mapStation.Txt_right;
newArea.setInfo.ChargeDirection = mapStation.ChargeDirection;
newArea.setInfo.ChargeLength = mapStation.ChargeLength;
newArea.setInfo.ChargeRFID = mapStation.ChargeRFID;
//nar.setInfo.StationLength = item.LowHeight.ToString();
newArea.setInfo.HighHeight = mapStation.HighHeight;
newArea.setInfo.LowHeight = mapStation.LowHeight;
newArea.setInfo.Code = mapStation.Code;
newArea.setInfo.IsEnable = mapStation.IsEnable;
newArea.setInfo.IsLocked = mapStation.IsLocked;
newArea.setInfo.StationDirection = mapStation.StationDirection ?? 0;
newArea.setInfo.StationType = mapStation.StationType == null ? 0 : (int)mapStation.StationType;
}
}
}
newMapContent.areas = newAreas.ToArray();
newMapContent.Regions = regions.ToArray();
MapContent mapContent = JsonConvert.DeserializeObject<MapContent>(data.MapContent);
newMapContent.initNum = mapContent.InitNum;
newMapContent.lines = mapContent.Lines;
newMapContent.nodes = mapContent.Nodes;
string json1 = JsonConvert.SerializeObject(newMapContent);
data.MapContent = json1;
result.data = data;
return result.data;
}
public TableData GetMaps()
{
var result = new TableData();
var data = _app.Find(u => !u.Emptymap.Value).Select(u => new { u.Id, u.Name });
result.data = data;
result.count = data.Count();
return result;
}
public TableData CheckDefault()
{
var result = new TableData();
var data = _app.Find(u => u.IsDefault.Value == 1);
result.data = data.Select(u => new { u.Id, u.Name });
result.count = data.Count();
return result;
}
public void MapBkp(int id)
{
Map map = _app.FindSingle(u => u.Id.Equals(id));
if (map != null)
{
Map map1 = _app.FindSingle(u => u.Id == id);
map1.MapContentBkp = map.MapContent;
map1.BkpTime = DateTime.Now;
_app.Update(map1);
//_app.Update(u => u.Id.Equals(id), u => new Map
//{
// MapContentBkp = map.MapContent,
// BkpTime = DateTime.Now,
//});
}
else
{
throw new Exception("地图不存在!");
}
}
public void MapRestore(int id)
{
Map map = _app.FindSingle(u => u.Id.Equals(id));
if (map != null)
{
Map map1 = _app.FindSingle(u => u.Id.Equals(id));
map1.MapContent = map.MapContentBkp;
map1.RestoreTime = DateTime.Now;
_app.Update(map1);
//_app.Update(u => u.Id.Equals(id), u => new Map
//{
// MapContent = map.MapContentBkp,
// RestoreTime = DateTime.Now,
//});
}
else
{
throw new Exception("地图不存在!");
}
}
}
}