IShipmentApp.cs
5.76 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
using System;
using System.Linq;
using Infrastructure;
using WebRepository;
namespace WebApp
{
/// <summary>
/// 出库单下发接口App
/// </summary>
public partial class IShipmentApp : ApiApp
{
public IRepository<ShipmentHeader> _app;
public IShipmentApp(IUnitWork unitWork, IAuth auth, BaseDBContext context, IRepository<ShipmentHeader> shipmentHeader) : base(unitWork, auth, context)
{
_app = shipmentHeader;
}
public string InsertShipment(IShipmentModel shipments)
{
IReceiptBackModel Response = new IReceiptBackModel();
using (var tran = _unitWork.GetDbContext().Database.BeginTransaction())
{
try
{
//判断出库站台是否正确
string WareCell = "";
StationRoadway Staroadway = _unitWork.Find<StationRoadway>(n => n.StationCode == shipments.LWHSL).FirstOrDefault();
if (Staroadway != null)
{
if (Staroadway.RoadWay == 1)
{
WareCell = "TB_WareCell";
}
else if (Staroadway.RoadWay == 2)
{
WareCell = "PP_WareCell";
}
else if (Staroadway.RoadWay == 3)
{
WareCell = "PJ_WareCell";
}
}
else
{
Response.Status = "E";
Response.ErrorMsg = "站台错误,未找到" + shipments.LWHSL + "站台,无法创建任务!";
return JsonHelper.Instance.Serialize(Response);
}
#region 保存出库单主表
ApiShipmentHeader apiShipmentHeader = _unitWork.Find<ApiShipmentHeader>(n => n.SourceCode == shipments.TaskNumber).FirstOrDefault();
if (apiShipmentHeader != null)
{
Response.Status = "E";
Response.ErrorMsg = "单据重复下发!";
return JsonHelper.Instance.Serialize(Response);
}
else
{
apiShipmentHeader = new ApiShipmentHeader
{
Organization = shipments.Organization,
SourceCode = shipments.TaskNumber,
WarehouseType = WareCell,
Type = shipments.TaskType.ToString(),
TotalQty = shipments.Quantity,
Code = _unitWork.GetTaskNo(shipments.TaskType.ToString()),
FirstStatus = ShipmentHeaderStatus.新建,
LastStatus = ShipmentHeaderStatus.新建,
TotalLines = 1,
ShipTo = shipments.Supllier,
Station = shipments.LWHSL,
CreateTime = DateTime.Now,
CreateBy = "Api",
ErpListType = shipments.ErpListType,
Status = 0
};
_unitWork.Add(apiShipmentHeader);
}
ApiInterfaceLog Apiinter = new ApiInterfaceLog
{
Type = "ApiLK_Out",
AllNum = 1,
ComNum = 0,
Request = JsonHelper.Instance.Serialize(shipments),
Status = 0,
TaskNo = shipments.TaskNumber,
CreateTime = DateTime.Now,
CreateBy = "Api"
};
_unitWork.Add(Apiinter);
#endregion
#region 保存出库单子表
ApiShipmentDetail apiShipmentDetail = new ApiShipmentDetail();
apiShipmentDetail = new ApiShipmentDetail
{
SourceCode = shipments.TaskNumber,
MaterialCode = shipments.PN,
InventoryStatus = "",
Qty = shipments.Quantity,
Lot = shipments.MO,
CreateTime = apiShipmentHeader.CreateTime,
CreateBy = apiShipmentHeader.CreateBy,
ShipmentId = apiShipmentHeader.Id,
ShipmentCode = apiShipmentHeader.Code,
QtyDivided = 0,
QtyCompleted = 0,
Price = 0,
Status = ShipmentHeaderStatus.新建,
WH = shipments.WH,
WHSL = shipments.WHSL,
LWH = shipments.LWH,
LWHSL = shipments.LWHSL,
Project = shipments.Barcode,
};
_unitWork.Add(apiShipmentDetail);
#endregion
Response.Status = "S";
Response.TaskNumber = apiShipmentHeader.SourceCode;
tran.Commit();
}
catch (Exception ex)
{
Response.Status = "E";
Response.ErrorMsg = "MES出库创建失败,Message:" + ex.Message + ",StackTrace:" + ex.StackTrace + ",Source" + ex.Source + ",Data" + ex.Data;
tran.Rollback();
}
}
return JsonHelper.Instance.Serialize(Response);
}
}
}