AcsTaskApp.cs
7.38 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
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 AcsTaskApp
{
private IUnitWork _unitWork;
private IUnitWorkAcs _unitWorkAcs;
public IRepository<AcsTask> _app;
private static IHostingEnvironment _hostingEnvironment;
ExcelHelper imp = new ExcelHelper(_hostingEnvironment);
public AcsTaskApp(IUnitWork unitWork, IUnitWorkAcs unitWorkAcs, IRepository<AcsTask> repository, IHostingEnvironment hostingEnvironment)
{
_unitWork = unitWork;
_unitWorkAcs = unitWorkAcs;
_app = repository;
_hostingEnvironment = hostingEnvironment;
}
public AcsTaskApp SetLoginInfo(LoginInfo loginInfo)
{
_app._loginInfo = loginInfo;
return this;
}
public TableData Load(PageReq pageRequest, AcsTask entity)
{
var result = new TableData();
var data = Find(EntityToExpression<AcsTask>.GetExpressions(entity));
int skipPage = 0;
int takeCount = data.Count();
string odby = "";
string sfield = "";
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;
List<AcsTask> data1;
if (string.IsNullOrEmpty(sfield))
data1 = data.Skip(skipPage).Take(takeCount).ToList();
else
data1 = data.OrderBy(sfield, isAsc).Skip(skipPage).Take(takeCount).ToList();
var data2 = _unitWorkAcs.Find<TTask>(null).Select(u => new { u.StrTaskNo, u.StrTaskAgv, u.StrTaskState, u.TaskErrMsg }).ToList();
var data3 = _unitWork.Find<AcsWorkstation>(null).Select(u => new { u.Code, u.Zonename }).ToList();
var taskData = from assignData in data1
join acsTaskData in data2 on assignData.TaskNo equals acsTaskData.StrTaskNo into temp1
join acsWorkstation in data3 on assignData.StartStation equals acsWorkstation.Code into temp2
from t1 in temp1.DefaultIfEmpty()
from t2 in temp2.DefaultIfEmpty()
select new
{
assignData.Id,
assignData.TaskNo,
assignData.OrderNo,
assignData.TaskType,
assignData.StartStation,
assignData.EndStation,
assignData.Status,
assignData.CreateTime,
assignData.CreateBy,
assignData.UpdateTime,
assignData.UpdateBy,
TaskAgv = t1 == null ? "" : t1.StrTaskAgv,
TaskState = t1 == null ? "" : t1.StrTaskState,
ErrorMsg = t1 == null ? "" : t1.TaskErrMsg,
StartZone = t2 == null ? "" : t2.Zonename,
};
result.data = taskData;
result.count = data1.Count();
return result;
}
public void Ins(AcsTask entity)
{
_app.Add(entity);
}
public void Upd(AcsTask entity)
{
_app.Update(entity);
}
public void DelByIds(int[] ids)
{
_app.Delete(u => ids.Contains(u.Id.Value));
}
public AcsTask FindSingle(Expression<Func<AcsTask, bool>> exp)
{
return _app.FindSingle(exp);
}
public IQueryable<AcsTask> Find(Expression<Func<AcsTask, bool>> exp)
{
return _app.Find(exp);
}
public Response ImportIn(IFormFile excelfile)
{
Response result = new Infrastructure.Response();
List<AcsTask> exp = imp.ConvertToModel<AcsTask>(excelfile);
string sErrorMsg = "";
for (int i = 0; i < exp.Count; i++)
{
try
{
AcsTask 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(AcsTask entity)
{
return _app.ExportData(entity);
}
public TableData Query(AcsTask entity)
{
var result = new TableData();
var data = _app.Find(EntityToExpression<AcsTask>.GetExpressions(entity));
GetData(data, result);
result.count = data.Count();
return result;
}
public void GetData(IQueryable<AcsTask> data, TableData result, PageReq pageRequest = null)
{
_app.GetData(data, result, pageRequest);
}
public Response<TTask> Init()
{
var response = new Response<TTask>();
var workSt = _unitWorkAcs.FindSingle<TBaseStation>(u => u.StrStationNo == "BeiLiao1");
var sonTask = _unitWorkAcs.Find<TSonTask>(u => u.SonTaskState == 5 && u.EndPoint == workSt.StrBarcode)
.ToList();
if (sonTask.Count == 0) return response;
response.Result =
_unitWorkAcs.FindSingle<TTask>(u =>
u.StrTaskID == "PeiSong" && sonTask.Exists(a => a.StrTaskNo == u.StrTaskNo));
return response;
}
public Response<TTask> Init1()
{
var response = new Response<TTask>();
var workSt = _unitWorkAcs.FindSingle<TBaseStation>(u => u.StrStationNo == "BeiLiao2");
var sonTask = _unitWorkAcs.Find<TSonTask>(u => u.SonTaskState == 5 && u.EndPoint == workSt.StrBarcode)
.ToList();
if (sonTask.Count == 0) return response;
response.Result =
_unitWorkAcs.FindSingle<TTask>(u =>
u.StrTaskID == "PeiSong" && sonTask.Exists(a => a.StrTaskNo == u.StrTaskNo));
return response;
}
}
}