EmptyOutAction.cs
8.89 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
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 = "p_1";
foreach (Station station in stations)
{
//正在执行的空板补给任务
int EmptyCount = _unitWork.Find<TaskDetail>(n => n.DestinationLocation == station.Code).Count();
//正在执行空板任务小于最大数量
if (EmptyCount < station.MaxNum)
{
StationRoadway stationRoadway = _unitWork.Find<StationRoadway>(n => n.StationCode == station.Code).FirstOrDefault();
if (stationRoadway != null)
{
//可用的空容器
Container container = null;
int num = _unitWork.Find<StoreStation>(n => n.StationCode == station.Code).Count();
while (num < station.MaxNum)
{
if (stationRoadway.StationPlace == StationPlace.巷道北面)
{
container = (from con in _unitWork.Find<Container>(n => n.Type == type && n.Status == ContainerStatus.空 && n.IsLock == 0)
join loc in _unitWork.Find<Location>(n => n.Roadway == stationRoadway.RoadWay && n.Status == LocationStatus.空容器)
on con.LocationCode equals loc.Code
orderby loc.RowIndex == 2 ? 0 : loc.RowIndex, loc.Row
select con).FirstOrDefault();
}
else if (stationRoadway.StationPlace == StationPlace.巷道南面)
{
container = (from con in _unitWork.Find<Container>(n => n.Type == type && n.Status == ContainerStatus.空 && n.IsLock == 0)
join loc in _unitWork.Find<Location>(n => n.Roadway == stationRoadway.RoadWay && n.Status == LocationStatus.空容器)
on con.LocationCode equals loc.Code
orderby loc.RowIndex == 2 ? 0 : loc.RowIndex, loc.Row descending
select con).FirstOrDefault();
}
else
{
container = (from con in _unitWork.Find<Container>(n => n.Type == type && n.Status == ContainerStatus.空 && n.IsLock == 0)
join loc in _unitWork.Find<Location>(n => n.Roadway == stationRoadway.RoadWay && n.Status == LocationStatus.空容器)
on con.LocationCode equals loc.Code
orderby loc.RowIndex == 2 ? 0 : loc.RowIndex
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 < station.MaxNum)
//{
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = "ZD" + _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 = 99;
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);
break;
//}
//else
//{
// break;
//}
}
}
//num = _unitWork.Find<StoreStation>(n => n.StationCode == station.Code).Count();
break;
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}