|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using WebRepository;
namespace WebApp
{
/// <summary>
/// 堆垛机运行节点接口App
/// </summary>
public partial class IStackerStatusApp : ApiApp
{
public IRepository<ReceiptHeader> _apprh;
|
|
16
|
public IRepository<Container> _appc;
|
|
17
|
public IRepository<ReceiptDetail> _apprd;
|
|
18
|
public IRepository<Inventory> _appi;
|
|
19
|
private object obj = new object();
|
|
20
|
public IStackerStatusApp(IUnitWork unitWork, IRepository<Inventory> inventory, IRepository<Container> Container, IAuth auth, BaseDBContext context, IRepository<ReceiptDetail> receiptDetail, IRepository<ReceiptHeader> receiptHeader) : base(unitWork, auth, context)
|
|
21
22
23
|
{
_apprd = receiptDetail;
_apprh = receiptHeader;
|
|
24
|
_appi = inventory;
|
|
25
|
_appc = Container;
|
|
26
27
28
|
//系统字段赋值
_apprd._loginInfo = _apprh._loginInfo = _loginInfo;
|
|
29
|
_appi._loginInfo = _apprh._loginInfo = _loginInfo;
|
|
30
|
_appc._loginInfo = _apprh._loginInfo = _loginInfo;
|
|
31
32
|
}
|
|
33
|
public Response<TaskDetail> SetStackerStatus(STKStatusModel sTKStatusModel)
|
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
{
using (var tran = _context.Database.BeginTransaction())
{
Response<TaskDetail> Response = new Response<TaskDetail>();
try
{
TaskDetail td = null;
if (sTKStatusModel.Status == 30)
{
td = _unitWork.FindSingle<TaskDetail>(u => u.TaskNo == sTKStatusModel.TaskNo && u.Status >= TaskStatus.新建任务 && u.Status < TaskStatus.已经完成);
}
else if (sTKStatusModel.Status == 40)
{
td = _unitWork.FindSingle<TaskDetail>(u => u.TaskNo == sTKStatusModel.TaskNo && u.Status >= TaskStatus.新建任务 && u.Status < TaskStatus.已经完成);
}
|
|
49
50
|
//WCS回库 货物到Rgv上给一次反馈站台占用解除
else if (sTKStatusModel.Status == 10)
|
|
51
|
{
|
|
52
|
td = _unitWork.FindSingle<TaskDetail>(u => u.TaskNo == sTKStatusModel.TaskNo && u.Status >= TaskStatus.新建任务 && u.Status < TaskStatus.已经完成);
|
|
53
54
55
|
if (td == null)
{
Response.Message = "重发";
|
|
56
|
return Response;
|
|
57
|
}
|
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
if (td.SourceLocation.Contains("ProductStationC0") && td.SourceLocation != "ProductStationC09")
{
Station stationEmpty = (from se in _unitWork.Find<Station>(n => n.IsEmpty == 1 && n.IsStop == 0 && n.Containercode != "")
join sts in _unitWork.Find<StationToStation>(a => a.EndStation == td.SourceLocation && a.StartStation.Contains("ProductStationC0"))
on se.Code equals sts.StartStation
select se).FirstOrDefault();
if (stationEmpty != null)
{
stationEmpty.Containercode = "";
stationEmpty.UpdateBy = "wms";
stationEmpty.UpdateTime = DateTime.Now;
_unitWork.Update(stationEmpty);
}
}
|
|
73
|
Station station = _unitWork.Find<Station>(n => n.Code == td.SourceLocation && n.Containercode == td.ContainerCode).FirstOrDefault();
|
|
74
75
76
|
if (station != null)
{
station.Containercode = "";
|
|
77
78
|
station.UpdateBy = "wms";
station.UpdateTime = DateTime.Now;
|
|
79
80
81
|
}
else
{
|
|
82
|
Response.Message = "重发";
|
|
83
|
return Response;
|
|
84
85
|
}
_unitWork.Update(station);
|
|
86
87
|
tran.Commit();
return Response;
|
|
88
|
}
|
|
89
90
91
|
//WCS回库仓位高度请求
else if (sTKStatusModel.Status == 20)
{
|
|
92
93
|
td = _unitWork.Find<TaskDetail>(u => u.TaskNo == sTKStatusModel.TaskNo && u.Status >= TaskStatus.新建任务 && u.Status < TaskStatus.已经完成 && (u.TaskType == TaskType.容器回库 || u.TaskType == TaskType.空容器入库)).FirstOrDefault();
StationRoadway stationRoadway = _unitWork.Find<StationRoadway>(n => n.StationCode == td.SourceLocation).FirstOrDefault();
|
|
94
|
Location loc = null;
|
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
if (stationRoadway == null)
{
Response.Code = 300;
Response.Status = false;
Response.Message = "未找到起始站台!";
return Response;
}
else if (td == null)
{
Response.Code = 300;
Response.Status = false;
Response.Message = "未找到回库任务!";
return Response;
}
|
|
109
|
else if (_unitWork.IsExist<Location>(n => n.ContainerCode == td.ContainerCode))
|
|
110
|
{
|
|
111
|
if (_unitWork.IsExist<Inventory>(n => n.ContainerCode == td.ContainerCode && n.TaskStatus == InventoryTaskType.有盘点任务))
|
|
112
|
{
|
|
113
|
loc = _unitWork.Find<Location>(n => n.ContainerCode == td.ContainerCode).FirstOrDefault();
|
|
114
|
}
|
|
115
|
else
|
|
116
|
{
|
|
117
118
|
Response.Result = td;
Response.Message = "已有仓位!";
|
|
119
120
|
return Response;
}
|
|
121
122
123
124
|
}
if (loc == null)
{
while (true)
|
|
125
|
{
|
|
126
|
if (stationRoadway.StationPlace == StationPlace.巷道北面)
|
|
127
|
{
|
|
128
129
130
|
loc = _unitWork.Find<Location>(n => n.Status == ContainerStatus.空 && n.IsStop == false && n.MaxHeight >= sTKStatusModel.Height && n.Roadway == stationRoadway.RoadWay && n.ContainerCode == "").OrderBy(y => y.MaxHeight).OrderBy(a => a.Row).FirstOrDefault();
}
else if (stationRoadway.StationPlace == StationPlace.巷道南面)
|
|
131
|
{
|
|
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
loc = _unitWork.Find<Location>(n => n.Status == ContainerStatus.空 && n.IsStop == false && n.MaxHeight >= sTKStatusModel.Height && n.Roadway == stationRoadway.RoadWay && n.ContainerCode == "").OrderBy(y => y.MaxHeight).OrderByDescending(a => a.Row).FirstOrDefault();
}
//更新仓位对应的容器,如果回库分配的不是原仓位则更新仓位且锁定
if (loc == null)
{
Response.Code = 300;
Response.Status = false;
Response.Message = "未找到仓位!";
return Response;
}
else
{
int i = _unitWork.Update<Location>(n => n.Id == loc.Id && n.Version == loc.Version, n => new Location
{
Status = LocationStatus.任务锁定中,
ContainerCode = td.ContainerCode,
UpdateTime = DateTime.Now
});
if (i == 1)
{
break;
}
|
|
155
156
|
}
}
|
|
157
|
}
|
|
158
|
|
|
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
List<Inventory> inventories = _unitWork.Find<Inventory>(n => n.ContainerCode == td.ContainerCode).ToList();
Container container = _unitWork.Find<Container>(n => n.Code == td.ContainerCode).FirstOrDefault();
if (container == null)
{
Response.Code = 300;
Response.Status = false;
Response.Message = "未找到该容器!";
return Response;
}
else
{
//更改容器
container.Height = sTKStatusModel.Height;
container.LocationCode = loc.Code;
container.LocationId = loc.Id;
_unitWork.Update(container);
}
|
|
176
|
|
|
177
178
179
180
|
//更新同个容器中其它物料对应新的回库仓位
if (inventories.Count > 0)
{
foreach (Inventory inv in inventories)
|
|
181
|
{
|
|
182
|
if (inv.LocationCode != loc.Code)
|
|
183
|
{
|
|
184
185
|
inv.LocationCode = loc.Code;
_appi.Update(inv);
|
|
186
187
|
}
}
|
|
188
189
190
191
192
193
194
|
}
//更改任务终点
td.DestinationLocation = loc.Code;
_unitWork.Update(td);
tran.Commit();
Response.Result = td;
return Response;
|
|
195
|
}
|
|
196
197
198
199
200
201
202
203
204
|
else
{
Response.Code = 500;
Response.Status = false;
Response.Message = "不识别的任务状态!";
}
if (td != null)
{
|
|
205
|
List<TaskDetail> taskDetails = _unitWork.Find<TaskDetail>(u => u.ContainerCode == td.ContainerCode && u.Status > TaskStatus.新建任务 && u.Status < TaskStatus.已经完成).ToList();
|
|
206
207
208
209
|
if (sTKStatusModel.Status == 30) //堆垛机出库完成容器到达站台
{
foreach (TaskDetail t in taskDetails)
{
|
|
210
|
|
|
211
|
if (t.TaskType == TaskType.容器出库 || t.TaskType == TaskType.空容器出库 || t.TaskType == TaskType.盘点)
|
|
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
|
{
t.Status = TaskStatus.已经完成; //更新托盘出库任务为已完成
t.UpdateBy = "wms";
t.UpdateTime = DateTime.Now;
_unitWork.Update(t);
Task pouttask = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
if (pouttask == null)
{
throw new Exception("任务主表:" + t.TaskNo + "不存在!");
}
pouttask.FirstStatus = TaskStatus.已经完成;
pouttask.LastStatus = TaskStatus.已经完成;
pouttask.UpdateBy = "wms";
pouttask.UpdateTime = DateTime.Now;
_unitWork.Update(pouttask);
//已完成托盘出库任务迁移至历史任务表
TaskHistory taskHistory = new TaskHistory();
pouttask.CopyTo(taskHistory);
taskHistory.Id = null;
_unitWork.Add(taskHistory);
TaskDetailHistory taskDetailHistory = new TaskDetailHistory();
t.CopyTo(taskDetailHistory);
taskDetailHistory.Id = null;
_unitWork.Add(taskDetailHistory);
//删除已完成的托盘出库任务
_unitWork.Delete(pouttask);
_unitWork.Delete(t);
}
|
|
243
244
245
246
247
248
249
250
251
252
253
254
|
else if (t.TaskType == TaskType.站台到站台)
{
t.Status = TaskStatus.已经完成; //更新托盘出库任务为已完成
t.UpdateBy = "wms";
t.UpdateTime = DateTime.Now;
_unitWork.Update(t);
Task pouttask = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
if (pouttask == null)
{
throw new Exception("任务主表:" + t.TaskNo + "不存在!");
}
|
|
255
|
|
|
256
|
Station stationSource = _unitWork.Find<Station>(n => n.Code == t.SourceLocation).FirstOrDefault();
|
|
257
|
|
|
258
259
|
if (stationSource != null)
{
|
|
260
261
262
263
264
|
if (stationSource.Containercode == td.ContainerCode)
{
stationSource.Containercode = "";
_unitWork.Update(stationSource);
}
|
|
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
|
pouttask.FirstStatus = TaskStatus.已经完成;
pouttask.LastStatus = TaskStatus.已经完成;
pouttask.UpdateBy = "wms";
pouttask.UpdateTime = DateTime.Now;
_unitWork.Update(pouttask);
//已完成托盘出库任务迁移至历史任务表
TaskHistory taskHistory = new TaskHistory();
pouttask.CopyTo(taskHistory);
taskHistory.Id = null;
_unitWork.Add(taskHistory);
TaskDetailHistory taskDetailHistory = new TaskDetailHistory();
t.CopyTo(taskDetailHistory);
taskDetailHistory.Id = null;
_unitWork.Add(taskDetailHistory);
//删除已完成的托盘出库任务
_unitWork.Delete(pouttask);
_unitWork.Delete(t);
}
else if (t.TaskType == TaskType.直接出库)
{
t.Status = TaskStatus.已经完成; //更新托盘出库任务为已完成
t.UpdateBy = "wms";
t.UpdateTime = DateTime.Now;
_unitWork.Update(t);
Task pouttask = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
if (pouttask == null)
{
throw new Exception("任务主表:" + t.TaskNo + "不存在!");
}
|
|
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
pouttask.FirstStatus = TaskStatus.已经完成;
pouttask.LastStatus = TaskStatus.已经完成;
pouttask.UpdateBy = "wms";
pouttask.UpdateTime = DateTime.Now;
_unitWork.Update(pouttask);
//已完成托盘出库任务迁移至历史任务表
TaskHistory taskHistory = new TaskHistory();
pouttask.CopyTo(taskHistory);
taskHistory.Id = null;
_unitWork.Add(taskHistory);
TaskDetailHistory taskDetailHistory = new TaskDetailHistory();
t.CopyTo(taskDetailHistory);
taskDetailHistory.Id = null;
_unitWork.Add(taskDetailHistory);
//删除已完成的托盘出库任务
_unitWork.Delete(pouttask);
_unitWork.Delete(t);
}
|
|
319
320
|
else
{
|
|
321
|
t.Status = TaskStatus.已经完成; //更新任务明细状态为已完成
|
|
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
|
t.UpdateBy = "wms";
t.UpdateTime = DateTime.Now;
_unitWork.Update(t);
//更新主任务头尾状态
Task task = _context.Set<Task>().AsQueryable().Where(u => u.TaskNo == t.TaskNo).SingleOrDefault();
if (task == null)
{
throw new Exception("任务主表:" + t.TaskNo + "不存在!");
}
// Task task = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
TaskDetail tdel = _unitWork.Find<TaskDetail>(u => u.TaskNo == t.TaskNo).OrderBy(a => a.Status).FirstOrDefault();//同一个任务号下面最小的任务状态,包含其它容器的任务,用于更新主任务的尾状态
if (tdel == null)
{
throw new Exception("任务子表:" + t.TaskNo + "不存在!");
}
if (task.FirstStatus < t.Status)
{
task.FirstStatus = t.Status;
}
if (task.LastStatus < tdel.Status)
{
task.LastStatus = tdel.Status;
}
task.UpdateBy = "wms";
task.UpdateTime = DateTime.Now;
_unitWork.Update(task);
|
|
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
|
//已完成的单据任务迁移至历史任务表
if (task.LastStatus == TaskStatus.已经完成)
{
TaskHistory taskhis = new TaskHistory();
task.CopyTo(taskhis);
taskhis.Id = null;
_unitWork.Add(taskhis);
List<TaskDetail> taskdtls = _context.Set<TaskDetail>().AsQueryable().Where(u => u.TaskNo == task.TaskNo).ToList();
foreach (TaskDetail tdl in taskdtls)
{
TaskDetailHistory taskdthis = new TaskDetailHistory();
tdl.CopyTo(taskdthis);
taskdthis.Id = null;
_unitWork.Add(taskdthis);
_unitWork.Delete(tdl);
}
_unitWork.Delete(task);
}
if (t.TaskType == TaskType.整盘出库 || t.TaskType == TaskType.分拣出库)//出库任务类型
{
//更新出库明细状态
|
|
373
|
ShipmentDetail shipmentDetail = _context.Set<ShipmentDetail>().AsQueryable().Where(u => u.SourceCode == t.SourceCode && u.ShipmentCode == t.OrderCode && u.MaterialCode == t.MaterialCode && u.Status == ShipmentHeaderStatus.分配完成).SingleOrDefault();
|
|
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
|
// ShipmentDetail shipmentDetail = _unitWork.Find<ShipmentDetail>(u => u.SourceCode == t.SourceCode && u.ShipmentCode == t.OrderCode && u.MaterialCode == t.MaterialCode).FirstOrDefault();
if (shipmentDetail != null)
{
shipmentDetail.Status = ShipmentHeaderStatus.过账;
shipmentDetail.UpdateBy = "wms";
shipmentDetail.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentDetail);
//更新主出库单头尾状态
// ShipmentHeader shipmentHeader = _unitWork.Find<ShipmentHeader>(u => u.Code == t.OrderCode).FirstOrDefault();
ShipmentHeader shipmentHeader = _context.Set<ShipmentHeader>().AsQueryable().Where(u => u.Code == t.OrderCode).SingleOrDefault();
ShipmentDetail shipdt = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == t.OrderCode).OrderBy(a => a.Status).FirstOrDefault();
if (shipmentHeader.FirstStatus < shipmentDetail.Status)
{
shipmentHeader.FirstStatus = shipmentDetail.Status;
}
if (shipmentHeader.LastStatus < shipdt.Status)
{
shipmentHeader.LastStatus = shipdt.Status;
}
shipmentHeader.UpdateBy = "wms";
shipmentHeader.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentHeader);
//已完成的出库单据迁移至历史出库单据,暂以过账状态,后期与ERP对接后以回传状态
if (shipmentHeader.LastStatus == ShipmentHeaderStatus.过账)
{
ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();
shipmentHeader.CopyTo(shipmentHeaderHistory);
shipmentHeaderHistory.Id = null;
_unitWork.Add(shipmentHeaderHistory);
List<ShipmentDetail> shipdtls = _context.Set<ShipmentDetail>().AsQueryable().Where(u => u.ShipmentCode == shipmentHeader.Code).ToList();
// List<ShipmentDetail> shipdtls = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == shipmentHeader.Code).ToList();
foreach (ShipmentDetail sd in shipdtls)
{
ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
sd.CopyTo(shipmentDetailHistory);
shipmentDetailHistory.Id = null;
shipmentDetailHistory.ShipmentId = shipmentHeaderHistory.Id;
_unitWork.Add(shipmentDetailHistory);
_unitWork.Delete(sd);
}
_unitWork.Delete(shipmentHeader);
}
}
}
//t.Status = TaskStatus.已经到站台; //更新任务状态为已到达站台
//t.UpdateBy = "wms";
//t.UpdateTime = DateTime.Now;
//_unitWork.Update(t);
////更新主任务头尾状态
//Task task = _context.Set<Task>().AsQueryable().Where(u => u.TaskNo == t.TaskNo).SingleOrDefault();
//if (task == null)
//{
// throw new Exception("任务主表:" + t.TaskNo + "不存在!");
//}
//// Task task = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
//TaskDetail tdel = _unitWork.Find<TaskDetail>(u => u.TaskNo == t.TaskNo).OrderBy(a => a.Status).FirstOrDefault();//同一个任务号下面最小的任务状态,包含其它容器的任务,用于更新主任务的尾状态
//if (tdel == null)
//{
// throw new Exception("任务子表:" + t.TaskNo + "不存在!");
//}
//if (task.FirstStatus < t.Status)
//{
// task.FirstStatus = t.Status;
//}
//if (task.LastStatus < tdel.Status)
//{
// task.LastStatus = tdel.Status;
//}
//task.UpdateBy = "wms";
//task.UpdateTime = DateTime.Now;
//_unitWork.Update(task);
|
|
449
450
|
}
}
|
|
451
|
|
|
452
|
if (td.TaskType == TaskType.直接出库 || td.TaskType == TaskType.空容器出库 || td.TaskType == TaskType.容器出库 || td.TaskType == TaskType.站台到站台 || td.TaskType == TaskType.盘点)
|
|
453
|
{
|
|
454
455
456
457
|
//托盘出库完成,容器占用站台
Station st = _unitWork.Find<Station>(u => u.Code == td.Station).FirstOrDefault();
Container cont = _unitWork.Find<Container>(n => n.Code == td.ContainerCode).FirstOrDefault();
if (st == null)
|
|
458
|
{
|
|
459
|
throw new Exception("站台:" + td.Station + "不存在!");
|
|
460
|
}
|
|
461
|
else if (st.IsOccupy == 0 && td.IsOccupy != 1)
|
|
462
|
{
|
|
463
|
st.Containercode = "";
|
|
464
|
if (cont != null && td.TaskType != TaskType.盘点)
|
|
465
466
467
|
{
_appc.DeleteByTracking(cont);
}
|
|
468
|
}
|
|
469
|
else if (st.IsOccupy == 1 && td.IsOccupy != 0)
|
|
470
|
{
|
|
471
|
st.Containercode = td.ContainerCode;
|
|
472
473
474
475
476
477
478
|
if (td.TaskType != TaskType.盘点)
{
cont.Status = "empty";
cont.Height = 0;
cont.LocationCode = st.Code;
_unitWork.Update(cont);
}
|
|
479
|
}
|
|
480
481
482
483
484
|
st.UpdateBy = "wms";
st.UpdateTime = DateTime.Now;
_unitWork.Update(st);
List<Inventory> inventories = _unitWork.Find<Inventory>(n => n.ContainerCode == td.ContainerCode).ToList();
|
|
485
|
if (st.Type == StationType.暂存区站台 || td.TaskType == TaskType.盘点)
|
|
486
|
{
|
|
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
foreach (Inventory inv in inventories)
{
inv.LocationCode = st.Code;
_appi.UpdateByTracking(inv);
}
}
else
{
foreach (Inventory inv in inventories)
{
_unitWork.Delete(inv);
InventoryTransaction inventoryTransaction = new InventoryTransaction();
inventoryTransaction.Type = TransactionType.出库;
inventoryTransaction.SourceCode = "AllTaskOut";
inventoryTransaction.ContainerCode = inv.ContainerCode;
inventoryTransaction.MaterialCode = inv.MaterialCode;
inventoryTransaction.Batch = inv.Batch;
inventoryTransaction.Qty = inv.Qty;
inventoryTransaction.Status = inv.Status;
_unitWork.Add(inventoryTransaction);
}
|
|
508
|
}
|
|
509
510
|
if (td.TaskType != TaskType.盘点)
|
|
511
|
{
|
|
512
513
514
|
//托盘出库完成,解锁并释放仓位
Location loc = _unitWork.Find<Location>(u => u.Code == td.SourceLocation).FirstOrDefault();
if (loc != null)
|
|
515
|
{
|
|
516
517
518
519
520
521
522
523
|
_unitWork.Update<Location>(n => n.Id == loc.Id && n.Version == loc.Version, n => new Location
{
ContainerCode = "",
Status = "empty",
UpdateBy = "wms",
UpdateTime = DateTime.Now
});
}
|
|
524
|
}
|
|
525
|
}
|
|
526
|
|
|
527
|
// Response.Result = td;
|
|
528
529
|
//PP片InStationC03站台补给空栈板逻辑
|
|
530
|
if ((td.TaskType == TaskType.空容器出库 || td.TaskType == TaskType.站台到站台) && td.DestinationLocation.Contains("ProductStationC0") && td.DestinationLocation != "ProductStationC09")
|
|
531
532
|
{
//判断是否有正在出的InStationC03空栈板任务,InStationC03托盘号是否为空,判断成功补给
|
|
533
|
if (_unitWork.IsExist<Station>(n => n.Code == "InStationC03" && n.Containercode == "" && n.IsStop == 0) && !_unitWork.IsExist<TaskDetail>(n => n.TaskType == TaskType.空容器出库 && n.DestinationLocation.Contains("ProductStationC0") && n.DestinationLocation != "ProductStationC09"))
|
|
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
{
var container = (from con in _unitWork.Find<Container>(n => n.Status == ContainerStatus.空 && n.IsLock == 0)
join loca in _unitWork.Find<Location>(n => n.Roadway == td.Roadway && n.Status == LocationStatus.空容器)
on con.LocationCode equals loca.Code
select con).FirstOrDefault();
if (container != null)
{
//建立容器出库任务
if (!_unitWork.IsExist<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.ContainerCode == container.Code))
{
int ptdcount = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.DestinationLocation == "InStationC03").Count();
if (ptdcount < 1)
{
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = _apprd.GetTaskNo(TaskNo.空板补充);
ptask.TaskNo = taskNo;
ptask.OrderCode = taskNo;
ptask.BusinessType = BusinessType.出库_其他出库单;
ptask.FirstStatus = TaskStatus.待下发任务;
ptask.LastStatus = TaskStatus.待下发任务;
ptask.CreateTime = DateTime.Now;
_unitWork.Add(ptask);
ptaskDetail.TaskNo = taskNo;
ptaskDetail.OrderCode = taskNo;
ptaskDetail.TaskType = TaskType.空容器出库;
ptaskDetail.ContainerCode = container.Code;
ptaskDetail.SourceLocation = container.LocationCode;
ptaskDetail.DestinationLocation = "InStationC03";
ptaskDetail.OderQty = 0;
ptaskDetail.ContainerQty = 0;
ptaskDetail.HadQty = 0;
ptaskDetail.Roadway = td.Roadway;
ptaskDetail.Station = "InStationC03";
ptaskDetail.Status = TaskStatus.待下发任务;
ptaskDetail.Priority = 0;
ptaskDetail.CreateTime = DateTime.Now;
_unitWork.Add(ptaskDetail);
container.IsLock = 1;
_unitWork.Update(container);
Location locat = _unitWork.Find<Location>(n => n.Code == container.LocationCode).FirstOrDefault();
|
|
578
579
580
581
|
_unitWork.Update<Location>(n => n.Id == locat.Id && n.Version == locat.Version, n => new Location
{
Status = LocationStatus.任务锁定中,
});
|
|
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
}
}
}
}
}
//判断该任务是否为补给InStationC03的任务
else if (td.TaskType == TaskType.空容器出库 && td.DestinationLocation == "InStationC03")
{
//查询是否已经建立了补给入库站台的任务
TaskDetail tdPP = _unitWork.Find<TaskDetail>(n => n.TaskType == TaskType.站台到站台 && n.Status == TaskStatus.新建任务 && n.SourceLocation == "InStationC03").FirstOrDefault();
if (tdPP != null)
{
tdPP.Status = TaskStatus.待下发任务;
_unitWork.Update(tdPP);
}
}
|
|
598
599
600
601
602
603
604
605
|
}
else if (sTKStatusModel.Status == 40) //堆垛机入库完成容器到达仓位
{
string locationStatus = ContainerStatus.有;
foreach (TaskDetail t in taskDetails)
{
if (t.TaskType == TaskType.容器回库)
{
|
|
606
607
608
|
//判断是否为木栈板回库 找到对应出库明细任务
if (_unitWork.IsExist<Station>(n => n.Type == StationType.木栈板补给站台w_1 || n.Type == StationType.木栈板补给站台w_2))
{
|
|
609
|
ShipmentDetail shipmentDetail = _unitWork.Find<ShipmentDetail>(n => n.ShipmentCode == t.OrderCode && n.Status == ShipmentHeaderStatus.分配完成).FirstOrDefault();
|
|
610
611
612
|
if (shipmentDetail != null)
{
var con = (from c in _unitWork.Find<Container>(n => n.IsLock == 0)
|
|
613
|
join i in _unitWork.Find<Inventory>(n => n.MaterialCode == shipmentDetail.MaterialCode && n.Status == InventoryTaskType.无任务)
|
|
614
615
616
617
618
|
on c.Code equals i.ContainerCode
select c).FirstOrDefault();
int ptdcount = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.ContainerCode == con.Code && n.TaskType == TaskType.容器出库).Count();
if (ptdcount < 1)
{
|
|
619
|
Station station = _unitWork.Find<Station>(n => n.Type == StationType.木板补给终点站台).FirstOrDefault();
|
|
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = _apprh.GetTaskNo(TaskNo.空板补充);
ptask.TaskNo = taskNo;
ptask.OrderCode = taskNo;
ptask.BusinessType = BusinessType.出库_其他出库单;
ptask.FirstStatus = TaskStatus.待下发任务;
ptask.LastStatus = TaskStatus.待下发任务;
_unitWork.Add(ptask);
ptaskDetail.TaskNo = taskNo;
ptaskDetail.OrderCode = taskNo;
ptaskDetail.TaskType = TaskType.空容器出库;
ptaskDetail.ContainerCode = con.Code;
ptaskDetail.SourceLocation = con.LocationCode;
if (con.Type == ContainerType.木栈板母板_1)
{
ptaskDetail.DestinationLocation = _unitWork.Find<Station>(n => n.Type == StationType.木栈板母板补给站台s_1).Select(n => n.Code).ToString();
}
else
{
ptaskDetail.DestinationLocation = _unitWork.Find<Station>(n => n.Type == StationType.木栈板母板补给站台s_2).Select(n => n.Code).ToString();
}
ptaskDetail.Station = ptaskDetail.DestinationLocation;
ptaskDetail.OderQty = 0;
ptaskDetail.ContainerQty = 0;
ptaskDetail.HadQty = 0;
ptaskDetail.Roadway = int.Parse(_unitWork.Find<Location>(n => n.ContainerCode == con.Code).Select(n => n.Roadway).ToString());
ptaskDetail.Status = TaskStatus.待下发任务;
ptaskDetail.Priority = 0;
_unitWork.Add(ptaskDetail);
Inventory inventory = _unitWork.Find<Inventory>(n => n.ContainerCode == con.Code && n.MaterialCode == shipmentDetail.MaterialCode).FirstOrDefault();
inventory.Qty -= 1;
_unitWork.Update(inventory);
station.Containercode = con.Code;
_unitWork.Update(station);
|
|
656
|
Location Location = _unitWork.Find<Location>(n => n.ContainerCode == con.Code).FirstOrDefault();
|
|
657
658
659
660
|
_unitWork.Update<Location>(n => n.Id == Location.Id && n.Version == Location.Version, n => new Location
{
IsStop = true
});
|
|
661
662
663
|
Container Container = _unitWork.Find<Container>(n => n.Code == con.Code).FirstOrDefault();
Container.IsLock = 1;
_unitWork.Update(Container);
|
|
664
665
666
667
668
|
shipmentDetail.Status = ShipmentHeaderStatus.回传;
_unitWork.Update(shipmentDetail);
}
}
}
|
|
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
|
t.Status = TaskStatus.已经完成; //更新托盘入库任务为已完成
t.UpdateBy = "wms";
t.UpdateTime = DateTime.Now;
_unitWork.Update(t);
Task pintask = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
if (pintask == null)
{
throw new Exception("任务主表:" + t.TaskNo + "不存在!");
}
pintask.FirstStatus = TaskStatus.已经完成;
pintask.LastStatus = TaskStatus.已经完成;
pintask.UpdateBy = "wms";
pintask.UpdateTime = DateTime.Now;
_unitWork.Update(pintask);
//已完成的托盘入库任务迁移至历史任务表
TaskHistory taskHistory = new TaskHistory();
pintask.CopyTo(taskHistory);
taskHistory.Id = null;
_unitWork.Add(taskHistory);
TaskDetailHistory taskDetailHistory = new TaskDetailHistory();
t.CopyTo(taskDetailHistory);
taskDetailHistory.Id = null;
_unitWork.Add(taskDetailHistory);
//删除已完成的托盘入库任务
_unitWork.Delete(pintask);
_unitWork.Delete(t);
}
else
{
t.Status = TaskStatus.已经完成; //更新任务明细状态为已完成
t.UpdateBy = "wms";
t.UpdateTime = DateTime.Now;
_unitWork.Update(t);
//更新主任务头尾状态
Task task = _context.Set<Task>().AsQueryable().Where(u => u.TaskNo == t.TaskNo).SingleOrDefault();
if (task == null)
{
throw new Exception("任务主表:" + t.TaskNo + "不存在!");
}
// Task task = _unitWork.FindSingle<Task>(u => u.TaskNo == t.TaskNo);
TaskDetail tdel = _unitWork.Find<TaskDetail>(u => u.TaskNo == t.TaskNo).OrderBy(a => a.Status).FirstOrDefault();//同一个任务号下面最小的任务状态,包含其它容器的任务,用于更新主任务的尾状态
if (tdel == null)
{
throw new Exception("任务子表:" + t.TaskNo + "不存在!");
}
if (task.FirstStatus < t.Status)
{
task.FirstStatus = t.Status;
}
if (task.LastStatus < tdel.Status)
{
task.LastStatus = tdel.Status;
}
task.UpdateBy = "wms";
task.UpdateTime = DateTime.Now;
_unitWork.Update(task);
//已完成的单据任务迁移至历史任务表
if (task.LastStatus == TaskStatus.已经完成)
{
TaskHistory taskhis = new TaskHistory();
task.CopyTo(taskhis);
taskhis.Id = null;
_unitWork.Add(taskhis);
List<TaskDetail> taskdtls = _context.Set<TaskDetail>().AsQueryable().Where(u => u.TaskNo == task.TaskNo).ToList();
foreach (TaskDetail tdl in taskdtls)
{
TaskDetailHistory taskdthis = new TaskDetailHistory();
tdl.CopyTo(taskdthis);
taskdthis.Id = null;
_unitWork.Add(taskdthis);
_unitWork.Delete(tdl);
}
_unitWork.Delete(task);
}
if (t.TaskType == TaskType.整盘出库 || t.TaskType == TaskType.分拣出库)//出库任务类型
{
//更新出库明细状态
|
|
753
|
ShipmentDetail shipmentDetail = _context.Set<ShipmentDetail>().AsQueryable().Where(u => u.SourceCode == t.SourceCode && u.ShipmentCode == t.OrderCode && u.MaterialCode == t.MaterialCode && t.OderQty == t.HadQty).SingleOrDefault();
|
|
754
|
// ShipmentDetail shipmentDetail = _unitWork.Find<ShipmentDetail>(u => u.SourceCode == t.SourceCode && u.ShipmentCode == t.OrderCode && u.MaterialCode == t.MaterialCode).FirstOrDefault();
|
|
755
|
if (shipmentDetail != null)
|
|
756
|
{
|
|
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
|
shipmentDetail.Status = ShipmentHeaderStatus.过账;
shipmentDetail.UpdateBy = "wms";
shipmentDetail.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentDetail);
//更新主出库单头尾状态
// ShipmentHeader shipmentHeader = _unitWork.Find<ShipmentHeader>(u => u.Code == t.OrderCode).FirstOrDefault();
ShipmentHeader shipmentHeader = _context.Set<ShipmentHeader>().AsQueryable().Where(u => u.Code == t.OrderCode).SingleOrDefault();
ShipmentDetail shipdt = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == t.OrderCode).OrderBy(a => a.Status).FirstOrDefault();
if (shipmentHeader.FirstStatus < shipmentDetail.Status)
{
shipmentHeader.FirstStatus = shipmentDetail.Status;
}
if (shipmentHeader.LastStatus < shipdt.Status)
{
shipmentHeader.LastStatus = shipdt.Status;
}
shipmentHeader.UpdateBy = "wms";
shipmentHeader.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentHeader);
|
|
776
|
|
|
777
778
|
//已完成的出库单据迁移至历史出库单据,暂以过账状态,后期与ERP对接后以回传状态
if (shipmentHeader.LastStatus == ShipmentHeaderStatus.过账)
|
|
779
|
{
|
|
780
781
782
783
784
785
786
787
788
789
790
791
792
793
|
ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();
shipmentHeader.CopyTo(shipmentHeaderHistory);
shipmentHeaderHistory.Id = null;
_unitWork.Add(shipmentHeaderHistory);
List<ShipmentDetail> shipdtls = _context.Set<ShipmentDetail>().AsQueryable().Where(u => u.ShipmentCode == shipmentHeader.Code).ToList();
// List<ShipmentDetail> shipdtls = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == shipmentHeader.Code).ToList();
foreach (ShipmentDetail sd in shipdtls)
{
ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
sd.CopyTo(shipmentDetailHistory);
shipmentDetailHistory.Id = null;
shipmentDetailHistory.ShipmentId = shipmentHeaderHistory.Id;
_unitWork.Add(shipmentDetailHistory);
|
|
794
|
|
|
795
796
797
|
_unitWork.Delete(sd);
}
_unitWork.Delete(shipmentHeader);
|
|
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
}
}
}
else if (t.TaskType == TaskType.整盘入库 || t.TaskType == TaskType.补充入库)//入库任务类型
{
//更新入库明细单据状态
ReceiptDetail receiptDetail = _unitWork.Find<ReceiptDetail>(u => u.SourceCode == t.SourceCode && u.ReceiptCode == t.OrderCode && u.MaterialCode == t.MaterialCode && t.OderQty == t.HadQty).FirstOrDefault();
if (receiptDetail != null)
{
receiptDetail.Status = ReceiptHeaderStatus.过账;
receiptDetail.UpdateBy = "wms";
receiptDetail.UpdateTime = DateTime.Now;
_apprd.UpdateByTracking(receiptDetail);
//更新入库主单据头尾状态
// ReceiptHeader receiptHeader = _unitWork.Find<ReceiptHeader>(u => u.Code == t.OrderCode).FirstOrDefault();
ReceiptHeader receiptHeader = _context.Set<ReceiptHeader>().AsQueryable().Where(u => u.Code == t.OrderCode).SingleOrDefault();
ReceiptDetail recepdt = _unitWork.Find<ReceiptDetail>(u => u.ReceiptCode == t.OrderCode).OrderBy(a => a.Status).FirstOrDefault();
if (receiptHeader.FirstStatus < receiptDetail.Status)
{
receiptHeader.FirstStatus = receiptDetail.Status;
}
if (receiptHeader.LastStatus < recepdt.Status)
{
receiptHeader.LastStatus = recepdt.Status;
}
receiptHeader.UpdateBy = "wms";
receiptHeader.UpdateTime = DateTime.Now;
_apprh.UpdateByTracking(receiptHeader);
//已完成的入库单据迁移至历史入库单据,暂以过账状态,后期与ERP对接后以回传状态
if (receiptHeader.LastStatus == ReceiptHeaderStatus.过账)
{
ReceiptHeaderHistory receiptHeaderHistory = new ReceiptHeaderHistory();
receiptHeader.CopyTo(receiptHeaderHistory);
receiptHeaderHistory.Id = null;
_unitWork.Add(receiptHeaderHistory);
List<ReceiptDetail> recepdtls = _context.Set<ReceiptDetail>().AsQueryable().Where(u => u.ReceiptCode == receiptHeader.Code).ToList();
// List<ReceiptDetail> recepdtls = _unitWork.Find<ReceiptDetail>(u => u.ReceiptCode == receiptHeader.Code).ToList();
foreach (ReceiptDetail rd in recepdtls)
{
ReceiptDetailHistory receiptDetailHistory = new ReceiptDetailHistory();
rd.CopyTo(receiptDetailHistory);
receiptDetailHistory.Id = null;
receiptDetailHistory.ReceiptId = receiptHeaderHistory.Id;
_unitWork.Add(receiptDetailHistory);
_unitWork.Delete(rd);
}
_unitWork.Delete(receiptHeader);
}
}
}
else if (t.TaskType == TaskType.空容器入库) //空容器入库任务类型
{
locationStatus = LocationStatus.空容器;
|
|
853
854
|
}
else if (t.TaskType == TaskType.出库查看)
|
|
855
856
857
|
{
}
|
|
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
|
//else if (t.TaskType == TaskType.盘点)
//{
// Inventory inventory = _unitWork.Find<Inventory>(n => n.ContainerCode == t.ContainerCode).FirstOrDefault();
// List<Inventory> invs = _unitWork.Find<Inventory>(n => n.ContainerCode == inventory.ContainerCode).ToList();
// foreach (Inventory inv in invs)
// {
// inv.TaskStatus = "cyclecountLock";
// _appi.UpdateByTracking(inv);
// }
// CyclecountHeader cycher = _unitWork.Find<CyclecountHeader>(n => n.Code == t.OrderCode).FirstOrDefault();
// CyclecountDetail cycdel = _unitWork.Find<CyclecountDetail>(n => n.Status == ReceiptHeaderStatus.过账 && n.MaterialCode == t.MaterialCode && n.ContainerCode == t.ContainerCode && n.Code == t.OrderCode).FirstOrDefault();
// CyclecountDetail cycdelEnd = _unitWork.Find<CyclecountDetail>(n => n.Code == t.OrderCode && n.Id != cycdel.Id).OrderBy(n => n.Status).FirstOrDefault();
// if (cycdel != null)
// {
// cycdel.Status = ReceiptHeaderStatus.回传;
// _unitWork.Update(cycdel);
// if (cycdelEnd.Status >= cycdel.Status)
// {
// cycher.Status = (short)cycdel.Status;
// _unitWork.Update(cycher);
// }
// if (t.OderQty < t.HadQty)
// {
// //erp传数据
// }
// else if (t.OderQty > t.HadQty)
// {
// //erp传数据
// }
// }
//}
|
|
889
890
891
892
893
894
895
|
else
{
throw new Exception("未知任务类型:" + t.TaskType);
}
}
}
|
|
896
|
//清除该托盘占用的站台
|
|
897
898
899
900
901
902
|
//Station s = _unitWork.Find<Station>(n => n.Code == td.SourceLocation && n.Containercode == td.ContainerCode && (td.TaskType == TaskType.容器回库 || td.TaskType == TaskType.空容器入库)).FirstOrDefault();
//if (s != null)
//{
// s.Containercode = "";
// _unitWork.Update(s);
//}
|
|
903
904
905
906
907
908
|
//托盘入库完成,解锁并释放仓位
Location loc = _unitWork.Find<Location>(u => u.Code == td.DestinationLocation).FirstOrDefault();
if (loc == null)
{
throw new Exception("仓位:" + td.DestinationLocation + "不存在!");
}
|
|
909
910
911
912
913
914
915
916
|
_unitWork.Update<Location>(n => n.Id == loc.Id && n.Version == loc.Version, n => new Location
{
ContainerCode = td.ContainerCode,
Status = locationStatus,
UpdateBy = "wms",
UpdateTime = DateTime.Now
});
|
|
917
|
List<Inventory> inventories = _unitWork.Find<Inventory>(n => n.ContainerCode == td.ContainerCode && n.Status != "cyclecountLock").ToList();
|
|
918
919
920
921
922
|
//更新同个容器中其它物料对应新的回库仓位
if (inventories.Count > 0)
{
foreach (Inventory inv in inventories)
{
|
|
923
924
|
if (loc.Roadway == 2)
{
|
|
925
|
inv.WarehouseType = "PPJ_WareCell";
|
|
926
|
}
|
|
927
|
else if (loc.Roadway == 3)
|
|
928
|
{
|
|
929
|
inv.WarehouseType = "PPP_WareCell";
|
|
930
|
}
|
|
931
|
else if (loc.Roadway == 4)
|
|
932
|
{
|
|
933
|
inv.WarehouseType = "TB_WareCell";
|
|
934
935
|
}
|
|
936
937
938
939
|
if (inv.LocationCode != loc.Code)
{
inv.LocationCode = loc.Code;
}
|
|
940
|
|
|
941
942
943
944
|
if (inv.TaskStatus == InventoryTaskType.任务锁定中)
{
inv.TaskStatus = InventoryTaskType.无任务;
}
|
|
945
|
_appi.Update(inv);
|
|
946
947
|
}
}
|
|
948
949
950
951
952
953
954
|
//托盘入库完成,解锁并释放容器
Container container = _unitWork.Find<Container>(u => u.Code == td.ContainerCode).FirstOrDefault();
if (container == null)
{
throw new Exception("容器:" + td.ContainerCode + "不存在!");
}
container.LocationCode = td.DestinationLocation;
|
|
955
|
container.IsLock = ContainerLock.未锁;
|
|
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
|
container.UpdateBy = "wms";
container.UpdateTime = DateTime.Now;
_unitWork.Update(container);
}
else
{
Response.Code = 500;
Response.Status = false;
Response.Message = "不识别的任务状态!";
}
}
else
{
Response.Code = 500;
Response.Status = false;
Response.Message = "获取任务号错误,未找到此容器的任务!";
}
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
Response.Code = 500;
Response.Status = false;
Response.Message = ex.Message;
}
|
|
983
|
return Response;
|
|
984
985
986
987
988
|
}
}
}
}
|