dengjunjie
2 天以前 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
#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 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 System.Transactions;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
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_DTO.WCSInfo;
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_OutboundRepository;
using WIDESEA_StockRepository;
using WIDESEA_TaskInfoRepository;
using WIDESEAWCS_DTO.WCSInfo;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
    {
        private readonly IMapper _mapper;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
 
        private readonly IBasicService _basicService;
        private readonly IOutboundService _outboundService;
        private readonly IInboundService _inboundService;
        private readonly IRecordService _recordService;
        private readonly IStockService _stockService;
        private readonly IInventoryInfoRepository _inventoryInfoRepository;
        private readonly IInventoryBatchRepository _inventoryBatchRepository;
        private readonly IBasicRepository _basicRepository;
 
        public ITaskRepository Repository => BaseDal;
 
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, IInventoryInfoRepository inventoryInfoRepository, IInventoryBatchRepository inventoryBatchRepository, IBasicRepository basicRepository) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
            _basicService = basicService;
            _outboundService = outboundService;
            _inboundService = inboundService;
            _recordService = recordService;
            _inventoryInfoRepository = inventoryInfoRepository;
            _inventoryBatchRepository = inventoryBatchRepository;
            _stockService = stockService;
            _basicRepository = basicRepository;
        }
 
        /// <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);
            }
 
        }
        /// <summary>
        /// 入库任务完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent InboundTaskCompleted(Dt_Task task)
        {
            Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
 
            Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
 
            CheckCompleted(stockInfo, locationInfo);
 
            stockInfo.LocationCode = locationInfo.LocationCode;
            stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
            _stockService.StockInfoService.Repository.UpdateData(stockInfo);
 
            int beforeStatus = locationInfo.LocationStatus;
            locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
            _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
 
            BaseDal.DeleteData(task);
 
            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
 
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 空托盘入库完成处理
        /// </summary>
        /// <param name="task">任务实体对象</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent PalletInboundTaskCompleted(Dt_Task task)
        {
            Dt_StockInfo stockInfo = new Dt_StockInfo()
            {
                PalletCode = task.PalletCode,
                LocationCode = task.TargetAddress,
                StockStatus = StockStatusEmun.已入库.ObjToInt()
            };
            Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
 
            CheckCompleted(stockInfo, locationInfo);
 
            _stockService.StockInfoService.Repository.AddData(stockInfo);
 
            int beforeStatus = locationInfo.LocationStatus;
            locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
            _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
 
 
            BaseDal.DeleteData(task);
 
            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
 
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 验证数据
        /// </summary>
        /// <param name="stockInfo"></param>
        /// <param name="locationInfo"></param>
        /// <returns></returns>
        private (bool, string) CheckCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true)
        {
            if (stockInfo == null)
            {
                return (false, "未找到组盘信息");
            }
 
            if (locationInfo == null)
            {
                return (false, "未找到货位信息");
            }
 
            if (isCheckStockDetail && (stockInfo.Details == null || stockInfo.Details.Count == 0))
            {
                return (false, "未找到组盘明细信息");
            }
 
            return (true, "成功");
        }
        /// <summary>
        /// 出库任务完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent OutboundTaskCompleted(Dt_Task task)
        {
            Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
 
            Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
 
            CheckCompleted(stockInfo, locationInfo);
 
            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.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
 
            return OnOutboundTaskCompleted?.Invoke(task) ?? WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 托盘出库任务完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent PalletOutboundTaskCompleted(Dt_Task task)
        {
            Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
 
            Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
 
            CheckCompleted(stockInfo, locationInfo);
 
            _stockService.StockInfoService.Repository.DeleteData(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.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
 
            return WebResponseContent.Instance.OK();
        }
        public WebResponseContent OutQC(string batchNo, int qty)
        {
            WebResponseContent webResponse = new WebResponseContent().OK();
            try
            {
                Dt_Inventory_Batch inventory_Batch = _inventoryBatchRepository.QueryFirst(x => x.BatchNo == batchNo);
                if (inventory_Batch == null) return webResponse.Error($"未找到批号【{batchNo}】的库存批次信息");
                if (inventory_Batch.ProductStatus != ProductStatusEmun.待检1.ObjToInt())
                    return webResponse.Error($"批号【{batchNo}】已质检入库");
                List<Dt_InventoryInfo> _InventoryInfos = _inventoryInfoRepository.QueryData(x => x.BatchNo == batchNo && x.StockStatus == StockStatusEmun.已入库.ObjToInt()).OrderByDescending(x => x.InDate).Take(qty).ToList();
                if (_InventoryInfos.Count < 1) return webResponse.Error($"未找到批号【{batchNo}】的库存");
                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == _InventoryInfos.First().LocationCode);
                List<Dt_Task> tasks = new List<Dt_Task>();
                List<Dt_OutStockLockInfo> OutStockLockInfos = new List<Dt_OutStockLockInfo>();
                #region 生成质检出库单
                Dt_OutboundOrderDetail orderDetail = new Dt_OutboundOrderDetail()
                {
                    BatchNo = batchNo,
                    Creater = "System",
                    OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt()
                };
                Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder()
                {
                    CreateType = CreateType.CreateInSystem.ObjToInt(),
                    OrderStatus = OutboundStatusEnum.出库中.ObjToInt(),
                    OrderNo = batchNo,
                    OrderType = OutOrderTypeEnum.Quality.ObjToInt(),
                    Creater = "System",
                    Details = new List<Dt_OutboundOrderDetail>() { orderDetail }
                };
                #endregion
                foreach (var item in _InventoryInfos)
                {
                    orderDetail.MaterielCode = item.MaterielCode;
                    orderDetail.MaterielName = item.MaterielName;
                    orderDetail.OrderQuantity += item.StockQuantity;
                    orderDetail.LockQuantity += item.StockQuantity;
                    item.OutboundQuantity = item.StockQuantity;
                    item.StockStatus = StockStatusEmun.出库中.ObjToInt();
                    Dt_Task task = new Dt_Task()
                    {
                        CurrentAddress = item.LocationCode,
                        Grade = 0,
                        PalletCode = item.PalletCode,
                        SourceIsPickPlace = item.SerialNumber == locationInfo.MaxQty,
                        NextAddress = "1005",
                        Roadway = "SC01",
                        SourceAddress = item.LocationCode,
                        TargetAddress = "1005",
                        TaskState = OutTaskStatusEnum.OutNew.ObjToInt(),
                        TaskType = TaskTypeEnum.OutQuality.ObjToInt(),
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
                    };
                    tasks.Add(task);
                    #region 添加出库详情
                    Dt_OutStockLockInfo outStockLockInfo = new Dt_OutStockLockInfo()
                    {
                        PalletCode = item.PalletCode,
                        AssignQuantity = item.OutboundQuantity,
                        MaterielCode = item.MaterielCode,
                        BatchNo = item.BatchNo,
                        LocationCode = item.LocationCode,
                        MaterielName = item.MaterielName,
                        OrderDetailId = orderDetail.Id,
                        OrderNo = outboundOrder.OrderNo,
                        OrderType = outboundOrder.OrderType,
                        OriginalQuantity = item.StockQuantity,
                        Status = OutLockStockStatusEnum.出库中.ObjToInt(),
                        StockId = item.Id,
                        TaskNum = task.TaskNum,
                        OrderQuantity = orderDetail.OrderQuantity
                    };
                    OutStockLockInfos.Add(outStockLockInfo);
                    #endregion
                }
 
                #region 生成质检入库单
                Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail()
                {
                    BatchNo = batchNo,
                    Creater = "System",
                    OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                    MaterielName = orderDetail.MaterielName,
                    MaterielCode = orderDetail.MaterielCode,
                    OrderQuantity = orderDetail.OrderQuantity
                };
                Dt_InboundOrder inboundOrder = new Dt_InboundOrder()
                {
                    CreateType = CreateType.CreateInSystem.ObjToInt(),
                    OrderStatus = InboundStatusEnum.未开始.ObjToInt(),
                    OrderNo = batchNo,
                    OrderType = InOrderTypeEnum.Quality.ObjToInt(),
                    Creater = "System",
                    Details = new List<Dt_InboundOrderDetail>() { inboundOrderDetail }
                };
                #endregion
                #region 处理库存和库存批次信息
                inventory_Batch.StockQuantity = Convert.ToInt32(inventory_Batch.StockQuantity - orderDetail.OrderQuantity);
 
                inventory_Batch.BoxQuantity = inventory_Batch.StockQuantity / 8;
                if (inventory_Batch.StockQuantity % 8 > 0) inventory_Batch.BoxQuantity++;
                inventory_Batch.OutboundQuantity = Convert.ToInt32(inventory_Batch.OutboundQuantity + orderDetail.OrderQuantity);
                #endregion
                #region 事务处理
                Db.Ado.BeginTran();
                BaseDal.AddData(tasks);
                _outboundService.OutboundOrderService.Repository.Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
                _outboundService.OutboundStockLockInfoService.Repository.AddData(OutStockLockInfos);
                _inboundService.InbounOrderService.Repository.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                _inventoryInfoRepository.UpdateData(_InventoryInfos);
                _inventoryBatchRepository.UpdateData(inventory_Batch);
                #region 下发任务给WCS
                List<WMSTaskDTO> wMSTaskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
                var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ReceiveTask, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"向WCS下发出库任务超时");
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
                if (content == null) throw new Exception($"下发出库任务WCS无响应");
                if (!content.Status) throw new Exception(content.Message);
                #endregion
                Db.Ado.CommitTran();
                #endregion
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                webResponse.Error(ex.Message);
            }
            return webResponse;
        }
        public WebResponseContent ModifyQty(string palletCode, int qty)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (inventoryInfo == null) throw new Exception("未找到托盘信息");
                if (inventoryInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && inventoryInfo.StockStatus != StockStatusEmun.入库确认.ObjToInt() && inventoryInfo.StockStatus != StockStatusEmun.入库中.ObjToInt())
                    throw new Exception($"托盘非入库中,不可修改数量");
                Dt_InboundOrderDetail orderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                var StockQty = inventoryInfo.StockQuantity;
                inventoryInfo.StockQuantity = qty;
                inventoryInfo.BoxQuantity = qty % 8 > 0 ? qty / 8 + 1 : qty / 8;
                if (orderDetail != null)
                {
                    orderDetail.ReceiptQuantity -= StockQty - qty;
                    _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
                }
                _inventoryInfoRepository.UpdateData(inventoryInfo);
                return webResponseContent.OK();
            }
            catch (Exception ex)
            {
                return webResponseContent.Error(ex.Message);
            }
        }
 
        public WebResponseContent ModifyBarcode(string barcode, string newBarcode)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                Dt_Task? dt_Task = BaseDal.QueryFirst(x => x.PalletCode == barcode);
                if (dt_Task == null) throw new Exception($"未找到托盘号为【{barcode}】的任务!");
                if (TaskEnumHelper.GetTaskTypeGroup(dt_Task.TaskType) != TaskTypeGroup.InboundGroup)
                    throw new Exception($"只可修改入库任务,如需修改其他任务类型请联系管理员!");
                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == newBarcode);
                if (inventoryInfo != null) throw new Exception($"托盘号【{newBarcode}】已存在库存信息!");
                inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == barcode);
                if (inventoryInfo == null) throw new Exception($"托盘号【{barcode}】未找到库存信息!");
                inventoryInfo.PalletCode = newBarcode;
 
                //var stock = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == newBarcode);
                //if (stock != null) throw new Exception($"托盘号【{newBarcode}】已存在库存信息!");
                //stock = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == barcode);
                //if (stock == null) throw new Exception($"托盘号【{barcode}】未找到库存信息!");
                //stock.PalletCode = newBarcode;
                dt_Task.PalletCode = newBarcode;
                Db.Ado.BeginTran();
                WMSTaskDTO wMSTaskDTOs = _mapper.Map<WMSTaskDTO>(dt_Task);
                var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ModifyBarcode, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>());
                if (ResultData.Result == null) throw new Exception($"WCS响应超时");
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result);
                if (content == null) throw new Exception($"WCS无响应");
                if (!content.Status) throw new Exception(content.Message);
                BaseDal.UpdateData(dt_Task);
                //_stockService.StockInfoService.Repository.UpdateData(stock);
                _inventoryInfoRepository.UpdateData(inventoryInfo);
                Db.Ado.CommitTran();
                webResponseContent.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                webResponseContent.Error(ex.Message);
            }
            return webResponseContent;
        }
        public WebResponseContent CancelTask(WMSTaskDTO WMStask)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == WMStask.TaskNum && x.TaskType == WMStask.TaskType);
                if (task == null) return WebResponseContent.Instance.Error("未找到任务信息");
                Dt_StockInfo? _StockInfo = _stockService.StockInfoService.GetStockByPalletCode(task.PalletCode);
                if (_StockInfo != null)
                {
                    Dt_StockInfoDetail? detail = _StockInfo.Details.FirstOrDefault();
                    if (detail != null)
                    {
                        Dt_InboundOrder dt_InboundOrder = _inboundService.InbounOrderService.GetInboundOrder(detail.OrderNo);
                        Dt_InboundOrderDetail? inboundOrderDetail = dt_InboundOrder.Details.FirstOrDefault(x => x.BatchNo == detail.BatchNo);
                        if (inboundOrderDetail != null)
                        {
                            inboundOrderDetail.ReceiptQuantity--;
                            _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                        }
                        _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(_StockInfo.Details, OperateType.AGV删除);
                    }
                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(_StockInfo, OperateType.AGV删除);
                }
                BaseDal.DeleteAndMoveIntoHty(task, /*App.User.UserId == 0 ? OperateType.自动完成 :*/ OperateType.AGV删除);
            }
            catch (Exception ex)
            {
                webResponseContent.Error(ex.Message);
            }
            return webResponseContent;
        }
        /// <summary>
        /// 同步任务状态
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent UpdateTaskStatus(WMSTaskDTO WMStask)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == WMStask.TaskNum && x.TaskType == WMStask.TaskType);
                if (task == null) return WebResponseContent.Instance.Error("未找到任务信息");
                if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.InboundGroup)
                {
                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
                    //if (WMStask.TaskState != nextStatus) return WebResponseContent.Instance.Error($"该任务状态有误,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】");
                    //task.TaskState = nextStatus;
                    task.TaskState = TaskInStatusEnum.InFinish.ObjToInt();
                    content = NewUpdateTaskStatusInFinish(task);
                }
                else if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.OutbondGroup)
                {
                    //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
                    //if (WMStask.TaskState != nextStatus) return WebResponseContent.Instance.Error($"该任务状态有误,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】");
                    //task.TaskState = nextStatus;
                    task.TaskState = WMStask.TaskState;
                    switch (task.TaskState)
                    {
                        case (int)TaskOutStatusEnum.SC_OutFinish://更新货位库存信息
                            content = NewUpdateTaskStatusSC_OutFinish(task);
                            break;
                        case (int)TaskOutStatusEnum.AGV_OutFinish:
                            {
                                task.CurrentAddress = WMStask.CurrentAddress;
                                task.TargetAddress = WMStask.TargetAddress;
                                task.NextAddress = string.Empty;
                                content = UpdateData(task);
                            }
                            break;
                        case (int)TaskOutStatusEnum.OutFinish:
                            content = UpdateTaskStatusOutFinish(task);
                            break;
                        default:
                            content = UpdateData(task);
                            break;
                    }
                }
                else if (task.TaskType == (int)TaskTypeEnum.Relocation)
                {
                    task.TaskState = WMStask.TaskState;
                    if (task.TaskState == (int)WIDESEA_Core.Enums.TaskRelocationStatusEnum.SC_RelocationFinish)
                        content = UpdateTaskStatusRelocationCarFinish(task);
                    else
                        content = UpdateData(task);
                }
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        public WebResponseContent NewUpdateTaskStatusSC_OutFinish(Dt_Task task)
        {
            try
            {
                Dt_Inventory_Batch? inventory_Batch = null;
                Dt_OutboundOrderDetail? orderDetail = null;
                Dt_OutboundOrder? outboundOrder = null;
                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
                if (inventoryInfo != null)
                {
                    inventory_Batch = _inventoryBatchRepository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                    orderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                }
                Dt_LocationInfo Sourcelocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
 
                Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum && task.PalletCode == x.PalletCode);
                Db.Ado.BeginTran();
                if (inventoryInfo != null) _inventoryInfoRepository.DeleteData(inventoryInfo);
 
                if (Sourcelocation != null)
                {
                    if (BaseDal.QueryFirst(x => x.SourceAddress == task.SourceAddress && x.TaskState < TaskOutStatusEnum.SC_OutFinish.ObjToInt()) == null)
                        Sourcelocation.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    Sourcelocation.CurrentQty--;
                    if (Sourcelocation.CurrentQty <= 0)
                    {
                        Sourcelocation.CurrentQty = 0;
                        Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                        Sourcelocation.EnableStatus = EnableStatusEnum.Normal.ObjToInt();
                    }
                    _basicService.LocationInfoService.Repository.UpdateData(Sourcelocation);
                }
                if (inventory_Batch != null)
                {
                    //inventory_Batch.StockQuantity -= inventoryInfo.StockQuantity;
                    inventory_Batch.OutboundQuantity -= inventoryInfo.StockQuantity;
                    if (inventory_Batch.StockQuantity == 0 && inventory_Batch.OutboundQuantity == 0)
                        _inventoryBatchRepository.DeleteData(inventory_Batch);
                    else _inventoryBatchRepository.UpdateData(inventory_Batch);
                }
                if (orderDetail != null)
                {
                    if (outStockLockInfo != null)
                    {
                        outStockLockInfo.OrderDetailId = orderDetail.OrderId;
                        _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo);
                    }
                    orderDetail.OverOutQuantity += inventoryInfo.StockQuantity;
                    if (orderDetail.OverOutQuantity == orderDetail.OrderQuantity)
                    {
                        outboundOrder = _outboundService.OutboundOrderService.Repository.QueryFirst(x => x.Id == orderDetail.OrderId);
                        if (outboundOrder != null)
                        {
                            outboundOrder.OrderStatus = OutboundStatusEnum.出库完成.ObjToInt();
                            _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, OperateType.自动完成);
                        }
                        orderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                        _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(orderDetail, OperateType.自动完成);
                    }
                    else
                        _outboundService.OutboundOrderDetailService.Repository.UpdateData(orderDetail);
                }
                task.CurrentAddress = "1005";
                task.TargetAddress = "1008";
                task.NextAddress = "1008";
                UpdateData(task);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// 修改任务状态为堆垛机出库完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent UpdateTaskStatusSC_OutFinish(Dt_Task task)
        {
            try
            {
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                Dt_LocationInfo Sourcelocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
                Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum);
                Db.Ado.BeginTran();
                if (stockInfo != null)
                {
                    _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                }
                if (Sourcelocation != null)
                {
                    /*if (task.TaskType == TaskOutboundTypeEnum.Outbound.ObjToInt())*/
                    if (BaseDal.QueryFirst(x => x.SourceAddress == task.SourceAddress && x.TaskState < TaskOutStatusEnum.SC_OutFinish.ObjToInt()) == null)
                        Sourcelocation.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    Sourcelocation.CurrentQty--;
                    if (Sourcelocation.CurrentQty <= 0)
                    {
                        Sourcelocation.CurrentQty = 0;
                        Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                        Sourcelocation.EnableStatus = EnableStatusEnum.Normal.ObjToInt();
                    }
                    _basicService.LocationInfoService.Repository.UpdateData(Sourcelocation);
                }
                if (outStockLockInfo != null)
                {
                    outStockLockInfo.Status = OutLockStockStatusEnum.出库中.ObjToInt();
                    _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo);
                }
                UpdateData(task);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// 更新出库任务状态完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent UpdateTaskStatusOutFinish(Dt_Task task)
        {
            try
            {
                Db.Ado.BeginTran();
                Dt_OutStockLockInfo? outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum && x.PalletCode == task.PalletCode);
                Dt_OutboundOrder? outboundOrder = null;
                Dt_OutboundOrderDetail? outboundOrderDetail = null;
                int overCount = 0;
                if (outStockLockInfo != null)
                {
                    outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfo.OrderDetailId);
                    if (outboundOrderDetail != null)
                    {
                        outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First();
                        if (outboundOrder != null)
                        {
                            outboundOrderDetail.OverOutQuantity++;
                            overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                            if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity)
                            {
                                var outboundOrderdetail = outboundOrder.Details.First(x => x.Id == outboundOrderDetail.Id);
                                outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                                outboundOrderdetail.OverOutQuantity = outboundOrderDetail.OverOutQuantity;
                                outboundOrderdetail.OrderDetailStatus = outboundOrderDetail.OrderDetailStatus;
                                overCount++;
                            }
                        }
                    }
                    outStockLockInfo.Status = OutLockStockStatusEnum.出库完成.ObjToInt();
                }
                if (outboundOrder != null && outboundOrder.Details.Count == overCount)
                {
                    outboundOrder.OrderStatus = OutboundStatusEnum.出库完成.ObjToInt();
                    _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(outboundOrder.Details, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    outboundOrder.Details = null;
                    _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                }
                else
                {
                    if (outboundOrderDetail != null)
                        _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetail);
                }
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                if (outStockLockInfo != null) _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// 更新移库任务状态完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent UpdateTaskStatusRelocationCarFinish(Dt_Task task)
        {
            try
            {
                Dt_LocationInfo Sourcelocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);//起始货位
                Dt_LocationInfo Targetlocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//目标货位
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//托盘库存
                Sourcelocation.CurrentQty--;
                //Targetlocation.CurrentQty++;
                stockInfo.LocationCode = Targetlocation.LocationCode;
                //stockInfo.SerialNumber = Targetlocation.CurrentQty;
                stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
                if (Sourcelocation.CurrentQty == 0) Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                Dt_Task _Task = BaseDal.QueryFirst(x => x.TaskNum != task.TaskNum && x.TaskType == task.TaskType && x.SourceAddress == Sourcelocation.LocationCode && x.TargetAddress == Targetlocation.LocationCode);
                if (_Task == null)
                {
                    if (Targetlocation.CurrentQty == Targetlocation.MaxQty) Targetlocation.LocationStatus = LocationStatusEnum.Fullload.ObjToInt();
                    else Targetlocation.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    if (Sourcelocation.CurrentQty == 0) Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                }
                task.CurrentAddress = task.NextAddress;
                task.NextAddress = string.Empty;
                task.ModifyDate = DateTime.Now;
                task.Modifier = "System";
                Db.Ado.BeginTran();
                _basicService.LocationInfoService.Repository.UpdateData(Sourcelocation);
                _basicService.LocationInfoService.Repository.UpdateData(Targetlocation);
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                //BaseDal.DeleteAndMoveIntoHty(task, OperateType.自动完成);
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                Db.Ado.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// 更新入库任务状态完成
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent NewUpdateTaskStatusInFinish(Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent().OK();
            try
            {
                Dt_InventoryInfo inventoryInfo = _inventoryInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
                if (inventoryInfo == null) return content.Error("未找到托盘信息");
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//货位
                if (locationInfo == null) return content.Error("未找到货位信息");
                if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())
                {
                    return content;
                }
                inventoryInfo.InDate = DateTime.Now;
                inventoryInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
                int beforeStatus = locationInfo.LocationStatus;
                if (BaseDal.QueryFirst(x => x.TargetAddress == locationInfo.LocationCode && x.TaskNum != task.TaskNum) == null)
                    locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                task.CurrentAddress = task.NextAddress;
                task.NextAddress = string.Empty;
 
                Dt_Inventory_Batch inventory_Batch = _inventoryBatchRepository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo);
                Db.Ado.BeginTran();
                if (inventory_Batch == null)
                {
                    inventory_Batch = new Dt_Inventory_Batch()
                    {
                        BatchNo = inventoryInfo.BatchNo,
                        BoxQuantity = inventoryInfo.BoxQuantity,
                        MaterielCode = inventoryInfo.MaterielCode,
                        MaterielName = inventoryInfo.MaterielName,
                        OutboundQuantity = inventoryInfo.OutboundQuantity,
                        StockQuantity = inventoryInfo.StockQuantity,
                        ProductionDate = inventoryInfo.ProductionDate,
                        ProductStatus = inventoryInfo.ProductStatus,
                        ShelfLife = inventoryInfo.ShelfLife,
                        ValidityPeriod = inventoryInfo.ValidityPeriod,
                        Creater = "System"
                    };
                    _inventoryBatchRepository.AddData(inventory_Batch);
                }
                else
                {
                    inventory_Batch.BoxQuantity = inventory_Batch.BoxQuantity + inventoryInfo.BoxQuantity;
                    inventory_Batch.StockQuantity = inventory_Batch.StockQuantity + inventoryInfo.StockQuantity;
                    _inventoryBatchRepository.UpdateData(inventory_Batch);
                }
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                _stockService.InventoryInfoService.Repository.UpdateData(inventoryInfo);
                Db.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
            }
            return content;
        }
        /// <summary>
        /// 更新入库任务状态完成
        /// </summary>
        /// <param name="WMStask"></param>
        /// <returns></returns>
        public WebResponseContent UpdateTaskStatusInFinish(Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent().OK();
            try
            {
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//组盘库存
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//货位
                var result = CheckCompleted(stockInfo, locationInfo);
                if (!result.Item1) throw new Exception(result.Item2);
 
 
                if (stockInfo.StockStatus != StockStatusEmun.入库中.ObjToInt()) throw new Exception($"托盘[{task.PalletCode}],该组盘状态不可入库");
                Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(x => x.StockId == stockInfo.Id);
 
                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.LocationCodesGetStockInfos(new List<string> { stockInfo.LocationCode }).Where(x => x.StockStatus == StockStatusEmun.已入库.ObjToInt()).ToList();
                if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())
                {
                    //stockInfo.SerialNumber = stockInfos.Count + 1;
                    stockInfo.InDate = DateTime.Now;
                    stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
                    stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt();
                    locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
                    task.CurrentAddress = task.NextAddress;
                    task.NextAddress = string.Empty;
                    Db.Ado.BeginTran();
                    BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                    _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                    Db.Ado.CommitTran();
                    return content;
                }
 
                Db.Ado.BeginTran();
                #region 入库单
                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
                if (inboundOrder != null)
                {
                    Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo && x.MaterielCode == stockInfoDetail.MaterielCode);
                    if (inboundOrderDetail != null)
                        inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
 
                    if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
                    {
                        inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
                    }
                    else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt())
                    {
                        inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
                    }
                    if (inboundOrder.OrderStatus != InboundStatusEnum.入库完成.ObjToInt())
                    {
                        _inboundService.InbounOrderService.Repository.UpdateData(inboundOrder);
                        if (inboundOrderDetail != null)
                            _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail);
                    }
                    else
                    {
                        List<Dt_InboundOrderDetail> orderDetails = inboundOrder.Details;
                        inboundOrder.Details = null;
                        _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.自动完成);
                        _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(orderDetails, OperateType.自动完成);
                    }
                }
 
                #endregion
                //stockInfo.SerialNumber = stockInfos.Count + 1;
                stockInfo.InDate = DateTime.Now;
                stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
                stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt();
                int beforeStatus = locationInfo.LocationStatus;
                locationInfo.LocationStatus = locationInfo.MaxQty - locationInfo.CurrentQty == 0 ? LocationStatusEnum.Fullload.ObjToInt() : LocationStatusEnum.InStock.ObjToInt();
                task.CurrentAddress = task.NextAddress;
                task.NextAddress = string.Empty;
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                Db.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
    }
}