CPEmptyAction.cs
30.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
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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Infrastructure;
using Quartz;
using WebApp;
using WebRepository;
namespace WebMvc
{
/// <summary>
/// 产品木栈板补给
/// </summary>
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public class CPEmptyAction
{
private string ConnString { set; get; }
IJobExecutionContext Context { set; get; }
public CPEmptyAction(string _ConnString, IJobExecutionContext _Context)
{
ConnString = _ConnString;
Context = _Context;
}
public void Execute(JobContainer jobContainer)
{
UnitWork _unitWork = new UnitWork(AppSettingsJson.JobContext(ConnString));
try
{
List<TaskDetail> ptaskDetails = _unitWork.Find<TaskDetail>(n => n.TaskType == TaskType.容器出库 && (n.Station == "InStationE07" || n.Station == "InStationE08") && n.ContainerCode == null && n.Status == TaskStatus.新建任务).OrderBy(n => n.CreateTime).ToList();
List<Inventory> inventorys = _unitWork.Find<Inventory>(n => n.Qty > 0 && (n.LocationCode == "InStationE07" || n.LocationCode == "InStationE08")).ToList();
foreach (Inventory inv in inventorys)
{
TaskDetail taskDetail = ptaskDetails.Where(n => n.MaterialCode == inv.MaterialCode).FirstOrDefault();
if (inv.ContainerCode == ContainerStatus.空)
{
//成品库木板补给下发站台到站台成功触发下一个空板补给
if (!_unitWork.IsExist<TaskDetail>(n => n.TaskType == TaskType.空容器出库 && n.DestinationLocation == inv.LocationCode))
{
string CType = "";
if (inv.MaterialCode.Contains("SWP"))
{
CType = ContainerType.木栈板母板_1;
}
else if (inv.MaterialCode.Contains("BWP"))
{
CType = ContainerType.木栈板母板_2;
}
else
{
if (taskDetail != null)
{
taskDetail.Error = "物料号不是托盘类型" + taskDetail.MaterialCode + DateTime.Now.ToString("HH:mm:ss");
_unitWork.Update(taskDetail);
}
continue;
}
var emptyContainer = (from con in _unitWork.Find<Container>(n => n.Type == CType && n.Status == ContainerStatus.空 && n.IsLock == 0)
join loc in _unitWork.Find<Location>(n => n.Roadway == 5 && n.Status == LocationStatus.空容器)
on con.LocationCode equals loc.Code
orderby loc.MaxHeight
select con).FirstOrDefault();
if (emptyContainer == null)
{
if (taskDetail != null)
{
taskDetail.Error = "暂无空母板无法入库:" + DateTime.Now.ToString("HH:mm:ss");
_unitWork.Update(taskDetail);
}
continue;
}
//建立容器出库任务
if (!_unitWork.IsExist<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.ContainerCode == emptyContainer.Code))
{
int ptdcount = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.DestinationLocation == "OutStationE02").Count();
if (ptdcount < 1)
{
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = _unitWork.GetTaskNo(TaskNo.空板补充);
ptask.TaskNo = taskNo;
if (taskDetail != null)
{
ptask.OrderCode = taskDetail.TaskNo;
}
else
{
ptask.OrderCode = taskNo;
}
ptask.BusinessType = BusinessType.出库_其他出库单;
ptask.FirstStatus = TaskStatus.待下发任务;
ptask.LastStatus = TaskStatus.待下发任务;
ptask.CreateTime = DateTime.Now;
_unitWork.Add(ptask);
ptaskDetail.TaskNo = taskNo;
if (taskDetail != null)
{
ptaskDetail.OrderCode = taskDetail.TaskNo;
}
else
{
ptaskDetail.OrderCode = taskNo;
}
ptaskDetail.TaskType = TaskType.空容器出库;
ptaskDetail.ContainerCode = emptyContainer.Code;
ptaskDetail.SourceLocation = emptyContainer.LocationCode;
ptaskDetail.DestinationLocation = inv.LocationCode;
ptaskDetail.OderQty = 0;
ptaskDetail.ContainerQty = 0;
ptaskDetail.HadQty = 0;
ptaskDetail.Roadway = 5;
ptaskDetail.Station = inv.LocationCode;
ptaskDetail.Status = TaskStatus.待下发任务;
ptaskDetail.Priority = 0;
ptaskDetail.CreateTime = DateTime.Now;
_unitWork.Add(ptaskDetail);
emptyContainer.IsLock = 1;
_unitWork.Update(emptyContainer);
Location loc = _unitWork.Find<Location>(n => n.Code == emptyContainer.LocationCode).FirstOrDefault();
_unitWork.Update<Location>(n => n.Id == loc.Id && n.Version == loc.Version, n => new Location
{
Status = LocationStatus.任务锁定中
});
if (CType == ContainerType.木栈板母板_2)
{
Location Cloc = _unitWork.Find<Location>(n => n.Code == loc.ContainerCode).FirstOrDefault();
_unitWork.Update<Location>(n => n.Id == Cloc.Id && n.Version == Cloc.Version, n => new Location
{
Status = LocationStatus.任务锁定中
});
}
inv.ContainerCode = emptyContainer.Code;
_unitWork.Update(inv);
}
}
}
else
{
continue;
}
}
else
{
if (!_unitWork.IsExist<TaskDetail>(n => n.Status > TaskStatus.新建任务 && n.Status < TaskStatus.已经完成 && (n.DestinationLocation == inv.LocationCode || n.SourceLocation == inv.LocationCode)))
{
if (taskDetail != null)
{
TaskDetail Detail = new TaskDetail();
Detail.TaskNo = taskDetail.TaskNo;
Detail.OrderCode = taskDetail.TaskNo;
Detail.TaskType = TaskType.站台到站台;
Detail.Roadway = 5;
Detail.ContainerCode = inv.ContainerCode;
Detail.SourceLocation = taskDetail.Station;
Detail.Station = taskDetail.DestinationLocation;
Detail.DestinationLocation = taskDetail.DestinationLocation;
Detail.Status = TaskStatus.待下发任务;
Detail.MaterialCode = taskDetail.MaterialCode;
inv.Qty -= 1;
if (inv.Qty == 0)
{
_unitWork.Delete(inv);
}
else
{
inv.ContainerCode = ContainerStatus.空;
_unitWork.Update(inv);
}
Detail.OderQty = 0;
Detail.ContainerQty = 0;
Detail.HadQty = 0;
Detail.Priority = 0;
Detail.CreateTime = DateTime.Now;
_unitWork.Add(Detail);
taskDetail.Status = TaskStatus.已经完成;
_unitWork.Update(taskDetail);
}
else
{
break;
}
}
}
}
string type = "";
foreach (TaskDetail ptaskDetail in ptaskDetails)
{
if (!_unitWork.IsExist<TaskDetail>(n => n.Status > TaskStatus.新建任务 && n.Status < TaskStatus.已经完成 && (n.DestinationLocation == ptaskDetail.Station || n.SourceLocation == ptaskDetail.Station)))
{
Inventory Inv = _unitWork.Find<Inventory>(n => n.LocationCode == ptaskDetail.Station).FirstOrDefault();
if (Inv != null)
{
if (Inv.ContainerCode != ContainerStatus.空)
{
Container container = _unitWork.Find<Container>(n => n.Code == Inv.ContainerCode).FirstOrDefault();
Location loc = null;
if (loc == null && container != null)
{
string error = "";
while (true)
{
List<LocationDistribution> locationDistributions = _unitWork.Find<LocationDistribution>(n => n.RoadWay == 5).ToList();
if (locationDistributions.Count != 0)
{
Inventory inventory = _unitWork.Find<Inventory>(n => n.ContainerCode == Inv.ContainerCode && n.NameDescription != "").FirstOrDefault();
if (inventory != null)
{
foreach (LocationDistribution locationDistribution in locationDistributions)
{
if (inventory.NameDescription.Substring((int)locationDistribution.ContrastStart - 1, (int)locationDistribution.Length) == locationDistribution.ContrastName)
{
if (container.Type == ContainerType.木栈板母板_2)
{
loc = (from loca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5 && n.ContainerCode == "" && n.Line == locationDistribution.PointX && n.Row >= locationDistribution.PointY_1 && n.Row <= locationDistribution.PointY_2
&& n.Layer >= locationDistribution.PointZ_1 && n.Layer <= locationDistribution.PointZ_2)
join Cloca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5 && n.ContainerCode == "")
on loca.ContiguousCode equals Cloca.Code
select loca).OrderBy(b => b.MaxHeight).ThenBy(n => n.DistributionType).ThenBy(n => (n.Code.Contains("EA-") || n.Code.Contains("EB-")) ? 0 : 1).ThenByDescending(a => a.Row).ThenBy(a => a.Layer).ThenBy(y => y.Row).FirstOrDefault();
}
else
{
loc = (from loca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5 && n.ContainerCode == "" && n.Line == locationDistribution.PointX && n.Row >= locationDistribution.PointY_1 && n.Row <= locationDistribution.PointY_2
&& n.Layer >= locationDistribution.PointZ_1 && n.Layer <= locationDistribution.PointZ_2)
join Cloca in _unitWork.Find<Location>(n => n.Status != LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5)
on loca.ContiguousCode equals Cloca.Code
select loca).OrderBy(b => b.MaxHeight).ThenBy(n => n.DistributionType).ThenBy(n => (n.Code.Contains("EA-") || n.Code.Contains("EB-")) ? 0 : 1).ThenByDescending(a => a.Row).ThenBy(a => a.Layer).ThenBy(y => y.Row).FirstOrDefault();
if (loc == null)
{
loc = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.Roadway == 5 && n.ContainerCode == "" && n.Line == locationDistribution.PointX && n.Row >= locationDistribution.PointY_1 && n.Row <= locationDistribution.PointY_2
&& n.Layer >= locationDistribution.PointZ_1 && n.Layer <= locationDistribution.PointZ_2).OrderBy(b => b.MaxHeight).ThenBy(n => n.DistributionType).ThenBy(n => (n.Code.Contains("EA-") || n.Code.Contains("EB-")) ? 0 : 1).ThenByDescending(a => a.Row).ThenBy(a => a.Layer).ThenBy(y => y.Row).FirstOrDefault();
}
}
}
}
}
}
if (loc == null)
{
if (container.Type == ContainerType.木栈板母板_2)
{
loc = (from loca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5 && n.ContainerCode == "" && n.DistributionType != LocationDistributionType.被分配库位静态库位)
join Cloca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5 && n.ContainerCode == "")
on loca.ContiguousCode equals Cloca.Code
select loca).OrderBy(b => b.MaxHeight).ThenBy(n => n.DistributionType).ThenBy(n => (n.Code.Contains("EA-") || n.Code.Contains("EB-")) ? 0 : 1).ThenByDescending(a => a.Row).ThenBy(a => a.Layer).ThenBy(y => y.Row).FirstOrDefault();
}
else
{
loc = (from loca in _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5 && n.ContainerCode == "" && n.DistributionType != LocationDistributionType.被分配库位静态库位)
join Cloca in _unitWork.Find<Location>(n => n.Status != LocationStatus.空仓位 && n.IsStop == false && n.MaxHeight >= 0 && n.Roadway == 5)
on loca.ContiguousCode equals Cloca.Code
select loca).OrderBy(b => b.MaxHeight).ThenBy(n => n.DistributionType).ThenBy(n => (n.Code.Contains("EA-") || n.Code.Contains("EB-")) ? 0 : 1).ThenByDescending(a => a.Row).ThenBy(a => a.Layer).ThenBy(y => y.Row).FirstOrDefault();
if (loc == null)
{
loc = _unitWork.Find<Location>(n => n.Status == LocationStatus.空仓位 && n.IsStop == false && n.Roadway == 5 && n.ContainerCode == "" && n.DistributionType != LocationDistributionType.被分配库位静态库位).OrderBy(b => b.MaxHeight).ThenBy(n => n.DistributionType).ThenByDescending(a => a.Row).ThenBy(a => a.Layer).ThenBy(y => y.Row).FirstOrDefault();
}
}
}
//更新仓位对应的容器,如果回库分配的不是原仓位则更新仓位且锁定
if (loc == null)
{
ptaskDetail.Error = "未找到仓位!";
_unitWork.Update(ptaskDetail);
break;
}
else
{
int i = _unitWork.Update<Location>(n => n.Id == loc.Id && n.Version == loc.Version, n => new Location
{
Status = LocationStatus.任务锁定中,
ContainerCode = container.Code,
UpdateTime = DateTime.Now
});
if (container != null && loc != null)
{
if (container.Type == ContainerType.木栈板母板_2)
{
Location Cloc = _unitWork.Find<Location>(u => u.Code == loc.ContiguousCode).FirstOrDefault();
if (Cloc != null)
{
int j = _unitWork.Update<Location>(n => n.Id == Cloc.Id && n.Version == Cloc.Version, n => new Location
{
ContainerCode = container.Code,
Status = LocationStatus.任务锁定中,
UpdateBy = "wms",
UpdateTime = DateTime.Now
});
if (j != 1)
{
break;
}
}
}
}
if (i == 1)
{
break;
}
}
}
}
int ptdcount = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.ContainerCode == Inv.ContainerCode).Count();
if (ptdcount < 1 && loc != null)
{
Task task = new Task();
var ctaskNo = _unitWork.GetTaskNo(TaskNo.容器回库);
task.TaskNo = ctaskNo;
task.OrderCode = ctaskNo;
task.BusinessType = BusinessType.入库_产成品入库单;
task.FirstStatus = TaskStatus.待下发任务;
task.LastStatus = TaskStatus.待下发任务;
task.CreateTime = DateTime.Now;
_unitWork.Add(task);
TaskDetail Detail = new TaskDetail();
Detail.MaterialCode = ptaskDetail.MaterialCode;
Detail.TaskNo = ctaskNo;
Detail.OrderCode = ctaskNo;
Detail.TaskType = TaskType.容器回库;
Detail.Roadway = 5;
Detail.ContainerCode = Inv.ContainerCode;
Detail.SourceLocation = ptaskDetail.Station;
Detail.DestinationLocation = loc.Code;
Detail.Station = ptaskDetail.Station;
Detail.Status = TaskStatus.待下发任务;
Detail.OderQty = 0;
Detail.ContainerQty = 0;
Detail.HadQty = 0;
Detail.Priority = 0;
Detail.CreateTime = DateTime.Now;
_unitWork.Add(Detail);
container.Status = ContainerStatus.有;
_unitWork.Update(container);
}
}
else
{
ptaskDetail.Error = "该站台库存无托盘号" + DateTime.Now.ToString("HH:mm:ss");
_unitWork.Update(ptaskDetail);
}
}
else
{
Inventory inventory = (from inv in _unitWork.Find<Inventory>(n => n.MaterialCode == ptaskDetail.MaterialCode && n.TaskStatus == InventoryTaskType.无任务)
join container in _unitWork.Find<Container>(n => n.IsLock == 0)
on inv.ContainerCode equals container.Code
select inv).FirstOrDefault();
if (inventory != null)
{
int ptdcount = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.ContainerCode == inventory.ContainerCode).Count();
if (ptdcount < 1 && inventory.TaskStatus == InventoryTaskType.无任务)
{
for (int i = 1; i < 3; i++)
{
TaskDetail Detail = new TaskDetail();
Detail.TaskNo = ptaskDetail.TaskNo;
Detail.OrderCode = ptaskDetail.TaskNo;
Detail.MaterialCode = ptaskDetail.MaterialCode;
if (i == 1)
{
Detail.TaskType = TaskType.容器出库;
Detail.Roadway = _unitWork.Find<Location>(n => n.Code == inventory.LocationCode).Select(a => a.Roadway).FirstOrDefault();
if (Detail.Roadway == null)
{
ptaskDetail.Error = "inventory id:" + inventory.Id + "LocationCode异常" + DateTime.Now.ToString("HH:mm:ss");
_unitWork.Update(ptaskDetail);
break;
}
Detail.ContainerCode = inventory.ContainerCode;
Detail.SourceLocation = inventory.LocationCode;
Detail.DestinationLocation = ptaskDetail.Station;
Detail.Station = ptaskDetail.Station;
Detail.Status = TaskStatus.待下发任务;
}
else if (i == 2)
{
Detail.TaskType = TaskType.站台到站台;
Detail.Roadway = _unitWork.Find<Location>(n => n.Code == inventory.LocationCode).Select(a => a.Roadway).FirstOrDefault();
Detail.ContainerCode = inventory.ContainerCode;
Detail.SourceLocation = ptaskDetail.Station;
Detail.Station = ptaskDetail.DestinationLocation;
Detail.DestinationLocation = ptaskDetail.DestinationLocation;
Detail.Status = TaskStatus.新建任务;
inventory.Qty -= 1;
if (inventory.Qty == 0)
{
_unitWork.Delete(inventory);
}
}
Detail.OderQty = 0;
Detail.ContainerQty = 0;
Detail.HadQty = 0;
Detail.Priority = 0;
Detail.CreateTime = DateTime.Now;
_unitWork.Add(Detail);
ptaskDetail.Status = TaskStatus.已经完成;
_unitWork.Update(ptaskDetail);
}
inventory.LocationCode = ptaskDetail.Station;
inventory.TaskStatus = InventoryTaskType.任务锁定中;
inventory.ContainerCode = ContainerStatus.空;
_unitWork.Update(inventory);
InventoryTransaction inventoryTransaction = new InventoryTransaction
{
Type = TransactionType.出库,
SourceCode = ptaskDetail.OrderCode,
ContainerCode = inventory.ContainerCode,
MaterialCode = inventory.MaterialCode,
Qty = inventory.Qty,
Status = inventory.Status,
LocationCode = ptaskDetail.Station,
CreateTime = inventory.CreateTime,
UpdateTime = DateTime.Now
};
_unitWork.Add(inventoryTransaction);
}
}
else
{
ptaskDetail.Error = "库内无该类型空木栈板" + DateTime.Now.ToString("HH:mm:ss");
_unitWork.Update(ptaskDetail);
}
}
}
else
{
ptaskDetail.Error = "该站台有出入库任务" + DateTime.Now.ToString("HH:mm:ss");
_unitWork.Update(ptaskDetail);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}