IEmptyPalletOutApp.cs
10.3 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
using System;
using System.Linq;
using Infrastructure;
using WebRepository;
namespace WebApp
{
/// <summary>
/// 空栈板补给接口App
/// </summary>
public partial class IEmptyPalletOutApp : ApiApp
{
public IRepository<ReceiptHeader> _app;
public IEmptyPalletOutApp(IUnitWork unitWork, IAuth auth, BaseDBContext context, IRepository<ReceiptHeader> app) : base(unitWork, auth, context)
{
_app = app;
}
public Response EmptyPalletOutApp(string station, string type)
{
Response response = new Response();
Station sta = _unitWork.Find<Station>(N => N.Code == station).FirstOrDefault();
try
{
StationRoadway stationRoadway = null;
if (sta == null)
{
response.Code = 300;
response.Message = station + "未找到该站台!";
return response;
}
if (sta.Type == StationType.PP片上胶站台)
{
//用PP片入库位置找出PP片空栈板补给仓位
StationToStation stationToStation = _unitWork.Find<StationToStation>(n => n.EndStation == station).FirstOrDefault();
stationRoadway = (from sr in _unitWork.Find<StationRoadway>(n => n.StationCode == stationToStation.StartStation)
join st in _unitWork.Find<Station>(n => n.Code == stationToStation.StartStation && n.IsEmpty == 1 && n.Containercode == "")
on sr.StationCode equals st.Code
select sr).FirstOrDefault();
}
else
{
stationRoadway = (from sr in _unitWork.Find<StationRoadway>(n => n.StationCode == station)
join st in _unitWork.Find<Station>(n => n.Code == station && n.IsEmpty == 1 && n.Containercode == "")
on sr.StationCode equals st.Code
select sr).FirstOrDefault();
}
if (stationRoadway == null)
{
response.Code = 300;
response.Message = station + "状态不正确!";
return response;
}
int count = _unitWork.Find<TaskDetail>(u => u.DestinationLocation == stationRoadway.StationCode && u.Status >= TaskStatus.新建任务 && u.Status < TaskStatus.已经完成 && (u.TaskType == TaskType.容器出库 || u.TaskType == TaskType.空容器出库 || u.TaskType == TaskType.站台到站台)).Count();
if (count > 0)
{
response.Message = "已有该站台出库任务!";
return response;
}
if (stationRoadway != null)
{
if (stationRoadway.RoadWay == 3)
{
Station s = _unitWork.Find<Station>(n => n.Code == "InStationC03").FirstOrDefault();
if ((s.Containercode != "" || _unitWork.IsExist<TaskDetail>(n => n.DestinationLocation == s.Code && n.TaskType == TaskType.空容器出库)) && sta.Type == StationType.PP片上胶站台 && !_unitWork.IsExist<TaskDetail>(n => n.ContainerCode == s.Containercode && n.ContainerCode != "" && n.TaskType == TaskType.站台到站台))
{
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = _app.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.站台到站台;
if (s.Containercode == "")
{
ptaskDetail.ContainerCode = _unitWork.Find<TaskDetail>(n => n.DestinationLocation == s.Code && n.TaskType == TaskType.空容器出库).Select(a => a.ContainerCode).FirstOrDefault();
}
else
{
ptaskDetail.ContainerCode = s.Containercode;
}
ptaskDetail.SourceLocation = s.Code;
ptaskDetail.DestinationLocation = stationRoadway.StationCode;
ptaskDetail.OderQty = 0;
ptaskDetail.ContainerQty = 0;
ptaskDetail.HadQty = 0;
ptaskDetail.Roadway = stationRoadway.RoadWay;
ptaskDetail.Station = stationRoadway.StationCode;
if (_unitWork.IsExist<TaskDetail>(n => n.TaskType == TaskType.空容器出库 && n.DestinationLocation == s.Code))
{
ptaskDetail.Status = TaskStatus.新建任务;
}
else
{
ptaskDetail.Status = TaskStatus.待下发任务;
}
ptaskDetail.Priority = 20;
ptaskDetail.CreateTime = DateTime.Now;
_unitWork.Add(ptaskDetail);
return response;
}
}
var 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
select con).FirstOrDefault();
if (container == null)
{
response.Code = 300;
response.Message = "库内无空栈板!";
return response;
}
//建立容器出库任务
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 == stationRoadway.StationCode).Count();
if (ptdcount < 1)
{
Task ptask = new Task();
TaskDetail ptaskDetail = new TaskDetail();
var taskNo = _app.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 = stationRoadway.StationCode;
ptaskDetail.OderQty = 0;
ptaskDetail.ContainerQty = 0;
ptaskDetail.HadQty = 0;
ptaskDetail.Roadway = stationRoadway.RoadWay;
ptaskDetail.Station = stationRoadway.StationCode;
ptaskDetail.Status = TaskStatus.待下发任务;
ptaskDetail.Priority = 0;
ptaskDetail.CreateTime = DateTime.Now;
_unitWork.Add(ptaskDetail);
container.IsLock = 1;
_unitWork.Update(container);
Location loc = _unitWork.Find<Location>(n => n.Code == container.LocationCode).FirstOrDefault();
_unitWork.Update<Location>(n => n.Id == loc.Id && n.Version == loc.Version, n => new Location
{
Status = LocationStatus.任务锁定中
});
}
else
{
response.Code = 300;
response.Message = "异常站台:" + stationRoadway.StationCode + "有任务!";
return response;
}
}
else
{
response.Code = 300;
response.Message = "异常" + container.Code + "栈板有任务!";
return response;
}
}
else
{
response.Code = 300;
response.Message = "此站台暂时不能补给空栈板!";
return response;
}
}
catch (Exception ex)
{
response.Code = 300;
response.Message = ex.Message;
}
return response;
}
}
}