InterfaceLogAction.cs
48.2 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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Xml;
using Infrastructure;
using Quartz;
using ServiceReference4;
using ServiceReference5;
using ServiceReference6;
using WebApp;
using WebRepository;
namespace WebMvc
{
/// <summary>
/// 接口回传
/// </summary>
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public class InterfaceLogAction
{
private string ConnString { set; get; }
IJobExecutionContext Context { set; get; }
public InterfaceLogAction(string _ConnString, IJobExecutionContext _Context)
{
ConnString = _ConnString;
Context = _Context;
}
public void Execute(JobContainer jobContainer)
{
UnitWork _unitWork = new UnitWork(AppSettingsJson.JobContext(ConnString));
var SourceCode = "";
try
{
List<InterfaceLog> interfaceLogs = _unitWork.Find<InterfaceLog>(n => (n.AllNum == n.ComNum && n.AllNum > 0 && n.Status == 0) || (n.ComNum > 0 && n.AllNum > 0 && n.Status == 2 && n.Type == "LK_In") || (n.Type == "GoodBack" && n.Status == 3) || (n.ComNum > 0 && n.AllNum != 0 && n.Type == "LK_Out" && n.Status == 0)).ToList();
foreach (InterfaceLog interfaceLog in interfaceLogs)
{
SourceCode = interfaceLog.TaskNo;
//入库回传
if (interfaceLog.Type == "LK_In")
{
string name = "";
string value = "";
string Location = "";
string WareCell = "";
//不良品回传 XmlDocument创建
int i_doc_isgood = 0;
XmlDocument doc_isgood = new XmlDocument();
//建立中转的XmlDocument(要以模板创建新的xml进行回传)
XmlDocument doc_isgood_copy = new XmlDocument();
var config = AppSettingsJson.GetAppSettings();
//获取不良品回传xml模板
doc_isgood.Load(config.GetSection("NouYaWebRGVService:Url").Value);
//添加字节<Document>
XmlElement xmlElement_Document = doc_isgood_copy.CreateElement("Document");
doc_isgood_copy.AppendChild(xmlElement_Document);
ConfigXmlDocument Config1 = new ConfigXmlDocument();
//入库完成接口回传XmlDocument创建
XmlDocument doc = new XmlDocument();
ConfigXmlDocument Config = new ConfigXmlDocument();
//获取日志记录的模板历史
doc.LoadXml(interfaceLog.Request);
//创建webservice回传接口实例
ServiceReference6.TIPTOPServiceGateWayPortTypeClient InBack = new ServiceReference6.TIPTOPServiceGateWayPortTypeClient();
//xml数据解析
XmlNodeList nodes = doc.SelectNodes("Request/RequestContent/Document/RecordSet/Master/Record/Field[@name='tc_dcf025']");
foreach (XmlNode node in nodes)
{
value = node.Attributes["value"].Value;
var locnode = "";
XmlNodeList locNodes = doc.SelectNodes("Request/RequestContent/Document/RecordSet/Master/Record/Field[@name='tc_dcf028']");
foreach (XmlNode locNode in locNodes)
{
locnode = locNode.Attributes["value"].Value;
}
Inventory inventory = _unitWork.Find<Inventory>(n => n.SourceCode == interfaceLog.TaskNo && n.QrCode == value).FirstOrDefault();
if (inventory != null)
{
WareCell = inventory.ErpWareCell;
Location = inventory.SpecialWarehouse;
//不良品回传
if (inventory.Status == "scrap")
{
XmlElement xmlElement_RecordSet = doc_isgood_copy.CreateElement("RecordSet");
xmlElement_RecordSet.SetAttribute("id", (++i_doc_isgood).ToString());
XmlNode node_RecordSet = doc_isgood_copy.SelectSingleNode("//Document").AppendChild(xmlElement_RecordSet);
XmlElement xmlElement_Master = doc_isgood_copy.CreateElement("Master");
xmlElement_Master.SetAttribute("name", "Master");
XmlNode node_Master = node_RecordSet.AppendChild(xmlElement_Master);
XmlElement xmlElement_Record = doc_isgood_copy.CreateElement("Record");
XmlNode node_Record = node_Master.AppendChild(xmlElement_Record);
XmlNode node_isgood = doc_isgood.SelectSingleNode(string.Format("Request/RequestContent/Document/RecordSet/Master/Record"));
node_Record.InnerXml = node_isgood.InnerXml;
XmlNodeList nodes_isgood = node_Record.ChildNodes;
foreach (XmlElement nodeEle in nodes_isgood)
{
//流水号
if (nodeEle.GetAttribute("name") == "imn00")
{
nodeEle.SetAttribute("value", i_doc_isgood.ToString());
}
//项次
else if (nodeEle.GetAttribute("name") == "imn01")
{
nodeEle.SetAttribute("value", inventory.SourceCode);
}
else if (nodeEle.GetAttribute("name") == "imn03")
{
nodeEle.SetAttribute("value", inventory.MaterialCode);
}
else if (nodeEle.GetAttribute("name") == "imn04")
{
nodeEle.SetAttribute("value", Location);
}
else if (nodeEle.GetAttribute("name") == "imn05")
{
nodeEle.SetAttribute("value", "C00");
}
else if (nodeEle.GetAttribute("name") == "imn10")
{
nodeEle.SetAttribute("value", inventory.Qty.ToString());
}
else if (nodeEle.GetAttribute("name") == "imn15")
{
nodeEle.SetAttribute("value", Location);
}
else if (nodeEle.GetAttribute("name") == "barcode_out")
{
nodeEle.SetAttribute("value", inventory.QrCode);
}
else if (nodeEle.GetAttribute("name") == "barcode_in")
{
nodeEle.SetAttribute("value", inventory.QrCode);
}
else if (nodeEle.GetAttribute("name") == "imn16")
{
nodeEle.SetAttribute("value", "C01");
}
else if (nodeEle.GetAttribute("name") == "imn20")
{
nodeEle.SetAttribute("value", inventory.Qty.ToString());
}
}
}
//入库回传
XmlNodeList nodes_1 = node.SelectSingleNode("parent::*").ChildNodes;
foreach (XmlElement nodeEle in nodes_1)
{
if (nodeEle.GetAttribute("name") == "tc_dcf022")
{
nodeEle.SetAttribute("value", inventory.Qty.ToString());
}
else if (nodeEle.GetAttribute("name") == "tc_dcf023")
{
nodeEle.SetAttribute("value", "1");
}
//if (nodeEle.GetAttribute("name") == "tc_dcf024")
//{
// nodeEle.SetAttribute("value", "测试回传");
//}
//仓库
else if (nodeEle.GetAttribute("name") == "tc_dcf029")
{
nodeEle.SetAttribute("value", Location);
}
//良品与不良品
else if (nodeEle.GetAttribute("name") == "tc_dcf031")
{
nodeEle.SetAttribute("value", WareCell);
}
}
ReceiptDetail receiptDetail = _unitWork.Find<ReceiptDetail>(n => n.SourceCode == interfaceLog.TaskNo && n.Project == inventory.QrCode && n.Status == ReceiptHeaderStatus.过账).FirstOrDefault();
if (receiptDetail != null)
{
receiptDetail.Status = ReceiptHeaderStatus.回传;
receiptDetail.UpdateBy = "wms";
receiptDetail.UpdateTime = DateTime.Now;
_unitWork.Update(receiptDetail);
}
}
else
{
interfaceLog.Message = "未找到该单据的库存数据";
_unitWork.Update(interfaceLog);
}
}
//调用方法
var response = InBack.intostore_post(doc.InnerXml);
//处理调用后回传数据
Config.LoadXml(response);
XmlElement element = (XmlElement)Config.SelectSingleNode("//Status");
string code = element.GetAttribute("code");
string msg = element.GetAttribute("description");
//string code = "0";
//string msg = "";
//回传状态成功
if (code == "0")
{
InterfaceLog Back = new InterfaceLog();
Back.TaskNo = interfaceLog.TaskNo;
Back.Request = doc.InnerXml;
Back.Type = "入库回传";
Back.CreateTime = DateTime.Now;
Back.CreateBy = "WMS";
_unitWork.Add(Back);
//不良品回传
if (i_doc_isgood > 0)
{
doc_isgood.SelectSingleNode("//RequestContent").RemoveAll();
doc_isgood.SelectSingleNode("//RequestContent").InnerXml = doc_isgood_copy.InnerXml;
string s = doc_isgood.InnerXml;
var Dresponse = InBack.wms_aimt324(doc_isgood.InnerXml);
Config1.LoadXml(Dresponse);
XmlElement element1 = (XmlElement)Config1.SelectSingleNode("//Status");
string code1 = element1.GetAttribute("code");
string msg1 = element1.GetAttribute("description");
if (code1 == "0")
{
InterfaceLog GoodBack = new InterfaceLog();
GoodBack.TaskNo = interfaceLog.TaskNo;
GoodBack.Request = doc_isgood.InnerXml;
GoodBack.Type = "GoodBack";
GoodBack.Status = 1;
GoodBack.Message = "不良品回传成功" + DateTime.Now;
GoodBack.CreateTime = DateTime.Now;
GoodBack.CreateBy = "WMS";
_unitWork.Add(GoodBack);
}
else
{
InterfaceLog inter = _unitWork.Find<InterfaceLog>(n => n.TaskNo == interfaceLog.TaskNo && n.Type == "GoodBack").FirstOrDefault();
if (inter != null)
{
inter.Request = doc_isgood.InnerXml;
inter.Status = 4;
inter.Message = "不良品回传失败" + msg1 + DateTime.Now;
inter.UpdateTime = DateTime.Now;
_unitWork.Update(inter);
}
else
{
InterfaceLog GoodBack = new InterfaceLog();
GoodBack.TaskNo = interfaceLog.TaskNo;
GoodBack.Request = doc_isgood.InnerXml;
GoodBack.Type = "GoodBack";
GoodBack.Status = 4;
GoodBack.Message = "不良品回传失败" + code1+":"+ msg1 + DateTime.Now;
GoodBack.CreateTime = DateTime.Now;
GoodBack.CreateBy = "WMS";
_unitWork.Add(GoodBack);
}
}
}
if (interfaceLog.Status == 0)
{
interfaceLog.Status = 1;
interfaceLog.Message = "已全部回传成功:" + DateTime.Now;
interfaceLog.UpdateTime = DateTime.Now;
}
else if (interfaceLog.Status == 2)
{
interfaceLog.Status = 0;
interfaceLog.Message = "已部分回传成功:" + DateTime.Now;
interfaceLog.UpdateTime = DateTime.Now;
}
_unitWork.Update(interfaceLog);
//更新主入库单头尾状态
ReceiptHeader receiptHeader = _unitWork.Find<ReceiptHeader>(u => u.SourceCode == interfaceLog.TaskNo).FirstOrDefault();
ReceiptDetail receiptDetail1 = _unitWork.Find<ReceiptDetail>(u => u.SourceCode == interfaceLog.TaskNo).OrderBy(a => a.Status).FirstOrDefault();
if (receiptHeader.FirstStatus < receiptDetail1.Status)
{
receiptHeader.FirstStatus = receiptDetail1.Status;
}
if (receiptHeader.LastStatus < receiptDetail1.Status)
{
receiptHeader.LastStatus = receiptDetail1.Status;
}
receiptHeader.UpdateTime = DateTime.Now;
_unitWork.Update(receiptHeader);
//已完成的入库单据迁移至历史出库单据,暂以过账状态,后期与ERP对接后以回传状态
if (receiptHeader.LastStatus == ReceiptHeaderStatus.回传)
{
ReceiptHeaderHistory receiptHeaderHistory = new ReceiptHeaderHistory();
receiptHeader.CopyTo(receiptHeaderHistory);
receiptHeaderHistory.Id = null;
receiptHeaderHistory.UpdateBy = "InterfaceLogAction";
_unitWork.Add(receiptHeaderHistory);
List<ReceiptDetail> receiptDetail1s = _unitWork.Find<ReceiptDetail>(u => u.SourceCode == interfaceLog.TaskNo).ToList();
foreach (ReceiptDetail rd in receiptDetail1s)
{
ReceiptDetailHistory receiptDetailHistory = new ReceiptDetailHistory();
rd.CopyTo(receiptDetailHistory);
receiptDetailHistory.Id = null;
receiptDetailHistory.ReceiptId = receiptHeaderHistory.Id;
receiptDetailHistory.UpdateBy = "InterfaceLogAction";
_unitWork.Add(receiptDetailHistory);
_unitWork.Delete(rd);
}
_unitWork.Delete(receiptHeader);
}
}
else
{
InterfaceLog error11 = new InterfaceLog();
error11.TaskNo = interfaceLog.TaskNo;
error11.Request = doc.InnerXml;
error11.Type = "入库回传报错";
error11.Status = 4;
error11.Message = code + DateTime.Now;
error11.CreateTime = DateTime.Now;
_unitWork.Add(error11);
interfaceLog.Status = 4;
interfaceLog.Message = msg + DateTime.Now;
interfaceLog.UpdateTime = DateTime.Now;
_unitWork.Update(interfaceLog);
}
}
//出库回传
if (interfaceLog.Type == "LK_Out")
{
string name = "";
string value = "";
string Ware = "";
string Sta = "";
string Statuse = "2";
List<ShipmentDetail> shipmentDetails = _unitWork.Find<ShipmentDetail>(n => n.SourceCode == interfaceLog.TaskNo && n.Status == ShipmentHeaderStatus.过账).ToList();
if (shipmentDetails.Count() < 1)
{
continue;
}
//每个任务明细都建立一个回传单据
foreach (ShipmentDetail shipmentDetail in shipmentDetails)
{
//建立回传 XmlDocument
XmlDocument doc = new XmlDocument();
//加载模板
doc.LoadXml(interfaceLog.Request);
//建立中转的XmlDocument(要以模板创建新的xml进行回传)
XmlDocument doc_copy = new XmlDocument();
ConfigXmlDocument Config = new ConfigXmlDocument();
ServiceReference6.TIPTOPServiceGateWayPortTypeClient OutBack = new ServiceReference6.TIPTOPServiceGateWayPortTypeClient();
XmlElement xmlElement_Document = doc_copy.CreateElement("Document");
doc_copy.AppendChild(xmlElement_Document);
int i = 1;
List<InventoryOut> list = new List<InventoryOut>();
List<ShipmentDetail> IsshipmentDetails = new List<ShipmentDetail>();
//剩余过账的出库明细
IsshipmentDetails = _unitWork.Find<ShipmentDetail>(n => n.SourceCode == interfaceLog.TaskNo && n.Status <= ShipmentHeaderStatus.过账 && n.Id != shipmentDetail.Id).ToList();
if (IsshipmentDetails.Count() > 0)
{
Statuse = "1";
}
else
{
Statuse = "2";
}
list = _unitWork.Find<InventoryOut>(n => n.SourceCode == interfaceLog.TaskNo && n.ShipmentState == 1 && n.ReceiptDetailId == shipmentDetail.Id && n.ReceiptCode == shipmentDetail.ShipmentCode).ToList();
if (list.Count() < 1)
{
continue;
}
else
{
foreach (InventoryOut inv in list)
{
//仓库与库位转换
ShipmentHeader shph = _unitWork.Find<ShipmentHeader>(n => n.SourceCode == interfaceLog.TaskNo).FirstOrDefault();
if (shph != null)
{
Ware = shph.WarehouseType;
if (inv.Status == "scrap")
{
Sta = "C01";
}
else if (inv.Status == "good")
{
Sta = "C00";
}
if (Ware == "PJ_WareCell")
{
Ware = "C1011";
//if (inv.Status == "scrap")
//{
// Sta = "B01";
//}
//else if (inv.Status == "good")
//{
// Sta = "B00";
//}
////打包
//else if (inv.IsPack == "Ispack")
//{
// Sta = "Z01";
//}
}
else if (Ware == "PP_WareCell")
{
Ware = "C1020";
//if (inv.Status == "scrap")
//{
// Sta = "B01";
//}
//else if (inv.Status == "good")
//{
// Sta = "B00";
//}
////排版
//else if (inv.IsFold == "Isflod")
//{
// Sta = "P01";
//}
}
else if (Ware == "TB_WareCell")
{
Ware = "C1031";
//if (inv.Status == "scrap")
//{
// Sta = "B01";
//}
//else if (inv.Status == "good")
//{
// Sta = "B00";
//}
}
}
//创建xml数据
XmlElement xmlElement_RecordSet = doc_copy.CreateElement("RecordSet");
xmlElement_RecordSet.SetAttribute("id", (i++).ToString());
XmlNode node_RecordSet = doc_copy.SelectSingleNode("//Document").AppendChild(xmlElement_RecordSet);
XmlElement xmlElement_Master = doc_copy.CreateElement("Master");
xmlElement_Master.SetAttribute("name", "Master");
XmlNode node_Master = node_RecordSet.AppendChild(xmlElement_Master);
XmlElement xmlElement_Record = doc_copy.CreateElement("Record");
XmlNode node_Record = node_Master.AppendChild(xmlElement_Record);
XmlNode node = doc.SelectSingleNode(string.Format("Request/RequestContent/Document/RecordSet/Master/Record"));
node_Record.InnerXml = node.InnerXml;
XmlNodeList nodes = node_Record.ChildNodes;
foreach (XmlElement nodeEle in nodes)
{
//任务完成状态
if (nodeEle.GetAttribute("name") == "tc_dfa002")
{
nodeEle.SetAttribute("value", Statuse);
}
//任务号
else if (nodeEle.GetAttribute("name") == "tc_dfa000")
{
nodeEle.SetAttribute("value", shipmentDetail.ShipmentCode + "%" + shipmentDetail.Id);
}
else if (nodeEle.GetAttribute("name") == "tc_dfa023")
{
nodeEle.SetAttribute("value", inv.MaterialCode);
}
else if (nodeEle.GetAttribute("name") == "tc_dfa026")
{
nodeEle.SetAttribute("value", inv.Qty.ToString());
}
else if (nodeEle.GetAttribute("name") == "tc_dfa027")
{
nodeEle.SetAttribute("value", Ware);
}
else if (nodeEle.GetAttribute("name") == "tc_dfa031")
{
nodeEle.SetAttribute("value", "1");
}
else if (nodeEle.GetAttribute("name") == "tc_dfa032")
{
nodeEle.SetAttribute("value", "");
}
else if (nodeEle.GetAttribute("name") == "tc_dfa033")
{
nodeEle.SetAttribute("value", inv.QrCode);
}
//实际仓库
else if (nodeEle.GetAttribute("name") == "tc_dfa036")
{
nodeEle.SetAttribute("value", Ware);
}
else if (nodeEle.GetAttribute("name") == "tc_dfa037")
{
nodeEle.SetAttribute("value", Sta);
}
//实际库位
else if (nodeEle.GetAttribute("name") == "tc_dfa038")
{
nodeEle.SetAttribute("value", Sta);
}
}
//doc_copy.SelectSingleNode("//Master").AppendChild(xmlElement_RecordSet);
}
doc.SelectSingleNode("//RequestContent").RemoveAll();
doc.SelectSingleNode("//RequestContent").InnerXml = doc_copy.InnerXml;
var response = OutBack.outstore_post(doc.InnerXml);
//处理调用后回传数据
Config.LoadXml(response);
XmlElement element = (XmlElement)Config.SelectSingleNode("//Status");
string code = element.GetAttribute("code");
string msg = element.GetAttribute("description");
//string code = "0";
//string msg = "";
if (code == "0")
{
InterfaceLog Back = new InterfaceLog();
if (Statuse == "2")
{
interfaceLog.Status = 1;
Back.Type = "出库全部回传成功";
}
else
{
Back.Type = "出库单笔回传成功";
}
Back.Status = 1;
Back.TaskNo = interfaceLog.TaskNo;
Back.Request = doc.InnerXml;
Back.CreateTime = DateTime.Now;
foreach (InventoryOut inv in list)
{
inv.ShipmentState = 2;
_unitWork.Update(inv);
}
shipmentDetail.Status = ShipmentHeaderStatus.回传;
shipmentDetail.UpdateBy = "wms";
shipmentDetail.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentDetail);
_unitWork.Add(Back);
ShipmentHeader shipmentHeader_2 = new ShipmentHeader();
ShipmentDetail shipmentDetail_2 = new ShipmentDetail();
if (Statuse == "2")
{
shipmentHeader_2 = _unitWork.Find<ShipmentHeader>(u => u.SourceCode == interfaceLog.TaskNo).FirstOrDefault();
shipmentDetail_2 = _unitWork.Find<ShipmentDetail>(u => u.SourceCode == interfaceLog.TaskNo).OrderBy(a => a.Status).FirstOrDefault();
}
else
{
shipmentHeader_2 = _unitWork.Find<ShipmentHeader>(u => u.SourceCode == interfaceLog.TaskNo).FirstOrDefault();
shipmentDetail_2 = _unitWork.Find<ShipmentDetail>(u => u.SourceCode == interfaceLog.TaskNo && u.Id == shipmentDetail.Id).FirstOrDefault();
}
//更新主出库单头尾状态
if (shipmentHeader_2 != null && shipmentDetail_2 != null)
{
if (shipmentHeader_2.FirstStatus < shipmentDetail_2.Status)
{
shipmentHeader_2.FirstStatus = shipmentDetail_2.Status;
}
if (Statuse == "2")
{
if (shipmentHeader_2.LastStatus < shipmentDetail_2.Status)
{
shipmentHeader_2.LastStatus = shipmentDetail_2.Status;
}
}
shipmentHeader_2.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentHeader_2);
//已完成的出库单据迁移至历史出库单据,暂以过账状态,后期与ERP对接后以回传状态
if (shipmentHeader_2.LastStatus == ShipmentHeaderStatus.回传)
{
ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();
shipmentHeader_2.CopyTo(shipmentHeaderHistory);
shipmentHeaderHistory.Id = null;
shipmentHeaderHistory.UpdateBy = "InterfaceLogAction";
_unitWork.Add(shipmentHeaderHistory);
List<ShipmentDetail> shipdtls = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == shipmentHeader_2.Code).ToList();
foreach (ShipmentDetail sd in shipdtls)
{
ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
sd.CopyTo(shipmentDetailHistory);
shipmentDetailHistory.Id = null;
shipmentDetailHistory.ShipmentId = shipmentHeaderHistory.Id;
shipmentDetailHistory.UpdateBy = "InterfaceLogAction";
_unitWork.Add(shipmentDetailHistory);
_unitWork.Delete(sd);
}
_unitWork.Delete(shipmentHeader_2);
}
interfaceLog.Message = "出库已回传完成";
interfaceLog.UpdateTime = DateTime.Now;
_unitWork.Update(interfaceLog);
}
else
{
interfaceLog.Message = "出库主表或明细未找到";
interfaceLog.UpdateTime = DateTime.Now;
_unitWork.Update(interfaceLog);
}
}
else
{
InterfaceLog error11 = new InterfaceLog();
error11.TaskNo = interfaceLog.TaskNo;
error11.Request = doc.InnerXml;
error11.Type = "出库回传失败";
error11.Status = 4;
error11.Message = code;
error11.CreateTime = DateTime.Now;
_unitWork.Add(error11);
interfaceLog.Status = 4;
interfaceLog.Message = "接口报错:" + msg + DateTime.Now;
interfaceLog.UpdateTime = DateTime.Now;
_unitWork.Update(interfaceLog);
}
}
}
}
//不良品回传
if (interfaceLog.Type == "GoodBack")
{
string name = "";
string value = "";
string Location = "";
string WareCell = "";
int i_doc_isgood = 0;
XmlDocument doc_isgood = new XmlDocument();
XmlDocument doc_isgood_copy = new XmlDocument();
var config = AppSettingsJson.GetAppSettings();
doc_isgood.Load(config.GetSection("NouYaWebRGVService:Url").Value);
XmlElement xmlElement_Document = doc_isgood_copy.CreateElement("Document");
doc_isgood_copy.AppendChild(xmlElement_Document);
ConfigXmlDocument Config1 = new ConfigXmlDocument();
ServiceReference6.TIPTOPServiceGateWayPortTypeClient NoGoodBack = new ServiceReference6.TIPTOPServiceGateWayPortTypeClient();
List<Inventory> invs = _unitWork.Find<Inventory>(n => n.SourceCode == interfaceLog.TaskNo).ToList();
if (invs.Count > 0)
{
foreach (var inventory in invs)
{
if (inventory.Status == "scrap")
{
if (inventory.WarehouseType == "PJ_WareCell")
{
Location = "C1011";
WareCell = "C0030";
}
else if (inventory.WarehouseType == "PP_WareCell")
{
Location = "C1020";
WareCell = "C0030";
}
else if (inventory.WarehouseType == "TB_WareCell")
{
Location = "C1031";
WareCell = "C0030";
}
XmlElement xmlElement_RecordSet = doc_isgood_copy.CreateElement("RecordSet");
xmlElement_RecordSet.SetAttribute("id", (++i_doc_isgood).ToString());
XmlNode node_RecordSet = doc_isgood_copy.SelectSingleNode("//Document").AppendChild(xmlElement_RecordSet);
XmlElement xmlElement_Master = doc_isgood_copy.CreateElement("Master");
xmlElement_Master.SetAttribute("name", "Master");
XmlNode node_Master = node_RecordSet.AppendChild(xmlElement_Master);
XmlElement xmlElement_Record = doc_isgood_copy.CreateElement("Record");
XmlNode node_Record = node_Master.AppendChild(xmlElement_Record);
XmlNode node_isgood = doc_isgood.SelectSingleNode(string.Format("Request/RequestContent/Document/RecordSet/Master/Record"));
node_Record.InnerXml = node_isgood.InnerXml;
XmlNodeList nodes_isgood = node_Record.ChildNodes;
foreach (XmlElement nodeEle in nodes_isgood)
{
//流水号
if (nodeEle.GetAttribute("name") == "imn00")
{
nodeEle.SetAttribute("value", i_doc_isgood.ToString());
}
//项次
else if (nodeEle.GetAttribute("name") == "imn01")
{
nodeEle.SetAttribute("value", inventory.SourceCode);
}
else if (nodeEle.GetAttribute("name") == "imn03")
{
nodeEle.SetAttribute("value", inventory.MaterialCode);
}
else if (nodeEle.GetAttribute("name") == "imn04")
{
nodeEle.SetAttribute("value", Location);
}
else if (nodeEle.GetAttribute("name") == "imn05")
{
nodeEle.SetAttribute("value", "C00");
}
else if (nodeEle.GetAttribute("name") == "imn10")
{
nodeEle.SetAttribute("value", inventory.Qty.ToString());
}
else if (nodeEle.GetAttribute("name") == "imn15")
{
nodeEle.SetAttribute("value", Location);
}
else if (nodeEle.GetAttribute("name") == "barcode_out")
{
nodeEle.SetAttribute("value", inventory.QrCode);
}
else if (nodeEle.GetAttribute("name") == "barcode_in")
{
nodeEle.SetAttribute("value", inventory.QrCode);
}
else if (nodeEle.GetAttribute("name") == "imn16")
{
nodeEle.SetAttribute("value", "C01");
}
else if (nodeEle.GetAttribute("name") == "imn22")
{
nodeEle.SetAttribute("value", inventory.Qty.ToString());
}
}
}
}
}
if (i_doc_isgood > 0)
{
doc_isgood.SelectSingleNode("//RequestContent").RemoveAll();
doc_isgood.SelectSingleNode("//RequestContent").InnerXml = doc_isgood_copy.InnerXml;
string s = doc_isgood.InnerXml;
var Dresponse = NoGoodBack.wms_aimt324(doc_isgood.InnerXml);
Config1.LoadXml(Dresponse);
XmlElement element = (XmlElement)Config1.SelectSingleNode("//Status");
string code = element.GetAttribute("code");
string msg = element.GetAttribute("description");
if (code == "0")
{
InterfaceLog GoodBack = new InterfaceLog();
GoodBack.TaskNo = interfaceLog.TaskNo;
GoodBack.Request = doc_isgood.InnerXml;
GoodBack.Type = "GoodBack";
GoodBack.Status = 1;
GoodBack.Message = "不良品回传成功" + DateTime.Now;
_unitWork.Add(GoodBack);
}
else
{
InterfaceLog inter = _unitWork.Find<InterfaceLog>(n => n.TaskNo == interfaceLog.TaskNo && n.Type == "GoodBack").FirstOrDefault();
if (inter != null)
{
inter.Request = doc_isgood.InnerXml;
inter.Status = 4;
inter.Message = "不良品回传失败" + code + "和" + msg + DateTime.Now;
_unitWork.Update(inter);
}
else
{
InterfaceLog GoodBack = new InterfaceLog();
GoodBack.TaskNo = interfaceLog.TaskNo;
GoodBack.Request = doc_isgood.InnerXml;
GoodBack.Type = "GoodBack";
GoodBack.Status = 4;
GoodBack.Message = "不良品回传失败:" + code + "和" + msg + DateTime.Now;
_unitWork.Add(GoodBack);
}
}
}
}
}
}
catch (Exception ex)
{
InterfaceLog error11 = new InterfaceLog();
error11.TaskNo = SourceCode;
error11.Request = "";
error11.Type = "接口回传定时器报错";
error11.Status = 4;
error11.Message = "异常单据号:"+ SourceCode + ",Message:"+ex.Message+",StackTrace:"+ex.StackTrace+ ",Source"+ex.Source+",Data"+ex.Data;
error11.CreateTime = DateTime.Now;
_unitWork.Add(error11);
jobContainer.ExceptionInfo = ex.Message;
}
}
}
}