TBaseAgvApp.cs
9.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
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
using Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using WebRepository;
namespace WebApp
{
/// <summary>
///
/// </summary>
public partial class TBaseAgvApp
{
private IUnitWork _unitWork;
private IUnitWorkAcs _unitWorkAcs;
public IRepositoryAcs<TBaseAgv> _app;
private static IHostingEnvironment _hostingEnvironment;
ExcelHelper imp = new ExcelHelper(_hostingEnvironment);
private ACSDbContext _ACSDbContext;
public TBaseAgvApp(IUnitWork unitWork, IUnitWorkAcs unitWorkAcs, IRepositoryAcs<TBaseAgv> repository, IHostingEnvironment hostingEnvironment, ACSDbContext ACSDbContext)
{
_unitWork = unitWork;
_unitWorkAcs = unitWorkAcs;
_app = repository;
_hostingEnvironment = hostingEnvironment;
_ACSDbContext = ACSDbContext;
}
public TBaseAgvApp SetLoginInfo(LoginInfo loginInfo)
{
_app._loginInfo = loginInfo;
return this;
}
public TableData Load(PageReq pageRequest, TBaseAgv entity)
{
return _app.Load(pageRequest, entity);
}
public void Ins(TBaseAgv entity)
{
_app.Add(entity);
}
public void Upd(TBaseAgv entity)
{
_app.Update(entity);
}
public void DelByIds(int[] ids)
{
_app.Delete(u => ids.Contains(u.Id.Value));
}
public TBaseAgv FindSingle(Expression<Func<TBaseAgv, bool>> exp)
{
return _app.FindSingle(exp);
}
public IQueryable<TBaseAgv> Find(Expression<Func<TBaseAgv, bool>> exp)
{
return _app.Find(exp);
}
public Response ImportIn(IFormFile excelfile)
{
Response result = new Response();
List<TBaseAgv> exp = imp.ConvertToModel<TBaseAgv>(excelfile);
string sErrorMsg = "";
for (int i = 0; i < exp.Count; i++)
{
try
{
TBaseAgv 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(TBaseAgv entity)
{
return _app.ExportData(entity);
}
public TableData Query(TBaseAgv entity)
{
var result = new TableData();
var data = _app.Find(EntityToExpression<TBaseAgv>.GetExpressions(entity));
GetData(data, result);
result.count = data.Count();
return result;
}
public void GetData(IQueryable<TBaseAgv> data, TableData result, PageReq pageRequest = null)
{
_app.GetData(data, result, pageRequest);
}
public TableData GetAgvInfo()
{
var result = new TableData();
dynamic TBaseAgvmileageData = from TBaseAgvs in _ACSDbContext.TBaseAgvs
where TBaseAgvs.IsEnable.Value
join TBasePoints in _ACSDbContext.TBasePoints on TBaseAgvs.StrBarcode equals TBasePoints.StrBarcode into temp1
from t1 in temp1.DefaultIfEmpty()
join TTasks in _ACSDbContext.TTasks on TBaseAgvs.StrAgvNo equals TTasks.StrTaskAgv into temp2
from t2 in temp2.DefaultIfEmpty()
select new
{
AgvNo = TBaseAgvs.StrAgvNo,
State = TBaseAgvs.AgvState,
HeightState = TBaseAgvs.HeightState,
Heart = TBaseAgvs.AgvHeart,
Error = TBaseAgvs.StrAgvError,
Charge = TBaseAgvs.CurrentCharge,
Left = t1 == null ? 0 : t1.IntX,
Top = t1 == null ? 0 : t1.IntY,
TaskNo = t2 == null ? "" : t2.StrTaskNo,
AgvMap = TBaseAgvs.AgvMap,
StrBarcode = TBaseAgvs.StrBarcode,
};
result.data = TBaseAgvmileageData;
result.count = 0;
return result;
}
public TableData GetEnableAgvInfo()
{
var result = new TableData();
var TBaseAgv = _unitWorkAcs.Find<TBaseAgv>(u => u.IsEnable == true);
result.data = TBaseAgv;
result.count = TBaseAgv.Count();
return result;
}
public TableData LoadAgvInfo(TBaseAgv entity)
{
var result = new TableData();
IQueryable<TBaseAgv> baseAgvs = Find(EntityToExpression<TBaseAgv>.GetExpressions(entity));
dynamic AgvInfoData = from TBaseAgvs in baseAgvs
where TBaseAgvs.IsEnable.Value
join TBasePoints in _ACSDbContext.TBasePoints on TBaseAgvs.StrBarcode equals TBasePoints.StrBarcode into temp1
from t1 in temp1.DefaultIfEmpty()
orderby (TBaseAgvs.ErrorTime == null ? DateTime.Now : TBaseAgvs.ErrorTime) ascending,
(TBaseAgvs.AgvState != 15 ? 0 : 1) ascending,
TBaseAgvs.StrAgvNo ascending
select new
{
StrAgvNo = TBaseAgvs.StrAgvNo,
AgvState = TBaseAgvs.AgvState,
Location = t1 == null ? "(0,0)" : "(" + ((t1.IntX.Value - 1) * 30).ToString() + "," + ((t1.IntY.Value - 1) * 30).ToString() + ")",
CurrentCharge = TBaseAgvs.CurrentCharge,
StrAgvError = TBaseAgvs.StrAgvError,
ErrorTime = TBaseAgvs.ErrorTime,
AlertTimes = TBaseAgvs.ErrorTime == null ? "" : TBaseAgvs.ErrorTime.Value.GetTimeSpanMinutes(DateTime.Now) + " Min",
AgvHeart = TBaseAgvs.AgvHeart,
Ip = TBaseAgvs.Ip,
};
result.data = AgvInfoData;
result.count = baseAgvs.Count();
return result;
}
public TableData GetTaskPathPoint(string TaskNo)
{
var result = new TableData();
try
{
TSonTask sonTaskNo = _unitWorkAcs.Find<TSonTask>(u => u.StrTaskNo.Equals(TaskNo) && u.SonTaskType == 1).OrderBy(u => u.IntSerialNo).FirstOrDefault();
if (sonTaskNo == null)
{
throw new Exception("没有子任务!");
}
var tBasePathPoint = _unitWorkAcs.Find<TBasePathPoint>(u => u.IntSonTaskNo.Equals(sonTaskNo.IntSonTaskNo)).OrderBy(u => u.IntSerialNo).Select(u => new { u.AreaType, u.IntSerialNo, u.StrBarcode, u.PathDirection });
dynamic AgvInfoData = from TBasePathPoints in tBasePathPoint
join TBasePoints in _unitWorkAcs.Find<TBasePoint>(null) on TBasePathPoints.StrBarcode equals TBasePoints.StrBarcode into temp1
from t1 in temp1.DefaultIfEmpty()
orderby (TBasePathPoints.IntSerialNo) ascending
select new
{
AreaType = TBasePathPoints.AreaType,
IntX = t1.IntX.Value,
IntY = t1.IntY.Value,
Direction = TBasePathPoints.PathDirection,
};
result.data = AgvInfoData;
result.count = tBasePathPoint.Count();
}
catch (Exception ex)
{
result.code = 500;
result.msg = ex.Message;
}
return result;
}
}
}