ERPReceiptAction.cs
14.9 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
using System;
using System.Collections.Generic;
using System.Data;
using Infrastructure;
using Quartz;
using WebApp;
using WebRepository;
using System.Linq;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using System.Xml;
using System.Configuration;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Database;
namespace WebMvc
{
/// <summary>
/// 在入库单据中检索铜箔入库单据,通过铜箔入库单向ERP申请单号,申请成功后为入库单据打上标记
/// </summary>
[PersistJobDataAfterExecution]
[DisallowConcurrentExecution]
public class ERPReceiptAction
{
private string ConnString { set; get; }
IJobExecutionContext Context { set; get; }
public ERPReceiptAction(string _ConnString, IJobExecutionContext _Context)
{
ConnString = _ConnString;
Context = _Context;
}
public void Execute(JobContainer jobContainer)
{
UnitWork _unitWork = new UnitWork(AppSettingsJson.JobContext(ConnString));
string str = "";
try
{
List<ReceiptHeader> ReceiptHeaders = _unitWork.Find<ReceiptHeader>(n => n.Status == 0 && n.Type == "ReturnCopperFoil" ).OrderBy(n => n.CreateTime).ToList();
foreach (ReceiptHeader ReceiptHeader in ReceiptHeaders)
{
//建立回传 XmlDocument
int i_doc_isgood = 0;
XmlDocument doc = new XmlDocument();
var config = AppSettingsJson.GetAppSettings();
//加载模板
doc.Load(config.GetSection("ErpSourceCodeService:Url").Value);
//建立中转的XmlDocument(要以模板创建新的xml进行回传)
XmlDocument doc_isgood_copy = new XmlDocument();
ConfigXmlDocument Config = new ConfigXmlDocument();
ServiceReference9.TIPTOPServiceGateWayPortTypeClient OutBack = new ServiceReference9.TIPTOPServiceGateWayPortTypeClient();
List<ReceiptDetail> receiptDetails = _unitWork.Find<ReceiptDetail>(n => n.SourceCode == ReceiptHeader.SourceCode).ToList();
if (receiptDetails.Count() > 0)
{
//账套
XmlNodeList OrganizationsOut = doc.SelectNodes("//Organization");
foreach (XmlElement OrganizationOut in OrganizationsOut)
{
OrganizationOut.SetAttribute("name", ReceiptHeader.Organization);
}
XmlElement xmlElement_Document = doc_isgood_copy.CreateElement("Document");
doc_isgood_copy.AppendChild(xmlElement_Document);
foreach (var receiptDetail in receiptDetails)
{
//创建RecordSet标签
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_HaerRecord = doc_isgood_copy.CreateElement("Record");
XmlNode node_HaerRecord = node_Master.AppendChild(xmlElement_HaerRecord);
//添加表单
XmlElement xmlElement_Detail = doc_isgood_copy.CreateElement("Detail");
xmlElement_Detail.SetAttribute("name", "report_detail");
node_Master = node_RecordSet.AppendChild(xmlElement_Detail);
XmlElement xmlElement_DeatilRecord = doc_isgood_copy.CreateElement("Record");
XmlNode node_DetailRecord = node_Master.AppendChild(xmlElement_DeatilRecord);
//获取表头数据
XmlNode node_Head = doc.SelectSingleNode(string.Format("Request/RequestContent/Document/RecordSet/Master/Record"));
//获取表单
XmlNode node_Detail = doc.SelectSingleNode(string.Format("Request/RequestContent/Document/RecordSet/Detail/Record"));
node_HaerRecord.InnerXml = node_Head.InnerXml;
node_DetailRecord.InnerXml = node_Detail.InnerXml;
//修改表头内容
XmlNodeList nodes_Hears = node_HaerRecord.ChildNodes;
foreach (XmlElement nodes_Hear in nodes_Hears)
{
//叫料类型
if (nodes_Hear.GetAttribute("name") == "type")
{
nodes_Hear.SetAttribute("value", "1");
}
//MES单号
else if (nodes_Hear.GetAttribute("name") == "wo_no")
{
nodes_Hear.SetAttribute("value", receiptDetail.SourceCode);
}
//调拨单别
else if (nodes_Hear.GetAttribute("name") == "imm01")
{
nodes_Hear.SetAttribute("value", ReceiptHeader.ErpListType);
}
//调拨日期
else if (nodes_Hear.GetAttribute("name") == "imm02")
{
nodes_Hear.SetAttribute("value", DateTime.Now.ToString("d"));
}
//部门
else if (nodes_Hear.GetAttribute("name") == "imm14")
{
nodes_Hear.SetAttribute("value", "0703");
}
//申请人
else if (nodes_Hear.GetAttribute("name") == "imm16")
{
nodes_Hear.SetAttribute("value", "tiptop");
}
//是否过账
else if (nodes_Hear.GetAttribute("name") == "is_posting")
{
nodes_Hear.SetAttribute("value", "N");
}
}
//修改表单内容
XmlNodeList nodes_Deatils = node_DetailRecord.ChildNodes;
foreach (XmlElement nodes_Deatil in nodes_Deatils)
{
if (nodes_Deatil.GetAttribute("name") == "imn03")
{
nodes_Deatil.SetAttribute("value", receiptDetail.MaterialCode);
}
//拨出仓库(起始点)
else if (nodes_Deatil.GetAttribute("name") == "imn04")
{
nodes_Deatil.SetAttribute("value", ReceiptHeader.LWH);
}
//拨出库位
else if (nodes_Deatil.GetAttribute("name") == "imn05")
{
nodes_Deatil.SetAttribute("value", ReceiptHeader.LWHSL);
}
//拨出批号
else if (nodes_Deatil.GetAttribute("name") == "imn06")
{
nodes_Deatil.SetAttribute("value", receiptDetail.BLot);
}
//库存单位
else if (nodes_Deatil.GetAttribute("name") == "imn09")
{
nodes_Deatil.SetAttribute("value", receiptDetail.Unit);
}
//拨出数量
else if (nodes_Deatil.GetAttribute("name") == "imn10")
{
nodes_Deatil.SetAttribute("value", receiptDetail.Qty.ToString());
}
//拨入仓库(目的地)
else if (nodes_Deatil.GetAttribute("name") == "imn15")
{
nodes_Deatil.SetAttribute("value", ReceiptHeader.WH);
}
//拨入库位
else if (nodes_Deatil.GetAttribute("name") == "imn16")
{
nodes_Deatil.SetAttribute("value", ReceiptHeader.WHSL);
}
//拨入批号
else if (nodes_Deatil.GetAttribute("name") == "imn17")
{
nodes_Deatil.SetAttribute("value", receiptDetail.BLot);
}
//库存单位
else if (nodes_Deatil.GetAttribute("name") == "imn20")
{
nodes_Deatil.SetAttribute("value", receiptDetail.Unit);
}
//单位转换率
else if (nodes_Deatil.GetAttribute("name") == "imn21")
{
nodes_Deatil.SetAttribute("value", "");
}
//转换后数量
else if (nodes_Deatil.GetAttribute("name") == "imn22")
{
nodes_Deatil.SetAttribute("value", "");
}
//拨出条码
else if (nodes_Deatil.GetAttribute("name") == "barcode_out")
{
nodes_Deatil.SetAttribute("value", receiptDetail.Project);
}
//拨入条码
else if (nodes_Deatil.GetAttribute("name") == "barcode_in")
{
nodes_Deatil.SetAttribute("value", receiptDetail.Project);
}
//厂商
else if (nodes_Deatil.GetAttribute("name") == "sfa36")
{
nodes_Deatil.SetAttribute("value", ReceiptHeader.SupplierCode);
}
//
else if (nodes_Deatil.GetAttribute("name") == "checkud")
{
nodes_Deatil.SetAttribute("value","");
}
//备注
else if (nodes_Deatil.GetAttribute("name") == "remark")
{
nodes_Deatil.SetAttribute("value", "");
}
}
}
doc.SelectSingleNode("//RequestContent").RemoveAll();
doc.SelectSingleNode("//RequestContent").InnerXml = doc_isgood_copy.InnerXml;
}
//回传数据
var response = OutBack.CreateMesAimt324(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")
{
var erpSourcecode = msg.Split("/")[0];
ReceiptHeader.Status = 1;
ReceiptHeader.ErpSourceCode = erpSourcecode;
_unitWork.Update(ReceiptHeader);
InterfaceLog interfaceLog = new InterfaceLog();
interfaceLog.TaskNo = ReceiptHeader.SourceCode;
interfaceLog.Request = doc.InnerXml;
interfaceLog.Type = "申请入库单号成功";
interfaceLog.Status = 1;
interfaceLog.Message = Config.InnerXml;
interfaceLog.CreateTime = DateTime.Now;
_unitWork.Add(interfaceLog);
}
else
{
ReceiptHeader.Status = 2;
_unitWork.Update(ReceiptHeader);
InterfaceLog error11 = new InterfaceLog();
error11.TaskNo = ReceiptHeader.SourceCode;
error11.Request = doc.InnerXml;
error11.Type = "申请入库单号失败";
error11.Status = 4;
error11.Message = Config.InnerXml;
error11.CreateTime = DateTime.Now;
_unitWork.Add(error11);
}
}
}
catch (Exception ex)
{
InterfaceLog error11 = new InterfaceLog();
error11.TaskNo = "";
error11.Request = "";
error11.Type = "接口回传定时器报错";
error11.Status = 4;
error11.Message = "Message:" + ex.Message + ",StackTrace:" + ex.StackTrace + ",Source" + ex.Source + ",Data" + ex.Data;
error11.CreateTime = DateTime.Now;
_unitWork.Add(error11);
jobContainer.ExceptionInfo = ex.Message;
}
}
}
}