SampleService.cs
19.7 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
using Infrastructure;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using WebApp;
using WebMvc.Areas.WebService;
using WebRepository;
namespace WebMvc.Areas.WebService
{
public class SampleService : ISampleService
{
private IUnitWork _unitWork;
public IRepository<WebRepository.Task> _app;
public IRepository<Container> _appc;
public IRepository<Inventory> _appi;
public IRepository<Location> _appl;
public IRepository<ReceiptDetail> _apprd;
public IRepository<ReceiptHeader> _apprh;
public IRepository<ShipmentHeader> _apph;
public IRepository<ShipmentDetail> _appsd;
public IRepository<TaskDetail> _apptd;
public IRepository<InventoryTransaction> _appit;
private BaseDBContext _context;
private IAuth _auth;
public SampleService(IUnitWork unitWork, IAuth auth, IRepository<Inventory> inventory, IRepository<InventoryTransaction> inventoryTransaction, IRepository<Container> Icontainer, IRepository<ReceiptHeader> receiptHeader, IRepository<ReceiptDetail> receiptDetail, IRepository<WebRepository.Task> repository, IRepository<Location> repositoryl, IRepository<ShipmentHeader> repositoryh, IRepository<TaskDetail> repositorytd, IRepository<ShipmentDetail> repositorysd, BaseDBContext context)
{
_unitWork = unitWork;
_app = repository;
_appl = repositoryl;
_apph = repositoryh;
_appsd = repositorysd;
_apptd = repositorytd;
_apprd = receiptDetail;
_apprh = receiptHeader;
_appc = Icontainer;
_appi = inventory;
_appit = inventoryTransaction;
_context = context;
_auth = auth;
LoginInfo loginInfo = new LoginInfo
{
Account = "NouYaWeb"
};
SetLoginInfo(loginInfo);
}
public void SetLoginInfo(LoginInfo loginInfo)
{
_app._loginInfo = loginInfo;
_appl._loginInfo = loginInfo;
_apph._loginInfo = loginInfo;
_appsd._loginInfo = loginInfo;
_apptd._loginInfo = loginInfo;
_appc._loginInfo = loginInfo;
_apprd._loginInfo = loginInfo;
_apprh._loginInfo = loginInfo;
_appi._loginInfo = loginInfo;
_appit._loginInfo = loginInfo;
}
//入库
public string LK_In(string Request)
{
XmlDocument doc = new XmlDocument();
ConfigXmlDocument reDoc = new ConfigXmlDocument();
//读取传入的xml
var config = AppSettingsJson.GetAppSettings();
reDoc.Load(config.GetSection("NouYaWebInService:Url").Value);
//取出报文接收状态字段
XmlElement element = (XmlElement)reDoc.SelectSingleNode("//Status");
try
{
InterfaceLog inter = new InterfaceLog();
inter.Request = Request;
inter.CreateTime = DateTime.Now;
inter.CreateBy = "WMS";
inter.Type = "LK_In";
_unitWork.Add(inter);
doc.LoadXml(Request);
string name = "";
string value = "";
string UpperTaskNo = "";
string SourceCode = "";
string TaskType = "";
string CustomerCode = "";
string MaterialCode = "";
string SupplierCode = "";
decimal? Num = 0;
string WareCell = "";
string Code = "";
var NewCode = "";
XmlNodeList RecordSets = doc.SelectNodes("//Record");
foreach (XmlNode RecordSet in RecordSets)
{
XmlNodeList nodes = RecordSet.ChildNodes;
foreach (XmlElement node in nodes)
{
//抓取单个的xml节点
//获得字节里面的属性值
name = node.GetAttribute("name");
value = node.GetAttribute("value");
//上游任务号
if (name == "tc_dcf000" && !string.IsNullOrEmpty(value))
{
UpperTaskNo = value;
}
//上游作业类型
else if (name == "tc_dcf001" && !string.IsNullOrEmpty(value))
{
TaskType = value;
}
//上游系统单号
else if (name == "tc_dcf003" && !string.IsNullOrEmpty(value))
{
SourceCode = value;
}
//供应商
else if (name == "dcf004" && !string.IsNullOrEmpty(value))
{
SupplierCode = value;
}
//入库部门
else if (name == "dcf006" && !string.IsNullOrEmpty(value))
{
SupplierCode = value;
}
//提取物料号
else if (name == "tc_dcf016" && !string.IsNullOrEmpty(value))
{
MaterialCode = value;
}
//入库数量
else if (name == "tc_dcf021" && !string.IsNullOrEmpty(value))
{
Num = decimal.Parse(value);
}
//条码
else if (name == "tc_dcf025" && !string.IsNullOrEmpty(value))
{
Code = value;
}
//仓库
else if (name == "tc_dcf028" && !string.IsNullOrEmpty(value))
{
WareCell = value;
}
}
#region 保存入库单主表
ReceiptHeader receiptHeader = _unitWork.FindSingle<ReceiptHeader>(u => u.SourceCode.Equals(UpperTaskNo + "&" + SourceCode));
if (receiptHeader != null)
{
if (receiptHeader.FirstStatus != ReceiptHeaderStatus.新建)
{
throw new Exception("单据进入订单池后,不允许修改!");
}
}
else
{
NewCode = _unitWork.GetTaskNo(TaskNo.入库手动分配);
receiptHeader = new ReceiptHeader();
receiptHeader.Type = BusinessType.入库_采购到货单;
receiptHeader.SourceCode = UpperTaskNo+"&"+SourceCode;
receiptHeader.Station = "";
receiptHeader.WarehouseType = WareCell;
receiptHeader.CreateTime = DateTime.Now;
receiptHeader.CreateBy = "Erp";
receiptHeader.UploadStatus = 0;
receiptHeader.Code = _unitWork.GetTaskNo(TaskNo.入库手动分配);
receiptHeader.FirstStatus = ReceiptHeaderStatus.新建;
receiptHeader.LastStatus = ReceiptHeaderStatus.新建;
receiptHeader.TotalLines = 0;
receiptHeader.TotalQty = 0;
}
if (receiptHeader.Id == null)
{
_apprh.Add(receiptHeader);
}
//else
//{
// _apprh.UpdateByTracking(receiptHeader);
//}
#endregion
#region 保存入库单子表
//ReceiptDetail receiptDetail = _context.Set<ReceiptDetail>().AsQueryable().Where(u => u.SourceCode.Equals(SourceCode) && u.MaterialCode.Equals(MaterialCode)).SingleOrDefault();
//if (receiptDetail == null)
//{
ReceiptDetail receiptDetail = new ReceiptDetail();
//}
receiptDetail.SourceCode = UpperTaskNo + "&" + SourceCode;
receiptDetail.Station = "";
receiptDetail.MaterialCode = MaterialCode;
//receiptDetail.Lot = item.Lot;
//receiptDetail.InventoryStatus = item.InventoryStatus;
receiptDetail.Qty = Num;
receiptDetail.CreateTime = receiptHeader.CreateTime;
receiptDetail.CreateBy = receiptHeader.CreateBy;
//receiptDetail.UpdateTime = item.UpdateTime;
//receiptDetail.UpdateBy = item.UpdateBy;
receiptDetail.ReceiptId = receiptHeader.Id;
receiptDetail.ReceiptCode = receiptHeader.Code;
receiptDetail.QtyDivided = 0;
receiptDetail.QtyCompleted = 0;
receiptDetail.Price = 0;
receiptDetail.Project = Code;
receiptDetail.Status = ReceiptHeaderStatus.新建;
//if (receiptDetail.Id == null)
//{
_apprd.Add(receiptDetail);
//string sql2 = "INSERT INTO dbo.receipt_detail (sourceCode,station,materialCode,qty,qtyDivided,qtyCompleted,price,project,status) VALUES ('"+ SourceCode + "','"+"Station1"+"', '" + MaterialCode + "','" + Num + "','" + 0 + "','" + 0 + "','" + 0 + "', '" + Code + "', '" + ReceiptHeaderStatus.新建 + "')";
//_unitWork.ExecuteSql(sql2);
//}
//else
//{
// _apprd.UpdateByTracking(receiptDetail);
//}
#endregion
#region 更新入库单主表汇总信息
receiptHeader.TotalLines += 1;
receiptHeader.TotalQty += receiptDetail.Qty;
if (receiptHeader.UpdateBy == null)
{
receiptHeader.UpdateBy = "wms";
receiptHeader.UpdateTime = DateTime.Now;
}
_apprh.UpdateByTracking(receiptHeader);
inter.AllNum += 1;
#endregion
}
inter.Status = 0;
inter.ComNum = 0;
inter.TaskNo = UpperTaskNo +"&"+ SourceCode;
inter.Type = "LK_In";
inter.Request = Request;
inter.CreateTime = DateTime.Now;
inter.CreateBy = "WMS";
_unitWork.Add(inter);
element.SetAttribute("code", "0");
}
catch(Exception ex)
{
element.SetAttribute("code", "1");
element.SetAttribute("description", ex.Message);
}
return reDoc.InnerXml;
}
//出库
public string LK_Out(string Request)
{
XmlDocument doc = new XmlDocument();
ConfigXmlDocument reDoc = new ConfigXmlDocument();
//读取传入的xml
var config = AppSettingsJson.GetAppSettings();
reDoc.Load(config.GetSection("NouYaWebInService:Url").Value);
//取出报文接收状态字段
XmlElement element = (XmlElement)reDoc.SelectSingleNode("//Status");
try
{
//InterfaceLog inter = new InterfaceLog
//{
// Initiator = "ERP",
// recipient = "WMS",
// Request = Request,
// Method = "LK_Out",
// CreateTime = DateTime.Now,
// CreateBy = "WMS"
//};
//_unitWork.Add(inter);
doc.LoadXml(Request);
string name = "";
string value = "";
string SourceCode = "";
string UpperTaskNo = "";
string MaterialCode = "";
string shipTo = "";
string Station = "";
decimal Num = 0;
string WareCell = "";
string Location ="";
XmlNodeList RecordSets = doc.SelectNodes("//Record");
foreach (XmlNode RecordSet in RecordSets)
{
XmlNodeList nodes = RecordSet.ChildNodes;
foreach (XmlElement node in nodes)
{
//抓取单个的xml节点
//获得字节里面的属性值
name = node.GetAttribute("name");
value = node.GetAttribute("value");
//上游系统单号
if (name == "tc_dcf000" && !string.IsNullOrEmpty(value))
{
UpperTaskNo = value;
}
else if (name == "tc_dfa003" && !string.IsNullOrEmpty(value))
{
SourceCode = value;
}
//客户
else if (name == "tc_dfa004" && !string.IsNullOrEmpty(value))
{
shipTo = value;
}
//物料号
else if (name == "tc_dfa023" && !string.IsNullOrEmpty(value))
{
MaterialCode = value;
}
//出库数量
else if (name == "tc_dfa025" && !string.IsNullOrEmpty(value))
{
Num = decimal.Parse(value);
}
//仓库
else if (name == "tc_dfa027" && !string.IsNullOrEmpty(value))
{
WareCell = value;
}
//站台
else if (name == "tc_dfa030" && !string.IsNullOrEmpty(value))
{
Station = value;
}
//库位
else if (name == "tc_dfa037" && !string.IsNullOrEmpty(value))
{
Location = value;
}
}
#region 保存出库单主表
ShipmentHeader shipmentheader = _unitWork.FindSingle<ShipmentHeader>(u => u.SourceCode.Equals(SourceCode) && u.Station == Station);
if (shipmentheader != null)
{
if (shipmentheader.FirstStatus != ReceiptHeaderStatus.新建)
{
throw new Exception("单据进入订单池后,不允许修改!");
}
}
else
{
shipmentheader = new ShipmentHeader
{
Type = BusinessType.出库_其他出库单,
SourceCode = UpperTaskNo + "&" + SourceCode,
Station = Station,
WarehouseType = WareCell,
UploadStatus = 0,
ShipTo = shipTo,
Code = _unitWork.GetTaskNo(TaskNo.出库手动分配),
FirstStatus = ReceiptHeaderStatus.新建,
LastStatus = ReceiptHeaderStatus.新建,
TotalLines = 0,
TotalQty = 0,
CreateBy = "WMS",
CreateTime = DateTime.Now
};
_unitWork.Add(shipmentheader);
}
#endregion
#region 保存出库单子表
ShipmentDetail shipmentDetail = new ShipmentDetail
{
SourceCode = UpperTaskNo + "&" + SourceCode,
MaterialCode = MaterialCode,
InventoryStatus = "",
Qty = Num,
CreateTime = shipmentheader.CreateTime,
CreateBy = shipmentheader.CreateBy,
ShipmentId = shipmentheader.Id,
ShipmentCode = shipmentheader.Code,
QtyDivided = 0,
QtyCompleted = 0,
Price = 0,
Status = ReceiptHeaderStatus.新建
};
_unitWork.Add(shipmentDetail);
#endregion
}
InterfaceLog inter = new InterfaceLog
{
Type = "LK_Out",
AllNum = RecordSets.Count,
ComNum = 0,
Request = Request,
Status = 0,
TaskNo = UpperTaskNo + "&" + SourceCode,
CreateTime = DateTime.Now,
CreateBy = "WMS"
};
_unitWork.Add(inter);
element.SetAttribute("code", "0");
}
catch (Exception ex)
{
element.SetAttribute("code", "1");
element.SetAttribute("description", ex.Message);
}
return reDoc.InnerXml;
}
//RGV移动
public string LK_RgvMove(string Request)
{
ConfigXmlDocument doc = new ConfigXmlDocument();
ConfigXmlDocument reDoc = new ConfigXmlDocument();
//读取传入的xml
var config = AppSettingsJson.GetAppSettings();
reDoc.Load(config.GetSection("NouYaWebInService:Url").Value);
//填入是否报错
XmlElement element = (XmlElement)doc.SelectSingleNode("//Status");
try
{
doc.LoadXml(Request);
XmlNodeList nodes = doc.SelectNodes("//Field");
foreach (XmlElement node in nodes)
{
//抓取单个的xml节点
//获得字节里面的属性值
string name = node.GetAttribute("name");
string value = node.GetAttribute("value");
}
element.SetAttribute("code", "0");
}
catch (Exception ex)
{
element.SetAttribute("code", "1");
element.SetAttribute("description", ex.Message);
}
return reDoc.InnerText;
}
public ReceiptResponse ReceiptService(MaterialsInformation[] materials)
{
ReceiptResponse receiptResponse = new ReceiptResponse();
try
{
receiptResponse.Code = 200;
receiptResponse.materials = materials;
receiptResponse.Message = "success";
}
catch (Exception ex)
{
receiptResponse.Code = 300;
receiptResponse.Message = ex.Message;
}
return receiptResponse;
}
}
}