Blame view

WebMvc/Areas/WebService/SampleService.cs 18.8 KB
gy.huang authored
1
using Infrastructure;
gy.huang authored
2
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
gy.huang authored
3
using System;
gy.huang authored
4
using System.Collections.Generic;
5
6
using System.Configuration;
using System.IO;
gy.huang authored
7
8
using System.Linq;
using System.Threading.Tasks;
9
using System.Xml;
gy.huang authored
10
using System.Xml.Linq;
11
12
13
14
using System.Xml.Serialization;
using WebApp;
using WebMvc.Areas.WebService;
using WebRepository;
gy.huang authored
15
16
namespace WebMvc.Areas.WebService
gy.huang authored
17
{
gy.huang authored
18
19
    public class SampleService : ISampleService
    {
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
        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;
        }
69
70
71
72
73
74
75
76
        //入库
        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);
霍尔 authored
77
78

            //取出报文接收状态字段
79
80
81
82
83
84
            XmlElement element = (XmlElement)reDoc.SelectSingleNode("//Status");
            try
            {
                doc.LoadXml(Request);
                string name = "";
                string value = "";
霍尔 authored
85
                string UpperTaskNo = "";
86
                string SourceCode = "";
霍尔 authored
87
88
                string TaskType = "";
                string CustomerCode = "";
89
                string MaterialCode = "";
霍尔 authored
90
                string SupplierCode = "";
霍尔 authored
91
                decimal? Num = 0;
92
                string WareCell = "";
霍尔 authored
93
                string Code = "";
霍尔 authored
94
                var NewCode = "";
霍尔 authored
95
                XmlNodeList RecordSets = doc.SelectNodes("//Record");
96
97
                foreach (XmlNode RecordSet in RecordSets)
                {
霍尔 authored
98
                    XmlNodeList nodes = RecordSet.ChildNodes;
99
100
101
102
103
104
                    foreach (XmlElement node in nodes)
                    {
                        //抓取单个的xml节点
                        //获得字节里面的属性值
                        name = node.GetAttribute("name");
                        value = node.GetAttribute("value");
霍尔 authored
105
106
107
108
109
110
111
112
113
114
                        //上游任务号
                        if (name == "tc_dcf000" && !string.IsNullOrEmpty(value))
                        {
                            UpperTaskNo = value;
                        }
                        //上游作业类型
                        else if (name == "tc_dcf001" && !string.IsNullOrEmpty(value))
                        {
                            TaskType = value;
                        }
115
                        //上游系统单号
霍尔 authored
116
                        else if (name == "tc_dcf003" && !string.IsNullOrEmpty(value))
117
118
119
                        {
                            SourceCode = value;
                        }
霍尔 authored
120
121
122
123
124
125
126
127
128
129
                        //供应商
                        else if (name == "dcf004" && !string.IsNullOrEmpty(value))
                        {
                            SupplierCode = value;
                        }
                        //入库部门
                        else if (name == "dcf006" && !string.IsNullOrEmpty(value))
                        {
                            SupplierCode = value;
                        }
130
131
132
133
134
135
136
137
138
139
                        //提取物料号
                        else if (name == "tc_dcf016" && !string.IsNullOrEmpty(value))
                        {
                            MaterialCode = value;
                        }
                        //入库数量
                        else if (name == "tc_dcf021" && !string.IsNullOrEmpty(value))
                        {
                            Num = decimal.Parse(value);
                        }
霍尔 authored
140
141
142
143
144
                        //条码
                        else if (name == "tc_dcf025" && !string.IsNullOrEmpty(value))
                        {
                            Code = value;
                        }
145
146
147
148
149
150
151
152
                        //仓库
                        else if (name == "tc_dcf028" && !string.IsNullOrEmpty(value))
                        {
                            WareCell = value;
                        }

                    }
霍尔 authored
153
154
155
                    #region 保存入库单主表
                    ReceiptHeader receiptHeader = _unitWork.FindSingle<ReceiptHeader>(u => u.SourceCode.Equals(SourceCode));
                    if (receiptHeader != null)
156
                    {
霍尔 authored
157
158
159
160
                        if (receiptHeader.FirstStatus != ReceiptHeaderStatus.新建)
                        {
                            throw new Exception("单据进入订单池后,不允许修改!");
                        }
161
                    }
霍尔 authored
162
163
                    else
                    {
霍尔 authored
164
                        NewCode = _unitWork.GetTaskNo(TaskNo.入库手动分配);
霍尔 authored
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
                        receiptHeader = new ReceiptHeader();
                        receiptHeader.Type = BusinessType.入库_采购到货单;
                        receiptHeader.SourceCode = 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)
                    {
183
                        _apprh.Add(receiptHeader);
霍尔 authored
184
185
186
187
188
189
                    }
                    //else
                    //{
                    //    _apprh.UpdateByTracking(receiptHeader);
                    //}
                    #endregion
190
霍尔 authored
191
192
193
194
195
196
                    #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();
                    //}
197
霍尔 authored
198
199
200
201
202
203
204
205
206
207
                    receiptDetail.SourceCode = 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;
208
霍尔 authored
209
210
211
212
213
214
215
216
217
                    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)
                    //{
218
219
220
                    _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);
