InterfaceLogAction.cs
18.1 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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Xml;
using Infrastructure;
using Quartz;
using ServiceReference3;
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) || (n.ComNum > 0 && n.AllNum > 0 && n.Status == 2 && n.Type == "LK_In")).ToList();
foreach (InterfaceLog interfaceLog in interfaceLogs)
{
if (interfaceLog.Type == "LK_In")
{
string name = "";
string value = "";
string Location = "";
string WareCell = "";
XmlDocument doc = new XmlDocument();
ConfigXmlDocument Config = new ConfigXmlDocument();
doc.LoadXml(interfaceLog.Request);
TIPTOPServiceGateWayPortTypeClient InBack = new TIPTOPServiceGateWayPortTypeClient();
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)
{
if (inventory.Status != "good")
{
}
if (inventory.WarehouseType == "YCL_WareCell")
{
Location = "B1032";
WareCell = "B0030";
}
else if(inventory.WarehouseType == "PPJ_WareCell")
{
Location = "B1011";
WareCell = "B0030";
}
else if (inventory.WarehouseType == "PPP_WareCell")
{
Location = "B1020";
WareCell = "B0030";
}
else if (inventory.WarehouseType == "TB_WareCell")
{
Location = "B1031";
WareCell = "B0030";
}
else if (inventory.WarehouseType == "CP_WareCell")
{
Location = "B1010";
WareCell = "B0030";
}
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_dcf029")
{
nodeEle.SetAttribute("value", Location);
}
//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 && n.Status == ReceiptHeaderStatus.过账).FirstOrDefault();
if (receiptDetail != null)
{
receiptDetail.Status = ReceiptHeaderStatus.回传;
receiptDetail.UpdateBy = "wms";
receiptDetail.UpdateTime = DateTime.Now;
_unitWork.Update(receiptDetail);
}
}
else
{
XmlNodeList nodes_1 = node.SelectSingleNode("parent::*").ChildNodes;
foreach (XmlElement nodeEle in nodes_1)
{
if (nodeEle.GetAttribute("name") == "tc_dcf022")
{
nodeEle.SetAttribute("value", "0");
}
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_dcf029")
//{
// nodeEle.SetAttribute("value", Location);
//}
}
}
}
//调用方法
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");
//回传状态成功
if (code == "0")
{
if (interfaceLog.Status == 0)
{
interfaceLog.Status = 1;
}
else if (interfaceLog.Status == 2)
{
interfaceLog.Status = 0;
interfaceLog.Message = "已部分回传:" + 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.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.SourceCode == interfaceLog.TaskNo).ToList();
foreach (ReceiptDetail rd in receiptDetail1s)
{
ReceiptDetailHistory receiptDetailHistory = new ReceiptDetailHistory();
rd.CopyTo(receiptDetailHistory);
receiptDetailHistory.Id = null;
receiptDetailHistory.ReceiptId = receiptHeader.Id;
_unitWork.Add(receiptDetailHistory);
_unitWork.Delete(rd);
}
_unitWork.Delete(receiptHeader);
}
}
else
{
interfaceLog.Message = msg + DateTime.Now;
_unitWork.Update(interfaceLog);
}
}
if (interfaceLog.Type == "LK_Out")
{
string name = "";
string value = "";
XmlDocument doc = new XmlDocument();
doc.LoadXml(interfaceLog.Request);
XmlDocument doc_copy = new XmlDocument();
ConfigXmlDocument Config = new ConfigXmlDocument();
TIPTOPServiceGateWayPortTypeClient OutBack = new TIPTOPServiceGateWayPortTypeClient();
XmlElement xmlElement_Document = doc_copy.CreateElement("Document");
doc_copy.AppendChild(xmlElement_Document);
List<ShipmentDetail> shipmentDetails = _unitWork.Find<ShipmentDetail>(n => n.SourceCode == interfaceLog.TaskNo && n.Status == ShipmentHeaderStatus.过账).ToList();
int i = 1;
foreach (ShipmentDetail sd in shipmentDetails)
{
List<InventoryOut> list = _unitWork.Find<InventoryOut>(n => n.SourceCode == sd.SourceCode && n.ShipmentState == 1).ToList();
foreach (InventoryOut inv in list)
{
XmlElement xmlElement_RecordSet = doc_copy.CreateElement("RecordSet");
string str = string.Format("Request/RequestContent/Document/RecordSet/Master/Record/Field[@value='{0}']", sd.SourceCode.Split("%")[0]);
XmlNode node = doc.SelectSingleNode(str);
xmlElement_RecordSet.InnerXml = node.SelectSingleNode("parent::*").InnerXml;
xmlElement_RecordSet.SetAttribute("id", i++.ToString());
XmlNodeList nodes = xmlElement_RecordSet.SelectNodes("//Field");
foreach (XmlElement nodeEle in nodes)
{
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", "");
}
}
doc_copy.SelectSingleNode("//Document").AppendChild(xmlElement_RecordSet);
inv.ShipmentState = 2;
_unitWork.Update(inv);
}
sd.Status = ShipmentHeaderStatus.回传;
sd.UpdateBy = "wms";
sd.UpdateTime = DateTime.Now;
_unitWork.Update(sd);
}
doc.SelectSingleNode("//RequestContent").RemoveAll();
doc.SelectSingleNode("//RequestContent").InnerXml = doc_copy.InnerXml;
//string response = doc.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 = "1";
string msg = "";
if (code == "1")
{
interfaceLog.Status = 1;
_unitWork.Update(interfaceLog);
//更新主出库单头尾状态
ShipmentHeader shipmentHeader = _unitWork.Find<ShipmentHeader>(u => u.SourceCode == interfaceLog.TaskNo).FirstOrDefault();
ShipmentDetail shipmentDetail = _unitWork.Find<ShipmentDetail>(u => u.SourceCode == 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 = shipmentHeader.Id;
_unitWork.Add(shipmentDetailHistory);
_unitWork.Delete(sd);
}
_unitWork.Delete(shipmentHeader);
}
}
else
{
interfaceLog.Message = msg + DateTime.Now;
_unitWork.Update(interfaceLog);
}
}
}
}
catch (Exception ex)
{
jobContainer.ExceptionInfo = ex.Message;
}
}
}
}