EmptyOutAction.cs
6.78 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
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 EmptyOutAction
{
private string ConnString { set; get; }
IJobExecutionContext Context { set; get; }
public EmptyOutAction(string _ConnString, IJobExecutionContext _Context)
{
ConnString = _ConnString;
Context = _Context;
}
public void Execute(JobContainer jobContainer)
{
UnitWork _unitWork = new UnitWork(AppSettingsJson.JobContext(ConnString));
try
{
List<Station> stations = _unitWork.Find<Station>(n => n.Type == StationType.空板暂存区站台).ToList();
string type = "";
foreach (Station station in stations)
{
if (!_unitWork.IsExist<TaskDetail>(n => n.DestinationLocation == station.Code || n.SourceLocation == station.Code))
{
int num = _unitWork.Find<StoreStation>(n => n.StationCode == station.Code).Count();
StationRoadway stationRoadway = _unitWork.Find<StationRoadway>(n => n.StationCode == station.Code).FirstOrDefault();
if (stationRoadway != null)
{
while (num < station.MaxNum)
{
//可用的空容器
var container = (from con in _unitWork.Find<Container>(n => n.Status == ContainerStatus.空 && n.IsLock == 0)
join loca in _unitWork.Find<Location>(n => n.Roadway == stationRoadway.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 == station.Code).Count();
//如果不存在
if (ptdcount < 1)
{
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = _unitWork.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 = station.Code;
ptaskDetail.OderQty = 0;
ptaskDetail.ContainerQty = 0;
ptaskDetail.HadQty = 0;
ptaskDetail.Roadway = stationRoadway.RoadWay;
ptaskDetail.Station = station.Code;
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();
_unitWork.Update<Location>(n => n.Id == locat.Id && n.Version == locat.Version, n => new Location
{
Status = LocationStatus.任务锁定中,
});
StoreStation storeStation = new StoreStation
{
StationCode = station.Code,
ContainerCode = container.Code,
Status = StoreStationStatus.任务中,
CreateTime = DateTime.Now
};
_unitWork.Add(storeStation);
}
else
{
break;
}
}
}
num = _unitWork.Find<StoreStation>(n => n.StationCode == station.Code).Count();
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}