霍尔 authored
221
222
223
224
225
226
                    //}
                    //else
                    //{
                    //    _apprd.UpdateByTracking(receiptDetail);
                    //}
                    #endregion
227
霍尔 authored
228
229
230
231
232
233
234
235
236
237
                    #region 更新入库单主表汇总信息
                    receiptHeader.TotalLines += (short)_unitWork.Find<ReceiptDetail>(n => n.ReceiptCode == receiptHeader.Code).ToList().Count;
                    receiptHeader.TotalQty += _unitWork.Find<ReceiptDetail>(n => n.ReceiptCode == receiptHeader.Code).Sum(x => x.Qty);
                    if (receiptHeader.UpdateBy == null)
                    {
                        receiptHeader.UpdateBy = "wms";
                        receiptHeader.UpdateTime = DateTime.Now;
                    }
                    _apprh.UpdateByTracking(receiptHeader);
                    #endregion
238
                }
霍尔 authored
239
240
241
242
243
244
245
                InterfaceLog inter = new InterfaceLog();
                inter.Status = 0;
                inter.TaskNo = UpperTaskNo + SourceCode;
                inter.Request = Request;
                inter.CreateTime = DateTime.Now;
                inter.CreateBy = "WMS";
                _unitWork.Add(inter);
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266




                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);
霍尔 authored
267
            //取出报文接收状态字段
