IReceiptApp.cs
9.23 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using WebRepository;
namespace WebApp
{
/// <summary>
/// 入库单下发接口App
/// </summary>
public partial class IReceiptApp : ApiApp
{
public IRepository<ReceiptHeader> _app;
public IReceiptApp(IUnitWork unitWork, IAuth auth, BaseDBContext context, IRepository<ReceiptHeader> repository) : base(unitWork, auth, context)
{
_app = repository;
}
public string InsertReceipt(IReceiptModel receipts)
{
IReceiptBackModel Response = new IReceiptBackModel();
using (var tran = _unitWork.GetDbContext().Database.BeginTransaction())
{
try
{
#region 保存入库单主表
ReceiptHeader receiptHeader = _unitWork.FindSingle<ReceiptHeader>(u => u.SourceCode == receipts.TaskNumber);
if (receiptHeader != null)
{
Response.Status = "E";
Response.ErrorMsg = "单据重复下发!";
return JsonHelper.Instance.Serialize(Response);
}
else
{
receiptHeader = new ReceiptHeader
{
Type = receipts.TaskType.ToString(),
SourceCode = receipts.TaskNumber,
SupplierCode = receipts.Supllier,
CreateTime = DateTime.Now,
CreateBy = "Api",
UploadStatus = 0,
Code = _app.GetTaskNo(receipts.TaskType.ToString()),
FirstStatus = ReceiptHeaderStatus.新建,
LastStatus = ReceiptHeaderStatus.新建,
TotalLines = 0,
TotalQty = 0,
WH = receipts.WH,
WHSL = receipts.WHSL,
LWH = receipts.LWH,
LWHSL = receipts.LWH,
ContainerCode = receipts.Tray,
ErpListType = receipts.ErpListType,
Status = 0,
Organization = receipts.Organization
};
_unitWork.Add(receiptHeader);
}
//总行数
short? totalLines = 0;
//物料总数
decimal? qty = 0;
#endregion
#region 保存入库单子表
foreach (var item in receipts.stockInDetails)
{
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.SourceCode = receipts.TaskNumber;
receiptDetail.MaterialCode = receipts.PN;
receiptDetail.Lot = receipts.MO;
receiptDetail.Qty = item.Quantity;
receiptDetail.CreateTime = receiptHeader.CreateTime;
receiptDetail.CreateBy = receiptHeader.CreateBy;
receiptDetail.UpdateTime = receiptHeader.UpdateTime;
receiptDetail.UpdateBy = receiptHeader.UpdateBy;
receiptDetail.Project = item.Barcode;
receiptDetail.Batch = item.Lot;
receiptDetail.Grade = receipts.Grade;
receiptDetail.Result = receipts.Result;
receiptDetail.ReceiptId = receiptHeader.Id;
receiptDetail.ReceiptCode = receiptHeader.Code;
receiptDetail.QtyDivided = 0;
receiptDetail.QtyCompleted = 0;
receiptDetail.Price = 0;
receiptDetail.Status = ReceiptHeaderStatus.新建;
receiptDetail.Unit = item.Uom;
receiptDetail.BLot = item.Lot;
_unitWork.Add(receiptDetail);
totalLines += 1;
qty += item.Quantity;
}
#endregion
#region 更新入库单主表汇总信息
receiptHeader.TotalLines += totalLines;
receiptHeader.TotalQty += qty;
_unitWork.Update(receiptHeader);
#endregion
ApiInterfaceLog Apiinter = new ApiInterfaceLog
{
Type = "ApiLK_In",
AllNum = totalLines,
ComNum = 0,
Request = JsonHelper.Instance.Serialize(receipts),
Status = 0,
TaskNo = receipts.TaskNumber,
CreateTime = DateTime.Now,
CreateBy = "Api"
};
_unitWork.Add(Apiinter);
Response.Status = "S";
Response.TaskNumber = receiptHeader.SourceCode;
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
#region 记录入库单接口错误信息
ApiInterfaceLog Apiinter = new ApiInterfaceLog
{
Type = "ApiLK_InErr",
AllNum = 0,
ComNum = 0,
Request = JsonHelper.Instance.Serialize(receipts),
Status = 4,
TaskNo = receipts.TaskNumber,
CreateTime = DateTime.Now,
CreateBy = "Api"
};
#endregion
Response.Status = "E";
Response.ErrorMsg = "入库单据错误,Message:" + ex.Message + ",StackTrace:" + ex.StackTrace + ",Source:" + ex.Source + ",Data:" + ex.Data;
return JsonHelper.Instance.Serialize(Response);
}
}
return JsonHelper.Instance.Serialize(Response);
}
public string UpInvinspect(InspectionResultRequest UpInvinspect)
{
MesResponse mesResponse = new MesResponse();
using (var tran = _unitWork.GetDbContext().Database.BeginTransaction())
{
try
{
#region 查找并更新库存
List<Inventory> inventorys = _unitWork.Find<Inventory>(n => n.Lot == UpInvinspect.MO).ToList();
if (inventorys.Count() > 0)
{
foreach (var inventory in inventorys)
{
inventory.Result = UpInvinspect.Result;
inventory.Grade = UpInvinspect.Grade;
_unitWork.Update(inventory);
}
}
else
{
mesResponse.Status = "E";
mesResponse.ErrorMsg = "库存中未找到单号为" + UpInvinspect.MO + "的物料";
return JsonHelper.Instance.Serialize(mesResponse);
}
#endregion
//添加更改库存记录
ApiInterfaceLog Apiinter = new ApiInterfaceLog
{
AllNum = 0,
ComNum = 0,
Request = JsonHelper.Instance.Serialize(UpInvinspect),
Status = 1,
TaskNo = "ApiLK_Up",
CreateTime = DateTime.Now,
CreateBy = "Api",
Type = "更改检验成功",
};
_unitWork.Add(Apiinter);
mesResponse.Status = "S";
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
#region 记录入库单接口错误信息
ApiInterfaceLog Apiinter = new ApiInterfaceLog
{
AllNum = 0,
ComNum = 0,
Message = ex.Message,
Request = JsonHelper.Instance.Serialize(UpInvinspect),
Status = 1,
TaskNo = "",
CreateTime = DateTime.Now,
CreateBy = "Api",
Type = "更改检验失败",
};
_unitWork.Add(Apiinter);
#endregion
mesResponse.Status = "E";
mesResponse.ErrorMsg = "出库单据错误,Message:" + ex.Message + ",StackTrace:" + ex.StackTrace + ",Source:" + ex.Source + ",Data:" + ex.Data;
return JsonHelper.Instance.Serialize(mesResponse);
}
}
return JsonHelper.Instance.Serialize(mesResponse);
}
}
}