InterfaceLogAction.cs
11 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Xml;
using Infrastructure;
using Quartz;
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));
try
{
List<InterfaceLog> interfaceLogs = _unitWork.Find<InterfaceLog>(n => n.AllNum == n.ComNum && n.AllNum != 0 && n.Status == 0).ToList();
foreach (InterfaceLog interfaceLog in interfaceLogs)
{
if (interfaceLog.Type == "LK_In")
{
string name = "";
string value = "";
XmlDocument doc = new XmlDocument();
doc.LoadXml(interfaceLog.Request);
XmlNodeList nodes = doc.SelectNodes("Request/RequestContent/Document/RecordSet/Master/Record/Field[@name='tc_dcf025']");
foreach (XmlNode node in nodes)
{
value = node.Attributes["value"].Value;
Inventory inventory = _unitWork.Find<Inventory>(n => n.SourceCode == interfaceLog.TaskNo && n.QrCode == value).FirstOrDefault();
if (inventory != null)
{
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");
}
else if (nodeEle.GetAttribute("name") == "tc_dcf024")
{
nodeEle.SetAttribute("value", "");
}
else if (nodeEle.GetAttribute("name") == "tc_dcf031")
{
nodeEle.SetAttribute("value", inventory.LocationCode);
}
}
ReceiptDetail receiptDetail = _unitWork.Find<ReceiptDetail>(n => n.SourceCode == interfaceLog.TaskNo && n.Project == inventory.QrCode).FirstOrDefault();
if (receiptDetail != null)
{
receiptDetail.Status = ReceiptHeaderStatus.回传;
receiptDetail.UpdateBy = "wms";
receiptDetail.UpdateTime = DateTime.Now;
_unitWork.Update(receiptDetail);
}
}
}
string response = doc.InnerXml;
interfaceLog.Status = 1;
_unitWork.Update(interfaceLog);
//更新主出库单头尾状态
ReceiptHeader receiptHeader = _unitWork.Find<ReceiptHeader>(u => u.Code == interfaceLog.TaskNo).FirstOrDefault();
ReceiptDetail receiptDetail1 = _unitWork.Find<ReceiptDetail>(u => u.ReceiptCode == 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.UpdateBy = "wms";
receiptHeader.UpdateTime = DateTime.Now;
_unitWork.Update(receiptHeader);
//已完成的出库单据迁移至历史出库单据,暂以过账状态,后期与ERP对接后以回传状态
if (receiptHeader.LastStatus == ReceiptHeaderStatus.回传)
{
ReceiptHeaderHistory receiptHeaderHistory = new ReceiptHeaderHistory();
receiptHeader.CopyTo(receiptHeaderHistory);
receiptHeaderHistory.Id = null;
_unitWork.Add(receiptHeaderHistory);
List<ReceiptDetail> receiptDetail1s = _unitWork.Find<ReceiptDetail>(u => u.ReceiptCode == interfaceLog.TaskNo).ToList();
// List<ShipmentDetail> shipdtls = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == shipmentHeader.Code).ToList();
foreach (ReceiptDetail rd in receiptDetail1s)
{
ReceiptDetailHistory receiptDetailHistory = new ReceiptDetailHistory();
rd.CopyTo(receiptDetailHistory);
receiptDetailHistory.Id = null;
receiptDetailHistory.ReceiptId = receiptDetailHistory.Id;
_unitWork.Add(receiptDetailHistory);
_unitWork.Delete(rd);
}
_unitWork.Delete(receiptHeader);
}
}
if (interfaceLog.Type == "LK_Out")
{
string name = "";
string value = "";
XmlDocument doc = new XmlDocument();
doc.LoadXml(interfaceLog.Request);
List<ShipmentDetail> shipmentDetails = _unitWork.Find<ShipmentDetail>(n => n.SourceCode == interfaceLog.TaskNo).ToList();
foreach (ShipmentDetail sd in shipmentDetails)
{
string str = string.Format("Request/RequestContent/Document/RecordSet/Master/Record/Field[@value='{0}']", sd.MaterialCode);
XmlNode node = doc.SelectSingleNode(str);
XmlNodeList nodes_1 = node.SelectSingleNode("parent::*").ChildNodes;
foreach (XmlElement nodeEle in nodes_1)
{
if (nodeEle.GetAttribute("name") == "tc_dfa026")
{
nodeEle.SetAttribute("value", sd.QtyDivided.ToString());
}
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_dfa038")
{
nodeEle.SetAttribute("value", "");
}
}
sd.Status = ShipmentHeaderStatus.回传;
sd.UpdateBy = "wms";
sd.UpdateTime = DateTime.Now;
_unitWork.Update(sd);
}
string response = doc.InnerXml;
interfaceLog.Status = 1;
_unitWork.Update(interfaceLog);
//更新主出库单头尾状态
ShipmentHeader shipmentHeader = _unitWork.Find<ShipmentHeader>(u => u.Code == interfaceLog.TaskNo).FirstOrDefault();
ShipmentDetail shipmentDetail = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == interfaceLog.TaskNo).OrderBy(a => a.Status).FirstOrDefault();
if (shipmentHeader.FirstStatus < shipmentDetail.Status)
{
shipmentHeader.FirstStatus = shipmentDetail.Status;
}
if (shipmentHeader.LastStatus < shipmentDetail.Status)
{
shipmentHeader.LastStatus = shipmentDetail.Status;
}
shipmentHeader.UpdateBy = "wms";
shipmentHeader.UpdateTime = DateTime.Now;
_unitWork.Update(shipmentHeader);
//已完成的出库单据迁移至历史出库单据,暂以过账状态,后期与ERP对接后以回传状态
if (shipmentHeader.LastStatus == ShipmentHeaderStatus.回传)
{
ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();
shipmentHeader.CopyTo(shipmentHeaderHistory);
shipmentHeaderHistory.Id = null;
_unitWork.Add(shipmentHeaderHistory);
List<ShipmentDetail> shipdtls = _unitWork.Find<ShipmentDetail>(u => u.ShipmentCode == shipmentHeader.Code).ToList();
foreach (ShipmentDetail sd in shipdtls)
{
ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
sd.CopyTo(shipmentDetailHistory);
shipmentDetailHistory.Id = null;
shipmentDetailHistory.ShipmentId = shipmentHeaderHistory.Id;
_unitWork.Add(shipmentDetailHistory);
_unitWork.Delete(sd);
}
_unitWork.Delete(shipmentHeader);
}
}
}
}
catch (Exception ex)
{
jobContainer.ExceptionInfo = ex.Message;
}
}
}
}