1
wankeda
2025-03-07 b55d324f4b7465f9a7dc50e999346697f5cc35a2
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEA_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using MailKit.Search;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Org.BouncyCastle.Asn1.Tsp;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Stock;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundService;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model.Models;
using WIDESEA_StockRepository;
using WIDESEA_TaskInfoRepository;
using static WIDESEA_Common.Authentication;
using static WIDESEA_Common.HouseInboundPassBack;
using static WIDESEA_Common.HouseoutboundPassBack;
using static WIDESEA_Common.InventoryAllocate;
using static WIDESEA_ITaskInfoService.ITaskService;
using Parameter = WIDESEA_Common.Parameter;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
    {
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly IStockRepository _stockRepository;
        private readonly IBasicService _basicService;
        private readonly IOutboundService _outboundService;
        private readonly IInboundService _inboundService;
        private readonly IInboundOrderDetailService _inboundOrderDetailService;
        private readonly IRecordService _recordService;
        private readonly IStockService _stockService;
        private readonly ITask_HtyService _taskHtyService;
        private readonly ILocationInfoService _locationInfoService;
        private readonly ITaskService _taskService;
        private readonly IMaterielInfoService _materielInfoService;
        private readonly IInboundOrder_HtyService _inboundOrder_HtyService;
        private readonly IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService;
        private readonly IOutboundOrder_HtyService _outboundOrder_HtyService;
        private readonly IOutboundOrderDetail_HtyService _outboundOrderDetail_HtyService;
 
        public ITaskRepository Repository => BaseDal;
 
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService) : base(BaseDal)
        {
            _mapper = mapper;
            _stockRepository = stockRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _basicService = basicService;
            _outboundService = outboundService;
            _inboundService = inboundService;
            _recordService = recordService;
            _stockService = stockService;
            _taskHtyService = taskHtyService;
            _locationInfoService = locationInfoService;
            _inboundOrderDetailService = inboundOrderDetailService;
            _materielInfoService = materielInfoService;
            _inboundOrder_HtyService = inboundOrder_HtyService;
            _inboundOrderDetail_HtyService = inboundOrderDetail_HtyService;
            _outboundOrder_HtyService = outboundOrder_HtyService;
            _outboundOrderDetail_HtyService = outboundOrderDetail_HtyService;
 
        }
 
        public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
        public string ReceiveWMSTaskout = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskout"];
        public string ReceiveWMSTaskAUT = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAUT"];
        public string ReceiveWMSTaskAllocatein = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAllocatein"];
 
        /// <summary>
        /// 任务完成
        /// </summary>
        /// <param name="taskNum">任务号</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent TaskCompleted(int taskNum)
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return WebResponseContent.Instance.Error("未找到任务信息");
                }
                MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted");
                if (methodInfo != null)
                {
                    WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task });
                    if (responseContent != null)
                    {
                        return responseContent;
                    }
                }
                return WebResponseContent.Instance.Error("未找到任务类型对应业务处理逻辑");
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
 
        }
 
        public WebResponseContent InboundTaskCompleted(int taskNum)
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该任务");
                }
                if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"任务类型错误");
                }
                Dt_StockInfo dt_StockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.Details).First();
                if (dt_StockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到托盘对应的组盘信息");
                }
 
                if (!string.IsNullOrEmpty(dt_StockInfo.LocationCode))
                {
                    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                }
 
                if (dt_StockInfo.Details == null || dt_StockInfo.Details.Count == 0)
                {
                    return WebResponseContent.Instance.Error($"未找到该托盘库存明细信息");
                }
                Dt_LocationInfo dt_LocationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                if (dt_LocationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到目标货位信息");
                }
 
                if (dt_LocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"货位状态不正确");
                }
 
                int lastStatus = dt_LocationInfo.LocationStatus;
                dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
 
                if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt())
                {
                    dt_StockInfo.StockStatus = StockStatusEmun.入库完成未建出库单.ObjToInt();
                    dt_StockInfo.Details.ForEach(x =>
                    {
                        x.Status = StockStatusEmun.入库完成.ObjToInt();
                    });
                }
                else
                {
                    dt_StockInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
 
                }
                dt_StockInfo.LocationCode = dt_LocationInfo.LocationCode;
 
                _unitOfWorkManage.BeginTran();
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateType.人工完成 : OperateType.自动完成);
 
                _basicService.LocationInfoService.Repository.UpdateData(dt_LocationInfo);
                _stockRepository.StockInfoRepository.UpdateData(dt_StockInfo);
                _stockRepository.StockInfoDetailRepository.UpdateData(dt_StockInfo.Details);
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(dt_LocationInfo, lastStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(dt_StockInfo, dt_StockInfo.Details, dt_StockInfo.Details.Sum(x => x.StockQuantity), dt_StockInfo.Details.Sum(x => x.StockQuantity), StockChangeType.Inbound);
                _unitOfWorkManage.CommitTran();
                Dt_StockInfoDetail stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == dt_StockInfo.Id).First();
                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == stockInfoDetail.OrderNo).Includes(x => x.Details).First();
                Dt_InboundOrderDetail inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.OrderId == inboundOrder.Id);
                //判断单据类型是入库还是调拨入库。。。入库
                if (inboundOrder.OrderType == 0)
                {
                    #region //判断入库单据明细只有最后一条完成时删除入库单
                    if (inboundOrder.Details.Count == 1)
                    {
                        Dt_InboundOrder_Hty inboundOrder_Hty = new Dt_InboundOrder_Hty
                        {
                            OrderStatus = inboundOrder.OrderStatus,
                            CreateType = inboundOrder.CreateType,
                            //SourceId = oldOutboundOrder.SourceId,
                            UpperOrderNo = inboundOrder.UpperOrderNo,
                            OrderNo = inboundOrder.OrderNo,
                            //OutWareHouse = inboundOrder.OutWareHouse,
                            TransactionCode = inboundOrder.TransactionCode,
                            InoutType = inboundOrder.InoutType,
                            OrderType = inboundOrder.OrderType,
                            Creater = "WMS",
                            CreateDate = DateTime.Now,
                        };
                        _inboundOrder_HtyService.AddData(inboundOrder_Hty);
                        _inboundService.InbounOrderService.DeleteData(inboundOrder);
                    }
                    Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_InboundOrderDetail_Hty
                    {
                        OrderId = inboundOrderDetail.OrderId,
                        MaterielCode = inboundOrderDetail.MaterielCode,
                        MaterielName = inboundOrderDetail.MaterielName,
                        BatchNo = inboundOrderDetail.BatchNo,
                        OrderQuantity = inboundOrderDetail.OrderQuantity,
                        ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
                        OverInQuantity = inboundOrderDetail.OverInQuantity,
                        OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                    };
                    _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
                    _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
                    #endregion
                    #region//入库信息返回上位WMS。。立库入库数量回传
                    HouseInboundPassBack houseInboundPassBack = new HouseInboundPassBack();
                    houseInboundPassBack.ApiType = "AsnController";
                    houseInboundPassBack.Method = "AsrsGroudingAsn";
                    data data = new data();
                    data.data1 data1 = new data.data1();
                    data1.AsnNo = task.OrderNo;
                    data1.InWarehouse = task.Roadway;
                    data1.TransactionCode = inboundOrder.TransactionCode;
                    data1.InoutType = inboundOrder.OrderType;
                    data1.OrderType = inboundOrder.InoutType;
                    data.data1.Inbound inbound = new data.data1.Inbound
                    {
                        LinId = stockInfoDetail.LinId,
                        MaterielCode = stockInfoDetail.MaterielCode,
                        OrderQuantity = stockInfoDetail.StockQuantity,
                        BatchNo = stockInfoDetail.BatchNo,
                        FinishQty = stockInfoDetail.StockQuantity,
                        LocationName = task.TargetAddress
                    };
                    data.Value.Add(data1);
                    data1.DetailList.Add(inbound);
                    houseInboundPassBack.Parameters.Add(data);
                    Authentication authentication = new Authentication()
                    {
                        ApiType = "AuthenticationController",
                        Parameters = new List<Parameter>
                {
                     new Parameter { Value = "LKAdmin"},
                     new Parameter { Value = "LKAdmin"},
                },
                        Method = "Login",
                    };
                    var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "登录WMS账号");
                    var Ticket = responses1.Context["Ticket"].ToString();
                    var InvOrgId = responses1.Context["InvOrgId"].ToString();
                    if (Ticket != null)
                    {
                        houseInboundPassBack.Context = new Dictionary<string, string>();
                        houseInboundPassBack.Context.Add("Ticket", Ticket);
                        houseInboundPassBack.Context.Add("InvOrgId", InvOrgId);
                        var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, houseInboundPassBack, "立库入库数量回传WMS");
                    }
                    #endregion
                }
                else
                {
                    #region //判断调拨入库单据明细只有最后一条完成时删除入库单并一次返回入库明细信息
                    if (inboundOrder.Details.Count == 1)
                    {
                        List<Dt_StockInfo> StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo);
                        Dt_InboundOrder_Hty inboundOrder_Hty = new Dt_InboundOrder_Hty
                        {
                            OrderStatus = inboundOrder.OrderStatus,
                            CreateType = inboundOrder.CreateType,
                            //SourceId = oldOutboundOrder.SourceId,
                            UpperOrderNo = inboundOrder.UpperOrderNo,
                            OrderNo = inboundOrder.OrderNo,
                            //OutWareHouse = inboundOrder.OutWareHouse,
                            TransactionCode = inboundOrder.TransactionCode,
                            InoutType = inboundOrder.InoutType,
                            OrderType = inboundOrder.OrderType,
                            Creater = "WMS",
                            CreateDate = DateTime.Now,
                        };
                        _inboundOrder_HtyService.AddData(inboundOrder_Hty);
                        _inboundService.InbounOrderService.DeleteData(inboundOrder);
                        Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_HtyS = new Dt_InboundOrderDetail_Hty
                        {
                            OrderId = inboundOrderDetail.OrderId,
                            MaterielCode = inboundOrderDetail.MaterielCode,
                            MaterielName = inboundOrderDetail.MaterielName,
                            BatchNo = inboundOrderDetail.BatchNo,
                            OrderQuantity = inboundOrderDetail.OrderQuantity,
                            ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
                            OverInQuantity = inboundOrderDetail.OverInQuantity,
                            OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
                            Creater = "WMS",
                            CreateDate = DateTime.Now,
                        };
                        _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_HtyS);
                        _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
                        #endregion
                        #region//调拨任务数量回传WMS
                        InventoryAllocate inventoryAllocate = new InventoryAllocate();
                        inventoryAllocate.ApiType = "InventoryAllocateController";
                        inventoryAllocate.Method = "AsrsFinishedStockCount";
 
                        Allocate allocate = new Allocate();
 
                        Allocate.data1 data1 = new Allocate.data1();
                        data1.No = task.OrderNo;
                        data1.InWarehouse = task.Roadway;
                        data1.TransactionCode = inboundOrder.TransactionCode;
                        data1.InoutType = inboundOrder.OrderType;
                        data1.OrderType = inboundOrder.InoutType;
                        foreach (var item in StockInfo)
                        {
                            Dt_StockInfoDetail detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
                            Allocate.data1.Inventory inbound = new Allocate.data1.Inventory();
                            inbound.LinId = detail.LinId;
                            inbound.LPN_No = item.PalletCode;
                            inbound.MaterielCode = detail.MaterielCode;
                            inbound.OrderQuantity = detail.StockQuantity;
                            inbound.BatchNo = detail.BatchNo;
                            inbound.FinishQty = detail.StockQuantity;
                            inbound.LocationName = item.LocationCode;
                            data1.DetailList.Add(inbound);
                        }
                        allocate.Value.Add(data1);
                        inventoryAllocate.Parameters.Add(allocate);
                        Authentication authentication = new Authentication()
                        {
                            ApiType = "AuthenticationController",
                            Parameters = new List<Parameter>
                    {
                     new Parameter { Value = "LKAdmin"},
                     new Parameter { Value = "LKAdmin"},
                    },
                            Method = "Login",
                        };
                        var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "登录WMS账号");
                        var Ticket = responses1.Context["Ticket"].ToString();
                        var InvOrgId = responses1.Context["InvOrgId"].ToString();
                        if (Ticket != null)
                        {
                            inventoryAllocate.Context = new Dictionary<string, string>();
                            inventoryAllocate.Context.Add("Ticket", Ticket);
                            inventoryAllocate.Context.Add("InvOrgId", InvOrgId);
                            var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "调拨入库数量回传WMS");
                        }
                    }
                    #endregion
                    Dt_InboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_InboundOrderDetail_Hty
                    {
                        OrderId = inboundOrderDetail.OrderId,
                        MaterielCode = inboundOrderDetail.MaterielCode,
                        MaterielName = inboundOrderDetail.MaterielName,
                        BatchNo = inboundOrderDetail.BatchNo,
                        OrderQuantity = inboundOrderDetail.OrderQuantity,
                        ReceiptQuantity = inboundOrderDetail.ReceiptQuantity,
                        OverInQuantity = inboundOrderDetail.OverInQuantity,
                        OrderDetailStatus = inboundOrderDetail.OrderDetailStatus,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                    };
                    _inboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
                    _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        public WebResponseContent OutboundTaskCompleted(int taskNum)
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return WebResponseContent.Instance.Error($"未找到任务信息");
                }
 
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
 
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到库存信息");
                }
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到货位信息");
                }
 
                List<Dt_OutStockLockInfo> outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum);
                if (outStockLockInfos == null || outStockLockInfos.Count == 0)
                {
                    return WebResponseContent.Instance.Error($"未找到出库详情信息");
                }
 
                List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
                for (int i = 0; i < outStockLockInfos.Count; i++)
                {
                    Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfos[i].OrderDetailId);
                    if (outboundOrderDetail != null)
                    {
                        outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
                        if (outboundOrderDetail.LockQuantity == outboundOrderDetail.OrderQuantity)
                        {
                            outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                        }
                        outboundOrderDetails.Add(outboundOrderDetail);
                    }
                }
 
                _unitOfWorkManage.BeginTran();
                _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
 
                stockInfo.LocationCode = locationInfo.LocationCode;
                stockInfo.StockStatus = StockStatusEmun.出库完成.ObjToInt();
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
 
                int beforeStatus = locationInfo.LocationStatus;
                locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
 
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
                _unitOfWorkManage.CommitTran();
                Dt_StockInfoDetail stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == stockInfo.Id).First();
                Dt_OutboundOrderDetail outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>().Where(x => x.LPNNo == stockInfo.PalletCode).First();
                Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outDetail.OrderId).Includes(x => x.Details).First();
                //判断单据类型是出库还是调拨出库。。。出库
                if (outboundOrder.OrderType == 1)
                {
                    #region //判断出库单据明细只有最后一条完成时删除出库单
                    if (outboundOrder.Details.Count == 1)
                    {
                        Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty
                        {
                            OrderStatus = outboundOrder.OrderStatus,
                            CreateType = outboundOrder.CreateType,
                            //SourceId = oldOutboundOrder.SourceId,
                            UpperOrderNo = outboundOrder.UpperOrderNo,
                            OrderNo = outboundOrder.OrderNo,
                            OutWareHouse = outboundOrder.OutWareHouse,
                            TransactionCode = outboundOrder.TransactionCode,
                            InoutType = outboundOrder.InoutType,
                            OrderType = outboundOrder.OrderType,
                            Creater = "WMS",
                            CreateDate = DateTime.Now,
                        };
                        _outboundOrder_HtyService.AddData(inboundOrder_Hty);
                        _outboundService.OutboundOrderService.DeleteData(outboundOrder);
                    }
                    Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty
                    {
                        OrderId = outDetail.OrderId,
                        MaterielCode = outDetail.MaterielCode,
                        MaterielName = outDetail.MaterielName,
                        BatchNo = outDetail.BatchNo,
                        OrderQuantity = outDetail.OrderQuantity,
                        //ReceiptQuantity = outDetail.ReceiptQuantity,
                        //OverInQuantity = outDetail.OverInQuantity,
                        OrderDetailStatus = outDetail.OrderDetailStatus,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                    };
                    _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
                    _outboundService.OutboundOrderService.DeleteData(outDetail);
                    #endregion
                    #region//出库信息返回上位WMS。。。立库出库数量回传
                    HouseoutboundPassBack houseInboundPassBack = new HouseoutboundPassBack();
                    houseInboundPassBack.ApiType = "ShippingOrderController";
                    houseInboundPassBack.Method = "AsrsOutboundSO";
                    datas datas = new datas();
                    datas.data1 data1 = new datas.data1();
                    data1.No = outboundOrder.OrderNo;
                    data1.OutWareHouse = task.Roadway;
                    data1.TransactionCode = outboundOrder.TransactionCode;
                    data1.InoutType = outboundOrder.OrderType;
                    data1.OrderType = outboundOrder.InoutType;
 
                    datas.data1.Inbound inbound = new datas.data1.Inbound();
                    inbound.LinId = outDetail.LinId;
                    inbound.LPN_No = task.PalletCode;
                    inbound.MaterielCode = stockInfoDetail.MaterielCode;
                    inbound.OrderQuantity = stockInfoDetail.OutboundQuantity;
                    inbound.BatchNo = stockInfoDetail.BatchNo;
                    inbound.FinishQty = stockInfoDetail.OutboundQuantity;
                    inbound.LocationName = task.SourceAddress;
                    datas.Value.Add(data1);
                    data1.DetailList.Add(inbound);
                    houseInboundPassBack.Parameters.Add(datas);
                    Authentication authentication = new Authentication()
                    {
                        ApiType = "AuthenticationController",
                        Parameters = new List<Parameter>
                    {
                     new Parameter { Value = "LKAdmin"},
                     new Parameter { Value = "LKAdmin"},
                    },
                        Method = "Login",
                    };
                    var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "登录WMS账号");
                    var Ticket = responses1.Context["Ticket"].ToString();
                    var InvOrgId = responses1.Context["InvOrgId"].ToString();
                    if (Ticket != null)
                    {
                        houseInboundPassBack.Context = new Dictionary<string, string>();
                        houseInboundPassBack.Context.Add("Ticket", Ticket);
                        houseInboundPassBack.Context.Add("InvOrgId", InvOrgId);
                        var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskout, houseInboundPassBack, "立库出库数量回传WMS");
                    }
                    #endregion
                    //删除库存信息
                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                }
                else if (outboundOrder.OrderType == 240)
                {
                    //盘点出库任务完成、、、、、、、、、不能删除库存等逻辑
                }
                else
                {
 
                    List<Dt_StockInfo> StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == outDetail.BatchNo);
                    if (outboundOrder.Details.Count == 1)
                    {
                        Dt_OutboundOrder_Hty inboundOrder_Hty = new Dt_OutboundOrder_Hty
                        {
                            OrderStatus = outboundOrder.OrderStatus,
                            CreateType = outboundOrder.CreateType,
                            //SourceId = oldOutboundOrder.SourceId,
                            UpperOrderNo = outboundOrder.UpperOrderNo,
                            OrderNo = outboundOrder.OrderNo,
                            OutWareHouse = outboundOrder.OutWareHouse,
                            TransactionCode = outboundOrder.TransactionCode,
                            InoutType = outboundOrder.InoutType,
                            OrderType = outboundOrder.OrderType,
                            Creater = "WMS",
                            CreateDate = DateTime.Now,
                        };
                        _outboundOrder_HtyService.AddData(inboundOrder_Hty);
                        _outboundService.OutboundOrderService.DeleteData(outboundOrder);
                    }
                    Dt_OutboundOrderDetail_Hty dt_InboundOrderDetail_Hty = new Dt_OutboundOrderDetail_Hty
                    {
                        OrderId = outDetail.OrderId,
                        MaterielCode = outDetail.MaterielCode,
                        MaterielName = outDetail.MaterielName,
                        BatchNo = outDetail.BatchNo,
                        OrderQuantity = outDetail.OrderQuantity,
                        //ReceiptQuantity = outDetail.ReceiptQuantity,
                        //OverInQuantity = outDetail.OverInQuantity,
                        OrderDetailStatus = outDetail.OrderDetailStatus,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                    };
                    _outboundOrderDetail_HtyService.AddData(dt_InboundOrderDetail_Hty);
                    _outboundService.OutboundOrderService.DeleteData(outDetail);
 
                    InventoryAllocate inventoryAllocate = new InventoryAllocate();
                    inventoryAllocate.ApiType = "InventoryAllocateController";
                    inventoryAllocate.Method = "AsrsFinishedStockCount";
 
                    Allocate allocate = new Allocate();
 
                    Allocate.data1 data1 = new Allocate.data1();
                    data1.No = outboundOrder.OrderNo;
                    data1.InWarehouse = task.Roadway;
                    data1.TransactionCode = outboundOrder.TransactionCode;
                    data1.InoutType = outboundOrder.OrderType;
                    data1.OrderType = outboundOrder.InoutType;
 
                    foreach (var item in StockInfo)
                    {
                        Dt_StockInfoDetail detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
                        Allocate.data1.Inventory inbound = new Allocate.data1.Inventory();
                        inbound.LinId = outDetail.LinId;
                        inbound.LPN_No = item.PalletCode;
                        inbound.MaterielCode = detail.MaterielCode;
                        inbound.OrderQuantity = detail.OutboundQuantity;
                        inbound.BatchNo = detail.BatchNo;
                        inbound.FinishQty = detail.OutboundQuantity;
                        inbound.LocationName = task.SourceAddress;
                        data1.DetailList.Add(inbound);
                    }
 
 
                    allocate.Value.Add(data1);
                    inventoryAllocate.Parameters.Add(allocate);
                    Authentication authentication = new Authentication()
                    {
                        ApiType = "AuthenticationController",
                        Parameters = new List<Parameter>
                    {
                     new Parameter { Value = "LKAdmin"},
                     new Parameter { Value = "LKAdmin"},
                    },
                        Method = "Login",
                    };
                    var responses1 = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "登录WMS账号");
                    var Ticket = responses1.Context["Ticket"].ToString();
                    var InvOrgId = responses1.Context["InvOrgId"].ToString();
                    if (Ticket != null)
                    {
                        inventoryAllocate.Context = new Dictionary<string, string>();
                        inventoryAllocate.Context.Add("Ticket", Ticket);
                        inventoryAllocate.Context.Add("InvOrgId", InvOrgId);
                        var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "调拨出库数量回传WMS");
                    }
                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
    }
}