1
wankeda
2 天以前 be438dd071400936c44a1425ec8d886f63c83329
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEA_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using MailKit.Search;
using Microsoft.AspNetCore.SignalR;
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_BasicRepository;
using WIDESEA_Common;
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_Core.TaskEnum;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Stock;
using WIDESEA_DTO.Task;
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;
        private readonly IPalletTypeInfoRepository _palletTypeInfoRepository;
        private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
        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, IOutboundOrderDetailRepository outboundOrderDetailRepository) : 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;
            _outboundOrderDetailRepository = outboundOrderDetailRepository;
        }
 
        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>
        /// 任务信息推送至WCS
        /// </summary>
        /// <returns></returns>
        public WebResponseContent PushTasksToWCS(List<Dt_Task> tasks, string agvDescription = "")
        {
            try
            {
                List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
                taskDTOs.ForEach(x =>
                {
                    x.AGVArea = agvDescription;
                });
                string url = AppSettings.app("WCS");
                if (string.IsNullOrEmpty(url))
                {
                    return WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件");
                }
                string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize());
 
                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误");
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// 放货完成
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public WebResponseContent PutFinish(string code)
        {
            try
            {
                string url = AppSettings.app("WCS");
                if (string.IsNullOrEmpty(url))
                {
                    return WebResponseContent.Instance.Error($"未找到WCSAApi地址,请检查配置文件");
                }
                string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish?code=" + code);
 
                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误");
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <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 UpdateTaskStatus(int taskNum, int tasktype)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskType == tasktype);
                if (task == null) return WebResponseContent.Instance.Error("未找到任务信息");
                if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.InboundGroup)
                {
                    task.TaskStatus = TaskInStatusEnum.InFinish.ObjToInt();
                    content = UpdateTaskStatusInFinish(task);
                }
            }
            catch (Exception)
            {
 
                throw;
            }
            return content;
        }
 
        public WebResponseContent UpdateTaskStatusInFinish(Dt_Task task)
        {
            WebResponseContent content = new WebResponseContent();
            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 == (int)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;
                }
                #region 入库单
                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
                if (inboundOrder != null || inboundOrder.Details.Count < 1) throw new Exception($"未找到托盘[{task.PalletCode}]的入库单明细信息");
                Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo && x.MaterielCode == stockInfoDetail.MaterielCode);
                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();
                }
                stockInfo.SerialNumber = stockInfos.Count + 1;
                stockInfo.InDate = DateTime.Now;
                stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
                stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                task.CurrentAddress = task.NextAddress;
                task.NextAddress = string.Empty;
                Db.Ado.BeginTran();
                #region 任务和入库单
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                if (inboundOrder.OrderStatus != InboundStatusEnum.入库完成.ObjToInt())
                {
                    _inboundService.InbounOrderService.Repository.UpdateData(inboundOrder);
                    _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
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                //_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
                Db.Ado.CommitTran();
                SendInboundInfoToWMS(task, inboundOrder, stockInfoDetail);
                #endregion
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
 
        /// <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, "成功");
        }
 
        #region 入库任务完成
        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();
                Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
 
                dt_StockInfo.LocationCode = dt_LocationInfo.LocationCode;
 
 
                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
                Dt_InboundOrderDetail? inboundOrderDetail = null;
 
                // 3. 处理入库逻辑
                return ProcessInbound(task, dt_StockInfo, dt_LocationInfo);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        private WebResponseContent ProcessInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo)
        {
            int lastStatus = locationInfo.LocationStatus;
            locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
 
            Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>()
                .Where(x => x.OrderNo == stockInfo.Details.FirstOrDefault().OrderNo)
                .Includes(x => x.Details)
                .First();
 
            if (inboundOrder == null) return WebResponseContent.Instance.Error("未找到入库单信息");
 
            Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details
                .FirstOrDefault(x => x.LinId == stockInfo.Details.FirstOrDefault()?.LinId);
 
            if (inboundOrder.OrderType == 0 && inboundOrder != null && stockInfo.StockStatus == StockStatusEmun.入库确认.ObjToInt())
            {
                //入库数量回传
                return ProcessNormalInbound(task, stockInfo, locationInfo, lastStatus, inboundOrder, inboundOrderDetail);
            }
            else
            {
                //调拨出入库任务数量回传
                return ProcessAllocateInbound(task, stockInfo, locationInfo, lastStatus, inboundOrder, inboundOrderDetail);
            }
        }
 
        private WebResponseContent ProcessNormalInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo,
            int lastStatus, Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
        {
            // 更新入库单明细状态
            UpdateInboundOrderDetails(stockInfo, inboundOrder, ref inboundOrderDetail);
 
            // 更新库存明细状态
            stockInfo.Details.ForEach(x => x.Status = StockStatusEmun.入库完成.ObjToInt());
 
            try
            {
                _unitOfWorkManage.BeginTran();
 
                // 更新任务状态
                UpdateTaskStatus(task);
 
                // 更新货位状态
                UpdateLocationStatus(locationInfo, lastStatus);
 
                // 更新库存信息
                UpdateStockInfo(stockInfo);
 
                // 添加记录
                AddRecords(task, stockInfo, locationInfo, lastStatus);
 
                // 更新入库单
                UpdateInboundOrder(inboundOrder, inboundOrderDetail);
 
                // 如果是最后一条明细,处理WMS回传
                if (inboundOrder.Details.Count == 1)
                {
                    var stockInfoDetail = stockInfo.Details.FirstOrDefault();
                    SendInboundInfoToWMS(task, inboundOrder, stockInfoDetail);
                }
 
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch
            {
                _unitOfWorkManage.RollbackTran();
                throw;
            }
        }
 
        private WebResponseContent ProcessAllocateInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo,
            int lastStatus, Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
        {
            // 如果是最后一条明细
            if (inboundOrder.Details.Count == 1)
            {
                try
                {
                    _unitOfWorkManage.BeginTran();
 
                    // 处理调拨入库单
                    //ProcessAllocateInboundOrder(inboundOrder, inboundOrderDetail);
 
                    // 获取相关库存信息
                    var relatedStockInfo = _stockService.StockInfoService.Repository
                        .QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo);
 
                    // 发送调拨信息到WMS
                    SendAllocateInfoToWMS(task, inboundOrder, relatedStockInfo);
 
                    _unitOfWorkManage.CommitTran();
                }
                catch
                {
                    _unitOfWorkManage.RollbackTran();
                    throw;
                }
            }
 
            // 添加历史记录
            AddInboundOrderDetailHistory(inboundOrderDetail);
 
            return WebResponseContent.Instance.OK();
        }
 
        #region Helper Methods
 
        private void UpdateInboundOrderDetails(Dt_StockInfo stockInfo, Dt_InboundOrder inboundOrder,
            ref Dt_InboundOrderDetail inboundOrderDetail)
        {
            int overCount = inboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
            inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.LinId == stockInfo.Details.FirstOrDefault()?.LinId);
 
            foreach (var item in stockInfo.Details)
            {
                if (inboundOrderDetail == null) continue;
 
                inboundOrderDetail.OverInQuantity += item.StockQuantity;
 
                if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
                {
                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                    overCount++;
                }
                else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
                {
                    inboundOrderDetail.OrderDetailStatus = InboundStatusEnum.入库中.ObjToInt();
                }
            }
        }
 
        private void UpdateTaskStatus(Dt_Task task)
        {
            task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateType.人工完成 : OperateType.自动完成);
        }
 
        private void UpdateLocationStatus(Dt_LocationInfo locationInfo, int lastStatus)
        {
            _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
        }
 
        private void UpdateStockInfo(Dt_StockInfo stockInfo)
        {
            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
            _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details);
        }
 
        private void AddRecords(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, int lastStatus)
        {
            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(
                locationInfo, lastStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
 
            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(
                stockInfo, stockInfo.Details,
                stockInfo.Details.Sum(x => x.StockQuantity),
                stockInfo.Details.Sum(x => x.StockQuantity),
                StockChangeType.Inbound, task.TaskNum);
        }
 
        private void UpdateInboundOrder(Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
        {
            if (inboundOrder != null)
            {
                _inboundService.InbounOrderService.UpdateData(inboundOrder);
                _inboundService.InboundOrderDetailService.UpdateData(inboundOrderDetail);
            }
        }
 
        private void SendInboundInfoToWMS(Dt_Task task, Dt_InboundOrder inboundOrder, Dt_StockInfoDetail stockInfoDetail)
        {
            if (stockInfoDetail == null) return;
 
            var houseInboundPassBack = new HouseInboundPassBack
            {
                ApiType = "AsnController",
                Method = "AsrsGroudingAsn",
                Parameters = new List<HouseInboundPassBack.data>
        {
            new HouseInboundPassBack.data
            {
                Value = new List<data.data1>
                {
                    new data.data1
                    {
                        AsnNo = task.OrderNo,
                        InWarehouse = task.Roadway,
                        TransactionCode = inboundOrder.TransactionCode,
                        InoutType = inboundOrder.OrderType,
                        OrderType = inboundOrder.InoutType,
                        DetailList = new List<data.data1.Inbound>
                        {
                            new data.data1.Inbound
                            {
                                LinId = stockInfoDetail.LinId,
                                MaterielCode = stockInfoDetail.MaterielCode,
                                OrderQuantity = stockInfoDetail.StockQuantity,
                                BatchNo = stockInfoDetail.BatchNo,
                                FinishQty = stockInfoDetail.StockQuantity,
                                LocationName = task.TargetAddress
                            }
                        }
                    }
                }
            }
        }
            };
 
            var authResult = AuthenticateWithWMS();
            if (authResult.IsSuccess)
            {
                houseInboundPassBack.Context = new Dictionary<string, string>
        {
            { "Ticket", authResult.Ticket },
            { "InvOrgId", authResult.InvOrgId }
        };
 
                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, houseInboundPassBack, "立库入库数量回传WMS");
            }
        }
 
        private void ProcessAllocateInboundOrder(Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
        {
            // 添加历史记录
            var history = new Dt_InboundOrder_Hty
            {
                OrderStatus = inboundOrder.OrderStatus,
                CreateType = inboundOrder.CreateType,
                UpperOrderNo = inboundOrder.UpperOrderNo,
                OrderNo = inboundOrder.OrderNo,
                TransactionCode = inboundOrder.TransactionCode,
                InoutType = inboundOrder.InoutType,
                OrderType = inboundOrder.OrderType,
                Creater = "WMS",
                CreateDate = DateTime.Now,
            };
            _inboundOrder_HtyService.AddData(history);
 
            // 添加明细历史记录
            var detailHistory = 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(detailHistory);
 
            // 删除原数据
            _inboundService.InbounOrderService.DeleteData(inboundOrder);
            _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
        }
 
        private void SendAllocateInfoToWMS(Dt_Task task, Dt_InboundOrder inboundOrder, List<Dt_StockInfo> stockInfos)
        {
 
            var detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfos.FirstOrDefault().Id);
            var inventoryAllocate = new InventoryAllocate
            {
                ApiType = "AsnController",
                Method = "AsrsGroudingAsn",
                Parameters = new List<InventoryAllocate.Allocate>
        {
             new InventoryAllocate.Allocate
            {
                Value = new List<Allocate.data1>
                {
                    new Allocate.data1
                    {
                        No = task.OrderNo,
                        InWarehouse = task.Roadway,
                        TransactionCode = inboundOrder.TransactionCode,
                        InoutType = inboundOrder.OrderType,
                        OrderType = inboundOrder.InoutType,
                        DetailList = new List<Allocate.data1.Inventory>
                        {
                            new Allocate.data1.Inventory
                            {
                                LinId = detail.LinId,
                                MaterielCode = detail.MaterielCode,
                                OrderQuantity = detail.StockQuantity,
                                BatchNo = detail.BatchNo,
                                FinishQty = detail.StockQuantity,
                                LocationName = task.TargetAddress
                            }
                        }
                    }
                }
            }
        }
            };
 
            var authResult = AuthenticateWithWMS();
            if (authResult.IsSuccess)
            {
                inventoryAllocate.Context = new Dictionary<string, string>
        {
            { "Ticket", authResult.Ticket },
            { "InvOrgId", authResult.InvOrgId }
        };
 
                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAllocatein, inventoryAllocate, "调拨入库数量回传WMS");
            }
        }
 
        private void AddInboundOrderDetailHistory(Dt_InboundOrderDetail inboundOrderDetail)
        {
            var history = 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(history);
            _inboundService.InboundOrderDetailService.DeleteData(inboundOrderDetail);
        }
 
        private (bool IsSuccess, string Ticket, string InvOrgId) AuthenticateWithWMS()
        {
            var authentication = new Authentication
            {
                ApiType = "AuthenticationController",
                Parameters = new List<Parameter>
        {
            new Parameter { Value = "LKAdmin" },
            new Parameter { Value = "LKAdmin" }
        },
                Method = "Login",
            };
 
            var response = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "登录WMS账号");
 
            if (response.Status && response.Context != null)
            {
                return (true, response.Context["Ticket"].ToString(), response.Context["InvOrgId"].ToString());
            }
 
            return (false, null, null);
        }
 
        #endregion
        #endregion
 
 
 
 
        #region//出库任务完成
        public WebResponseContent OutboundTaskCompleted(int taskNum)
        {
            try
            {
                // 1. 验证任务和获取基础数据
                var validationResult = ValidateAndGetBaseData(taskNum, out var task, out var stockInfo,
                    out var locationInfo, out var outStockLockInfos);
                if (!validationResult.Status) return validationResult;
 
                // 2. 处理出库订单详情
                var outboundOrderDetails = ProcessOutboundOrderDetails(outStockLockInfos);
 
                // 3. 执行核心出库逻辑
                return ExecuteOutboundLogic(task, stockInfo, locationInfo, outboundOrderDetails);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        #region 私有方法
 
        private WebResponseContent ValidateAndGetBaseData(int taskNum, out Dt_Task task,
            out Dt_StockInfo stockInfo, out Dt_LocationInfo locationInfo,
            out List<Dt_OutStockLockInfo> outStockLockInfos)
        {
            task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
            if (task == null)
            {
                stockInfo = null;
                locationInfo = null;
                outStockLockInfos = null;
                return WebResponseContent.Instance.Error("未找到任务信息");
            }
            var SourceAddress = task.SourceAddress;
            stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
            locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == SourceAddress);
            outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum);
 
            if (stockInfo == null) return WebResponseContent.Instance.Error("未找到库存信息");
            if (locationInfo == null) return WebResponseContent.Instance.Error("未找到货位信息");
            if (outStockLockInfos == null || outStockLockInfos.Count == 0)
                return WebResponseContent.Instance.Error("未找到出库详情信息");
 
            return WebResponseContent.Instance.OK();
        }
 
        private List<Dt_OutboundOrderDetail> ProcessOutboundOrderDetails(List<Dt_OutStockLockInfo> outStockLockInfos)
        {
            var outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
 
            foreach (var lockInfo in outStockLockInfos)
            {
                var detail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == lockInfo.OrderDetailId);
                if (detail != null)
                {
                    detail.OverOutQuantity = detail.LockQuantity;
                    if (detail.LockQuantity == detail.OrderQuantity)
                    {
                        detail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
                    }
                    outboundOrderDetails.Add(detail);
                }
            }
 
            return outboundOrderDetails;
        }
 
        private WebResponseContent ExecuteOutboundLogic(Dt_Task task, Dt_StockInfo stockInfo,
            Dt_LocationInfo locationInfo, List<Dt_OutboundOrderDetail> outboundOrderDetails)
        {
            try
            {
                _unitOfWorkManage.BeginTran();
 
                // 更新出库订单详情
                _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
 
                // 更新库存状态
                UpdateStockStatus(stockInfo, locationInfo);
 
                // 更新货位状态
                UpdateLocationStatus(locationInfo);
 
                // 处理任务完成
                CompleteTask(task);
 
                // 添加状态变更记录
                AddStatusChangeRecord(task, stockInfo, locationInfo);
 
                // 根据订单类型处理不同逻辑
                var outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
                    .Where(x => x.LPNNo == stockInfo.PalletCode).First();
                var outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>()
                    .Where(x => x.Id == outDetail.OrderId).Includes(x => x.Details).First();
 
                if (outboundOrder.OrderType == 1) // 普通出库
                {
                    ProcessNormalOutbound(task, stockInfo, outboundOrder, outDetail);
                }
                else if (outboundOrder.OrderType == 240) // 盘点出库
                {
                    // 盘点出库特殊处理逻辑
                }
                else // 调拨出库
                {
                    ProcessAllocateOutbound(task, stockInfo, outboundOrder, outDetail);
                }
 
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch
            {
                _unitOfWorkManage.RollbackTran();
                throw;
            }
        }
 
        private void UpdateStockStatus(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo)
        {
            stockInfo.LocationCode = locationInfo.LocationCode;
            stockInfo.StockStatus = StockStatusEmun.出库完成.ObjToInt();
            _stockService.StockInfoService.Repository.UpdateData(stockInfo);
        }
 
        private void UpdateLocationStatus(Dt_LocationInfo locationInfo)
        {
            int beforeStatus = locationInfo.LocationStatus;
            locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
            _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
        }
 
        private void CompleteTask(Dt_Task task)
        {
            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
        }
 
        private void AddStatusChangeRecord(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo)
        {
            _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(
                locationInfo,
                locationInfo.LocationStatus,
                StockChangeType.Outbound.ObjToInt(),
                stockInfo.Details.FirstOrDefault()?.OrderNo ?? "",
                task.TaskNum);
        }
 
        private void ProcessNormalOutbound(Dt_Task task, Dt_StockInfo stockInfo,
            Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outDetail)
        {
            var stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>()
                .Where(x => x.StockId == stockInfo.Id).First();
 
            if (outboundOrder.Details.Count == 1)
            {
                MoveOutboundOrderToHistory(outboundOrder);
            }
 
            MoveOutboundDetailToHistory(outDetail);
 
            // 发送出库信息到WMS
            SendNormalOutboundToWMS(task, outboundOrder, stockInfoDetail, outDetail);
 
            // 删除库存信息
            DeleteStockInfo(stockInfo);
        }
 
        private void ProcessAllocateOutbound(Dt_Task task, Dt_StockInfo stockInfo,
            Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail outDetail)
        {
            var relatedStockInfos = _stockService.StockInfoService.Repository.QueryData(x => x.BatchNo == outDetail.BatchNo);
 
            if (outboundOrder.Details.Count == 1)
            {
                MoveOutboundOrderToHistory(outboundOrder);
            }
 
            MoveOutboundDetailToHistory(outDetail);
 
            // 发送调拨出库信息到WMS
            SendAllocateOutboundToWMS(task, outboundOrder, outDetail, relatedStockInfos);
 
            // 删除库存信息
            DeleteStockInfo(stockInfo);
        }
 
        private void MoveOutboundOrderToHistory(Dt_OutboundOrder outboundOrder)
        {
            var history = new Dt_OutboundOrder_Hty
            {
                OrderStatus = outboundOrder.OrderStatus,
                CreateType = outboundOrder.CreateType,
                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(history);
            _outboundService.OutboundOrderService.DeleteData(outboundOrder);
        }
 
        private void MoveOutboundDetailToHistory(Dt_OutboundOrderDetail outDetail)
        {
            var detailHistory = new Dt_OutboundOrderDetail_Hty
            {
                OrderId = outDetail.OrderId,
                MaterielCode = outDetail.MaterielCode,
                MaterielName = outDetail.MaterielName,
                BatchNo = outDetail.BatchNo,
                OrderQuantity = outDetail.OrderQuantity,
                OrderDetailStatus = outDetail.OrderDetailStatus,
                Creater = "WMS",
                CreateDate = DateTime.Now,
            };
            _outboundOrderDetail_HtyService.AddData(detailHistory);
            _outboundService.OutboundOrderService.DeleteData(outDetail);
        }
 
        private void SendNormalOutboundToWMS(Dt_Task task, Dt_OutboundOrder outboundOrder,
            Dt_StockInfoDetail stockInfoDetail, Dt_OutboundOrderDetail outDetail)
        {
            var passBack = new HouseoutboundPassBack
            {
                ApiType = "ShippingOrderController",
                Method = "AsrsOutboundSO",
                Parameters = new List<HouseoutboundPassBack.datas>
        {
            new HouseoutboundPassBack.datas
            {
                Value = new List<HouseoutboundPassBack.datas.data1>
                {
                    new HouseoutboundPassBack.datas.data1
                    {
                        No = outboundOrder.OrderNo,
                        OutWareHouse = task.Roadway,
                        TransactionCode = outboundOrder.TransactionCode,
                        InoutType = outboundOrder.OrderType,
                        OrderType = outboundOrder.InoutType,
                        DetailList = new List<HouseoutboundPassBack.datas.data1.Inbound>
                        {
                            new HouseoutboundPassBack.datas.data1.Inbound
                            {
                                LinId = outDetail.LinId,
                                LPN_No = task.PalletCode,
                                MaterielCode = stockInfoDetail.MaterielCode,
                                OrderQuantity = stockInfoDetail.OutboundQuantity,
                                BatchNo = stockInfoDetail.BatchNo,
                                FinishQty = stockInfoDetail.OutboundQuantity,
                                LocationName = task.SourceAddress
                            }
                        }
                    }
                }
            }
        }
            };
 
            var authResult = AuthenticateWithWMS();
            if (authResult.IsSuccess)
            {
                passBack.Context = new Dictionary<string, string>
        {
            { "Ticket", authResult.Ticket },
            { "InvOrgId", authResult.InvOrgId }
        };
 
                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, passBack, "立库入库数量回传WMS");
            }
        }
 
        private void SendAllocateOutboundToWMS(Dt_Task task, Dt_OutboundOrder outboundOrder,
            Dt_OutboundOrderDetail outDetail, List<Dt_StockInfo> stockInfos)
        {
            var allocate = new InventoryAllocate
            {
                ApiType = "InventoryAllocateController",
                Method = "AsrsFinishedStockCount",
                Parameters = new List<Allocate>
        {
            new Allocate
            {
                Value = new List<Allocate.data1>
                {
                    new Allocate.data1
                    {
                        No = outboundOrder.OrderNo,
                        InWarehouse = task.Roadway,
                        TransactionCode = outboundOrder.TransactionCode,
                        InoutType = outboundOrder.OrderType,
                        OrderType = outboundOrder.InoutType,
                        DetailList = stockInfos.Select(item =>
                        {
                            var detail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == item.Id);
                            return new Allocate.data1.Inventory
                            {
                                LinId = outDetail.LinId,
                                LPN_No = item.PalletCode,
                                MaterielCode = detail.MaterielCode,
                                OrderQuantity = detail.OutboundQuantity,
                                BatchNo = detail.BatchNo,
                                FinishQty = detail.OutboundQuantity,
                                LocationName = task.SourceAddress
                            };
                        }).ToList()
                    }
                }
            }
        }
            };
 
            var authResult = AuthenticateWithWMS();
            if (authResult.IsSuccess)
            {
                allocate.Context = new Dictionary<string, string>
        {
            { "Ticket", authResult.Ticket },
            { "InvOrgId", authResult.InvOrgId }
        };
 
                HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, allocate, "立库入库数量回传WMS");
            }
        }
 
        private void DeleteStockInfo(Dt_StockInfo stockInfo)
        {
            _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo,
                App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
            _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details,
                App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
        }
 
        #endregion
        #endregion
 
 
 
 
 
        #region
        //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();
        //        Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == task.WarehouseId);
 
        //        dt_StockInfo.LocationCode = dt_LocationInfo.LocationCode;
 
 
        //        Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
        //        Dt_InboundOrderDetail? inboundOrderDetail = null;
        //        //判断单据类型是入库还是调拨入库。。。入库
        //        if (inboundOrder.OrderType == 0 && inboundOrder != null && dt_StockInfo.StockStatus == StockStatusEmun.入库确认.ObjToInt())
        //        {
        //            #region //判断入库单据明细只有最后一条完成时删除入库单
        //            //查询原完成的入库明细数量
        //            int overCount = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
        //            //明细id查询
        //            inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.LinId == dt_StockInfo.Details.FirstOrDefault()?.LinId);
        //            foreach (var item in dt_StockInfo.Details)
        //            {
        //                if (inboundOrderDetail == null)
        //                {
        //                    continue;
        //                }
        //                inboundOrderDetail.OverInQuantity += item.StockQuantity;
        //                if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
        //                {
        //                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
        //                    overCount += 1;
        //                }
        //                else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
        //                {
        //                    inboundOrderDetail.OrderDetailStatus = InboundStatusEnum.入库中.ObjToInt();
        //                }
        //            }
        //            dt_StockInfo.Details.ForEach(x =>
        //            {
        //                x.Status = StockStatusEmun.入库完成.ObjToInt();
        //            });
 
        //            _unitOfWorkManage.BeginTran();
        //            task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
        //            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, task.TaskNum);
        //            if (inboundOrder != null)
        //            {
        //                _inboundService.InbounOrderService.UpdateData(inboundOrder);
        //                _inboundService.InboundOrderDetailService.UpdateData(inboundOrderDetail);
        //            }
        //            _unitOfWorkManage.CommitTran();
 
 
 
 
        //            if (inboundOrder.Details.Count == 1)
        //            {
        //                var stockInfoDetail = dt_StockInfo.Details.FirstOrDefault();
 
        //                #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);
        //    }
        //}
        #endregion
        #region
        //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);
        //    }
        //}
        #endregion
    }
}