268
269
270
            XmlElement element = (XmlElement)reDoc.SelectSingleNode("//Status");
            try
            {
gy.huang authored
271
272
273
274
275
276
277
278
279
                InterfaceLog inter = new InterfaceLog
                {
                    Initiator = "ERP",
                    recipient = "WMS",
                    Request = Request,
                    Method = "LK_Out",
                    CreateTime = DateTime.Now,
                    CreateBy = "WMS"
                };
霍尔 authored
280
281
                _unitWork.Add(inter);
282
                doc.LoadXml(Request);
霍尔 authored
283
284
285
286
287
288
289
290
291
                string name = "";
                string value = "";
                string SourceCode = "";
                string MaterialCode = "";
                string shipTo = "";
                string Station = "";
                decimal Num = 0;
                string WareCell = "";
                string Location ="";
gy.huang authored
292
                XmlNodeList RecordSets = doc.SelectNodes("//Record");
霍尔 authored
293
                foreach (XmlNode RecordSet in RecordSets)
294
                {
gy.huang authored
295
                    XmlNodeList nodes = RecordSet.ChildNodes;
霍尔 authored
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
                    foreach (XmlElement node in nodes)
                    {
                        //抓取单个的xml节点
                        //获得字节里面的属性值
                        name = node.GetAttribute("name");
                        value = node.GetAttribute("value");
                        //上游系统单号
                        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;
                        }
                    }
gy.huang authored
339
340
341
                    #region 保存入库单主表
                    ShipmentHeader shipmentheader = _unitWork.FindSingle<ShipmentHeader>(u => u.SourceCode.Equals(SourceCode) && u.Station == Station);
                    if (shipmentheader != null)
342
                    {
gy.huang authored
343
344
345
346
                        if (shipmentheader.FirstStatus != ReceiptHeaderStatus.新建)
                        {
                            throw new Exception("单据进入订单池后,不允许修改!");
                        }
347
                    }
gy.huang authored
348
349
350
351
352
353
354
355
356
357
                    else
                    {
                        shipmentheader = new ShipmentHeader
                        {
                            Type = BusinessType.出库_其他出库单,
                            SourceCode = SourceCode,
                            Station = Station,
                            WarehouseType = WareCell,
                            UploadStatus = 0,
                            ShipTo = shipTo,
霍尔 authored
358
gy.huang authored
359
360
361
362
363
364
365
366
367
368
369
                            Code = _unitWork.GetTaskNo(TaskNo.出库手动分配),
                            FirstStatus = ReceiptHeaderStatus.新建,
                            LastStatus = ReceiptHeaderStatus.新建,
                            TotalLines = 0,
                            TotalQty = 0,
                            CreateBy = "WMS",
                            CreateTime = DateTime.Now
                        };
                        _unitWork.Add(shipmentheader);
                    }
                    #endregion
霍尔 authored
370
gy.huang authored
371
372
373
374
375
376
377
378
379
                    #region 保存入库单子表
                    ShipmentDetail shipmentDetail = new ShipmentDetail
                    {
                        SourceCode = SourceCode,
                        MaterialCode = MaterialCode,
                        InventoryStatus = "",
                        Qty = Num,
                        CreateTime = shipmentheader.CreateTime,
                        CreateBy = shipmentheader.CreateBy,
霍尔 authored
380
gy.huang authored
381
382
383
384
385
386
387
                        ShipmentId = shipmentheader.Id,
                        ShipmentCode = shipmentheader.Code,
                        QtyDivided = 0,
                        QtyCompleted = 0,
                        Price = 0,
                        Status = ReceiptHeaderStatus.新建
                    };
霍尔 authored
388
389
gy.huang authored
390
                    _unitWork.Add(shipmentDetail);
霍尔 authored
391
gy.huang authored
392
393
                    #endregion
                }
394
395
396
397
398
399
400
401

                element.SetAttribute("code", "0");
            }
            catch (Exception ex)
            {
                element.SetAttribute("code", "1");
                element.SetAttribute("description", ex.Message);
            }
霍尔 authored
402
            return reDoc.InnerXml;
403
404
405
        }
        //RGV移动
        public string LK_RgvMove(string Request)
gy.huang authored
406
407
408
409
410
        {
            ConfigXmlDocument doc = new ConfigXmlDocument();
            ConfigXmlDocument reDoc = new ConfigXmlDocument();
            //读取传入的xml
            var config = AppSettingsJson.GetAppSettings();
411
            reDoc.Load(config.GetSection("NouYaWebInService:Url").Value);
gy.huang authored
412
413
414
415
416
417
418
419
420
421
422
423
424
425
            //填入是否报错
            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");
                }
426
                element.SetAttribute("code", "0");
gy.huang authored
427
            }
428
            catch (Exception ex)
gy.huang authored
429
            {
430
                element.SetAttribute("code", "1");
gy.huang authored
431
432
433
                element.SetAttribute("description", ex.Message);
            }
            return reDoc.InnerText;
434
        }
435
gy.huang authored
436
        public ReceiptResponse ReceiptService(MaterialsInformation[] materials)
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
        {
            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;
        }
gy.huang authored
452
453
    }
}