1
wangxinhui
2025-06-10 2779947fe07c41250237437365f367b5a78a03b6
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
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.MES;
using WIDESEA_DTO.Task;
using WIDESEA_Model.Models;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        /// <summary>
        /// 申请入库任务(PDA使用,仅托盘绑定入库站台,不分配货位)
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent RequestInboundTask(SaveModel saveModel)
        {
            try
            {
                var palletCode = saveModel.MainData["barcode"].ToString();
                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
                var stationCode = saveModel.MainData["startPoint"].ToString();
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error($"未找到库区");
                }
 
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode && x.WarehouseId == warehouseId);
                if (task != null)
                {
                    return WebResponseContent.Instance.Error($"该托盘已生成任务");
                }
 
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && warehouse.WarehouseCode != WarehouseEnum.HA60.ToString())
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
 
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.PalletCode== palletCode).Includes(x=>x.Details).First();
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                }
                if (warehouseId != stockInfo.WarehouseId)
                {
                    return WebResponseContent.Instance.Error($"仓库不正确");
                }
                if (warehouse.WarehouseCode == WarehouseEnum.HA60.ToString())
                {
                    Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseId);
                    if (locationInfo == null) return WebResponseContent.Instance.Error($"未找到当前库区货位信息");
                    return DeviceRequestInboundTask(stationCode, locationInfo.RoadwayNo, palletCode);
                }
                else
                {
                    Dt_Task newTask = new Dt_Task()
                    {
                        CurrentAddress = stationCode,
                        Grade = 0,
                        NextAddress = "",
                        PalletCode = palletCode,
                        Roadway = "",
                        SourceAddress = stationCode,
                        TargetAddress = "",
                        TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfo.WarehouseId,
                        PalletType = stockInfo.PalletType,
                        MaterielCode = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode,
                        Quantity = (float)stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.StockQuantity,
                    };
                    //获取是否存在入库单
                    Dt_InboundOrder? inboundOrder =  null;
                    if (stockInfo!=null && stockInfo.Details.Count>0)
                    {
                        string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
                        inboundOrder =_inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.入库完成.ObjToInt());
                        if (inboundOrder!=null)
                        {
                            newTask.OrderNo = inboundOrder.InboundOrderNo;
                        }
                    }
                    
                    if (inboundOrder != null)
                    {
                        if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
                        {
                            newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
                            newTask.OrderNo = inboundOrder.InboundOrderNo;
                        }
                        else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
                        {
                            newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
                            newTask.OrderNo = inboundOrder.InboundOrderNo;
                        }
                    }
                    if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                    {
                        stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                    }
                    else if (stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt())
                    {
                        stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                        newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                    }
                    else
                    {
                        stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                    }
 
                    if (warehouse.WarehouseCode==WarehouseEnum.HA57.ToString())
                    {
                        Dt_Task dt_TaskMesReturn = BaseDal.QueryFirst(x=>x.TaskType==TaskTypeEnum.MesMatReturn.ObjToInt() && x.TaskStatus!=TaskStatusEnum.SC_Executing.ObjToInt());
                        if (dt_TaskMesReturn!=null)
                        {
                            return WebResponseContent.Instance.Error($"退料任务正执行");
                        }
                    }
                    _unitOfWorkManage.BeginTran();
                    int taskId = BaseDal.AddData(newTask);
                    newTask.TaskId = taskId;
                    _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                    _unitOfWorkManage.CommitTran();
                    PushTasksToWCS(new List<Dt_Task> { newTask });
                    return WebResponseContent.Instance.OK(data: newTask);
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 入空箱
        /// </summary>
        /// <param name="barcode"></param>
        /// <param name="address"></param>
        /// <param name="WarehouseId"></param>
        /// <returns></returns>
        public WebResponseContent InEmpty(string barcode, string address, int WarehouseId)
        {
            try
            {
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error($"未找到库区");
                }
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode && x.StockStatus != StockStatusEmun.出库完成.ObjToInt());
                if (stockInfo != null) throw new Exception($"托盘号已存在");
                stockInfo = new Dt_StockInfo()
                {
                    PalletCode = barcode,
                    StockStatus = StockStatusEmun.入库确认.ObjToInt(),
                    WarehouseId = WarehouseId,
                    PalletType = PalletTypeEnum.Empty.ObjToInt(),
                    Details = new List<Dt_StockInfoDetail>()
                };
                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == WarehouseId);
                if (locationInfo == null) return WebResponseContent.Instance.Error($"未找到当前库区货位信息");
                locationInfo = _basicService.LocationInfoService.AssignLocation(locationInfo.RoadwayNo, ((PalletTypeEnum)stockInfo.PalletType).ObjToInt(), stockInfo.WarehouseId);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
                }
 
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = address,
                    Grade = 0,
                    NextAddress = locationInfo.LocationCode,
                    PalletCode = barcode,
                    Roadway = locationInfo.RoadwayNo,
                    SourceAddress = address,
                    TargetAddress = locationInfo.LocationCode,
                    TaskType = TaskTypeEnum.InEmpty.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
                };
                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _basicRepository.LocationInfoRepository.UpdateData(locationInfo);
                _stockRepository.StockInfoRepository.AddData(stockInfo);
                _unitOfWorkManage.CommitTran();
                PushTasksToWCS(new List<Dt_Task> { newTask });
                PutFinish(address, newTask.PalletCode, newTask.TaskNum.ToString());
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="qty"></param>
        /// <param name="address"></param>
        /// <param name="WarehouseId"></param>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public WebResponseContent OutEmpty(int qty, string address, int WarehouseId, string barcode)
        {
            try
            {
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error($"未找到库区");
                }
                List<Dt_StockInfo> stockInfos = null;
                if (string.IsNullOrEmpty(barcode))
                {
                    stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.入库完成.ObjToInt(), qty, nameof(Dt_StockInfo.CreateDate));
                }
                else
                {
                    stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.入库完成.ObjToInt() && x.PalletCode == barcode);
                    if (stockInfos.Count == 0) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}未找到空箱【{barcode}】");
                }
 
                if (stockInfos.Count < qty) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}空箱库存不足,库存数【{stockInfos.Count}】");
                List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutEmpty);
                stockInfos.ForEach(x =>
                {
                    x.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                });
                tasks.ForEach(x =>
                {
                    x.TargetAddress = address;
                    x.NextAddress = address;
                });
                _unitOfWorkManage.BeginTran();
                BaseDal.AddData(tasks);
                _stockRepository.StockInfoRepository.UpdateData(stockInfos);
                _unitOfWorkManage.CommitTran();
                PushTasksToWCS(tasks);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="roadwayNo"></param>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTask(string stationCode, string roadwayNo, string palletCode,string materielBoxCode = "")
        {
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
 
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && stationCode != "8005")//辅料仓不限制入库任务
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                if (!string.IsNullOrEmpty(materielBoxCode))
                {
                    _unitOfWorkManage.BeginTran();
                    WebResponseContent responseGroup = _inboundOrderService.MaterielPPorGM(materielBoxCode);
                    if (!responseGroup.Status)
                    {
                        return WebResponseContent.Instance.Error($"{responseGroup.Message}");
                    }
                    Dt_StockInfo stockInfoPPorGM = responseGroup.Data as Dt_StockInfo ?? null;
                    if (stockInfoPPorGM==null)
                    {
                        return WebResponseContent.Instance.Error($"组盘数据转换失败");
                    }
                    Dt_LocationInfo? locationInfoPPorGM = _basicService.LocationInfoService.AssignLocation(roadwayNo, stockInfoPPorGM.PalletType, stockInfoPPorGM.WarehouseId);
                    if (locationInfoPPorGM == null)
                    {
                        return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
                    }
                    Dt_Task newTaskPPorGM = new Dt_Task()
                    {
                        CurrentAddress = stationCode,
                        Grade = 0,
                        NextAddress = locationInfoPPorGM.LocationCode,
                        PalletCode = stockInfoPPorGM.PalletCode,
                        Roadway = roadwayNo,
                        SourceAddress = stationCode,
                        TargetAddress = locationInfoPPorGM.LocationCode,
                        TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfoPPorGM.WarehouseId,
                        PalletType = stockInfoPPorGM.PalletType,
                        TaskLength= stockInfoPPorGM.StockLength
                    };
 
                    //获取是否存在入库单
                    Dt_InboundOrder? inboundOrderPPorGM = null;
                    if (stockInfoPPorGM != null && stockInfoPPorGM.Details.Count > 0)
                    {
                        string? orderNo = stockInfoPPorGM.Details.FirstOrDefault()?.OrderNo ?? "";
                        inboundOrderPPorGM = _inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.入库完成.ObjToInt());
                    }
 
                    if (inboundOrderPPorGM != null)
                    {
                        if (inboundOrderPPorGM.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
                        {
                            newTaskPPorGM.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
                        }
                        else if (inboundOrderPPorGM.OrderType == InOrderTypeEnum.Return.ObjToInt())
                        {
                            newTaskPPorGM.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
                        }
                    }
                    stockInfoPPorGM.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                    LocationStatusEnum lastStatusPPorGM = (LocationStatusEnum)locationInfoPPorGM.LocationStatus;
                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfoPPorGM, lastStatusPPorGM, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
                    _basicService.LocationInfoService.UpdateLocationStatus(locationInfoPPorGM, newTaskPPorGM.PalletType, LocationStatusEnum.Lock, newTaskPPorGM.WarehouseId);
                    int taskIdPPorGM = BaseDal.AddData(newTaskPPorGM);
                    newTaskPPorGM.TaskId = taskIdPPorGM;
                    _stockRepository.StockInfoRepository.Db.InsertNav(stockInfoPPorGM).Include(x => x.Details).ExecuteCommand();
                    _unitOfWorkManage.CommitTran();
                    WMSTaskDTO wMSTaskDTOPPorGM = _mapper.Map<WMSTaskDTO>(newTaskPPorGM);
 
                    PushTasksToWCS(new List<Dt_Task> { newTaskPPorGM });
                    return WebResponseContent.Instance.OK(data: wMSTaskDTOPPorGM);
                }
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                }
 
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, stockInfo.PalletType, stockInfo.WarehouseId);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
                }
 
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = locationInfo.LocationCode,
                    PalletCode = palletCode,
                    Roadway = roadwayNo,
                    SourceAddress = stationCode,
                    TargetAddress = locationInfo.LocationCode,
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType,
                };
 
                //获取是否存在入库单
                Dt_InboundOrder? inboundOrder = null;
                if (stockInfo != null && stockInfo.Details.Count > 0)
                {
                    string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
                    inboundOrder = _inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.入库完成.ObjToInt());
                }
 
                if (inboundOrder != null)
                {
                    if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
                    {
                        newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
                    }
                    else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
                    {
                        newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
                    }
                }
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES退库.ObjToInt())
                {
                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt())
                {
                    newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                }
                else
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                }
                
                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                _unitOfWorkManage.BeginTran();
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, newTask.PalletType, LocationStatusEnum.Lock, newTask.WarehouseId);
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                _unitOfWorkManage.CommitTran();
                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
 
                PushTasksToWCS(new List<Dt_Task> { newTask });
                if (newTask.WarehouseId == 5) PutFinish(stationCode.ToString(),newTask.PalletCode, newTask.TaskNum.ToString());
                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 仅申请任务,让WCS根据路由确定下一地址
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTaskSimple(string stationCode, string palletCode)
        {
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
 
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
 
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES空托退库.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                }
 
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = palletCode,
                    Roadway = "",
                    SourceAddress = stationCode,
                    TargetAddress = "",
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType,
                };
 
 
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES退库.ObjToInt())
                {
                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES空托退库.ObjToInt())
                {
                    //todo 小托盘暂时未启用
                    if (stockInfo.PalletType == PalletTypeEnum.MediumPallet.ObjToInt())
                    {
                        newTask.TaskType = TaskTypeEnum.MesPalletLargeReturn.ObjToInt();
                    }
                    else
                    {
                        newTask.TaskType = TaskTypeEnum.MesPalletSmallReturn.ObjToInt();
                    }
                }
                else
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                }
 
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                _unitOfWorkManage.CommitTran();
                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
 
                PushTasksToWCS(new List<Dt_Task> { newTask });
                if (newTask.WarehouseId == 5) PutFinish(stationCode, newTask.PalletCode, newTask.TaskNum.ToString());
                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="palletCode"></param>
        /// <param name="staions"></param>
        /// <param name="heightType"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTaskByRoadways(string stationCode, string palletCode, List<string> staions, int heightType)
        {
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
 
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
 
                string roadwayNo = AssignRoadwayNo(staions, palletCode, heightType);
 
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                }
 
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = palletCode,
                    Roadway = roadwayNo,
                    SourceAddress = stationCode,
                    TargetAddress = roadwayNo,
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType,
                };
 
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES退库.ObjToInt())
                {
                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
                }
                else
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                }
 
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                _unitOfWorkManage.CommitTran();
                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
 
                PushTasksToWCS(new List<Dt_Task> { newTask });
                //if (newTask.WarehouseId == 5) PutFinish(stationCode);
                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 入库任务申请分配货位
        /// </summary>
        /// <param name="taskNum">任务号</param>
        /// <param name="roadwayNo">巷道号</param>
        /// <returns></returns>
        public WebResponseContent AssignInboundTaskLocation(int taskNum, string roadwayNo)
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该入库任务");
                }
 
                if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null)
                {
                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
                }
                
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
                }
 
                task.Roadway = roadwayNo;
                task.TargetAddress = locationInfo.LocationCode;
                if (task.Roadway.Contains("AGV"))
                {
                    task.TaskStatus = TaskStatusEnum.AGV_Execute.ObjToInt();
                }
                else
                {
                    task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
                }
                
 
                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
 
                _unitOfWorkManage.BeginTran();
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
                BaseDal.UpdateData(task);
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK(data: locationInfo.LocationCode);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="taskNum"></param>
        /// <param name="roadwayNo"></param>
        /// <param name="heightType"></param>
        /// <returns></returns>
        public WebResponseContent AssignInboundTaskLocationByHeight(int taskNum, string roadwayNo, int heightType)
        {
            try
            {
                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
                if (task == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该入库任务");
                }
 
                if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null)
                {
                    return WebResponseContent.Instance.OK(data: task.TargetAddress);
                }
 
                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, heightType: heightType);
                if (locationInfo == null)
                {
                    return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位");
                }
 
                task.Roadway = roadwayNo;
                task.TargetAddress = locationInfo.LocationCode;
                task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt();
 
                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
 
                _unitOfWorkManage.BeginTran();
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
                BaseDal.UpdateData(task);
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK(data: locationInfo.LocationCode);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
 
        public WebResponseContent RequestZHInboundTask(string agvTaskCode, string palletCode, string palletType, string materialLot)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //获取测试架原库存信息
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA154.ToString());
                //获取库存记录
                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                  x.WarehouseId == warehouse.WarehouseId && x.PalletCode== palletCode).Includes(x => x.Details).ToList();
                if (stockInfos.Count > 0)
                {
                    return content.Error($"载具托盘已存在");
                }
                Dt_StockInfo? stockInfoOld = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == materialLot));
                if (stockInfoOld != null)
                {
                    return content.Error($"库存信息已存在");
                }
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x=>x.CodeStartStr== palletType);
                if (palletTypeInfo == null)
                {
                    return content.Error($"托盘类型信息不存在");
                }
                //获取阻焊批次
                WebResponseContent requestLotInfo = GetZHMesMaterialLot(materialLot);
                if (!requestLotInfo.Status)
                {
                    return content.Error($"请求阻焊批次信息失败,{requestLotInfo.Message}");
                }
                MesLotInfoModel mesLotInfo = JsonConvert.DeserializeObject<MesLotInfoModel>(requestLotInfo.Data.ToString());
                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                {
                    MaterielSpec = mesLotInfo.ProductVersion,
                    BatchNo = materialLot,
                    EffectiveDate = mesLotInfo.DateCode ?? " ",
                    MaterielCode = mesLotInfo.Product,
                    InboundOrderRowNo =  0,
                    MaterielName = mesLotInfo.Product,
                    ProductionDate = mesLotInfo.DateCode ?? " ",
                    OrderNo = "",
                    OutboundQuantity = 0,
                    SerialNumber = materialLot,
                    StockQuantity = (float)mesLotInfo.Qty,
                    Status = StockStatusEmun.入库确认.ObjToInt(),
                    Unit = "Lot",
                    Remark= mesLotInfo.IsFullNumber?"满Lot":"不满Lot"
                };
                Dt_StockInfo stockInfo = new Dt_StockInfo()
                {
                    PalletCode = palletCode,
                    PalletType = palletTypeInfo.PalletType,
                    WarehouseId = warehouse.WarehouseId,
                    StockStatus = StockStatusEmun.入库确认.ObjToInt(),
                    Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
                };
                
                //生成退库任务
                Dt_Task taskIn = new()
                {
                    CurrentAddress = "AGV_ZH",
                    Grade = 0,
                    PalletCode = palletCode,
                    NextAddress = "",
                    Roadway = "SC01_ZH",
                    SourceAddress = "AGV_ZH",
                    TargetAddress = "",
                    TaskStatus = (int)TaskStatusEnum.New,
                    TaskType = palletTypeInfo.LocaitonCount==2? (int)TaskTypeEnum.InZHProductLarge : (int)TaskTypeEnum.InZHProductSmall,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    PalletType = palletTypeInfo.PalletType,
                    WarehouseId = warehouse.WarehouseId
                };
                _unitOfWorkManage.BeginTran();
                Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
                BaseDal.AddData(taskIn);
                //BaseDal.AddData(task);
                _unitOfWorkManage.CommitTran();
                //将任务推送到WCS
                PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV_ZH"); ;
                content.OK(data: taskIn);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
 
        public readonly string[] OutStartPonits = { "5230", "5237", "5244" };
        /// <summary>
        /// 成品余料退库入仓
        /// </summary>
        /// <param name="barCode"></param>
        /// <param name="startPoint"></param>
        /// <returns></returns>
        public WebResponseContent BackProductTask(string barCode, string startPoint)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string palletCode = @"^C\d{5}$";  // 正则表达式
                bool isValid = Regex.IsMatch(barCode, palletCode);
                if (!isValid)
                {
                    return content.Error($"框码格式错误{barCode}");
                }
                if (!OutStartPonits.Contains(startPoint))
                {
                    return content.Error($"起点错误{startPoint}");
                }
                //判断当前点位是否重复
                Dt_Task taskOldPoint = BaseDal.QueryFirst(x=>x.SourceAddress==startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt()||x.TaskStatus==TaskStatusEnum.Line_Execute.ObjToInt()|| x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt() || x.TaskStatus == TaskStatusEnum.AGV_Takeing.ObjToInt()));
                if (taskOldPoint != null)
                {
                    return content.Error($"站点{startPoint}已存在任务");
                }
                Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode);
                if (taskOld != null)
                {
                    return content.Error($"胶框{barCode}任务已存在");
                }
                //获取胶框余料
                Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x=>x.PalletCode== barCode).Includes(x=>x.proStockInfoDetails).First();
                if (proStockInfo==null)
                {
                    return content.Error($"未找到{barCode}胶框信息");
                }
                if (proStockInfo.proStockInfoDetails==null || proStockInfo.proStockInfoDetails.Count<=0)
                {
                    return content.Error($"{barCode}胶框信息为空");
                }
                if (proStockInfo.StockStatus!=StockStatusEmun.出库完成.ObjToInt())
                {
                    return content.Error($"{barCode}胶框信息状态异常");
                }
                //获取成品平库
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
                if (proStockInfo.WarehouseId != warehouse.WarehouseId && proStockInfo.LocationCode!= "成品包装拣货区")
                {
                    return content.Error($"{barCode}胶框信息不在拣货区");
                }
                //获取当前的库存属性
                Dt_Warehouse? warePoint = null;
                switch (proStockInfo.ProStockAttribute)
                {
                    case (int)ProStockAttributeEnum.成品:
                        warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
                        break;
                    case (int)ProStockAttributeEnum.尾数:
                        warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA72.ToString());
                        break;
                    case (int)ProStockAttributeEnum.研发:
                        warePoint = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA73.ToString());
                        break;
                    default:
                        throw new Exception($"未找到{barCode}胶框信息库存属性");
                }
                Dt_Warehouse warehouseLocation = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
                Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseLocation.WarehouseId);
                if (locationInfo == null)
                {
                    return content.Error($"未找到{warehouse.WarehouseCode}货位信息");
                }
                proStockInfo.StockStatus = StockStatusEmun.成品余料回库.ObjToInt();
                proStockInfo.proStockInfoDetails.ForEach(x =>
                {
                    x.ProOutDetailStatus = StockStatusEmun.成品余料回库.ObjToInt();
                });
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = startPoint,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = proStockInfo.PalletCode,
                    Roadway = locationInfo.RoadwayNo,
                    SourceAddress = startPoint,
                    TargetAddress = "",
                    TaskType = TaskTypeEnum.InProductBack.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = warePoint.WarehouseId,
                    PalletType = proStockInfo.PalletType,
                    MaterielCode = proStockInfo.proStockInfoDetails.Where(x => x.ProStockId == proStockInfo.Id).FirstOrDefault()?.ProductCode,
                    Quantity = (float)proStockInfo.proStockInfoDetails.Where(x => x.ProStockId == proStockInfo.Id).Sum(x => x.StockPcsQty)
                };
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
                _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails);
                _unitOfWorkManage.CommitTran();
                //推送任务
                PushTasksToWCS(new List<Dt_Task> { newTask });
                content.OK("发送成功");
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// 空框回库
        /// </summary>
        public WebResponseContent EmptyBackTask(string barCode, string startPoint)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string palletCode = @"^C\d{5}$";  // 正则表达式
                bool isValid = Regex.IsMatch(barCode, palletCode);
                if (!isValid)
                {
                    return content.Error($"框码格式错误{barCode}");
                }
                if (!OutStartPonits.Contains(startPoint))
                {
                    return content.Error($"起点错误{startPoint}");
                }
                //判断当前点位是否重复
                Dt_Task taskOldPoint = BaseDal.QueryFirst(x => x.SourceAddress == startPoint && (x.TaskStatus == TaskStatusEnum.New.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Execute.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt()));
                //if (taskOldPoint != null)
                //{
                //    return content.Error($"站点{startPoint}已存在任务");
                //}
                Dt_Task taskOld = BaseDal.QueryFirst(x => x.PalletCode == barCode);
                if (taskOld != null)
                {
                    return content.Error($"胶框{barCode}任务已存在");
                }
                //if (_stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode) != null)
                //{
                //    return content.Error($"胶框{barCode}库存信息已存在");
                //}
                //todo:临时解绑
                Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode);
                if (_stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == barCode) != null)
                {
                    proStockInfo.PalletCode = proStockInfo.PalletCode + ":" + DateTime.Now.ToString("MM/dd");
                }
                //获取成品平库
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = startPoint,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = barCode,
                    Roadway = "CL01_CP",
                    SourceAddress = startPoint,
                    TargetAddress = "",
                    TaskType = TaskTypeEnum.EmptyProductBack.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = warehouse.WarehouseId,
                    PalletType = 1
                };
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                if (proStockInfo!=null)
                {
                    _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
                }
                newTask.TaskId = taskId;
                _unitOfWorkManage.CommitTran();
                //推送任务
                PushTasksToWCS(new List<Dt_Task> { newTask });
                content.OK("发送成功");
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}