IEmptyPalletOutApp.cs
5.68 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
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 string EmptyPalletOutApp(string station, string type)
{
Response response = new Response();
try
{
StationRoadway 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)
{
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 JsonHelper.Instance.Serialize(response);
}
//建立容器出库任务
if (!_unitWork.IsExist<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.MaterialCode == container.Code))
{
int ptdcount = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.ContainerCode == container.Code && n.TaskType == TaskType.容器出库).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.待下发任务;
_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;
_unitWork.Add(ptaskDetail);
container.IsLock = 1;
_unitWork.Update(container);
Location loc = _unitWork.Find<Location>(n => n.Code == container.LocationCode).FirstOrDefault();
loc.Status = LocationStatus.任务锁定中;
_unitWork.Update(loc);
}
else
{
response.Code = 300;
response.Message = "异常" + container.Code + "栈板有任务!";
return JsonHelper.Instance.Serialize(response);
}
}
else
{
var t = _unitWork.Find<TaskDetail>(n => (n.Status >= TaskStatus.新建任务 && n.Status < TaskStatus.已经完成) && n.MaterialCode == container.Code).ToList();
response.Code = 300;
response.Message = "异常" + container.Code + "栈板有任务!";
return JsonHelper.Instance.Serialize(response);
}
}
else
{
response.Code = 300;
response.Message = "无此站台!";
return JsonHelper.Instance.Serialize(response);
}
}
catch (Exception ex)
{
response.Code = 300;
response.Message = ex.Message;
}
return JsonHelper.Instance.Serialize(response);
}
}
}