wangxinhui
2024-09-23 a3eb67538c4716aef9967f1e6301720cce095e3c
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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Policy;
using System.Text;
using System.Threading;
using WIDESEA_Common;
using WIDESEA_Common.LoctionEnum;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.DomainModels.CacheTask;
using WIDESEA_Entity.DomainModels.CacheTask.WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.materielinfo;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
namespace WIDESEA_Services.Services
{
 
    public class PdaWorkService
    {
        /// <summary>
        /// pda入库
        /// </summary>
        public static WebResponseContent Warehousing(SaveModel saveModel)
        {
 
            #region MyRegion
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            Idt_containerRepository containerRepository = new dt_containerRepository(Context);
            IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
            Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
            Ibase_ware_locationRepository ibase_Ware_Location = new base_ware_locationRepository(Context);
            try
            {
                //File.ReadAllText(Environment.CurrentDirectory); 表示获取当前
 
                var hcgnmmjsondata = File.ReadAllText(Directory.GetCurrentDirectory() + @"/Database/HcgNumdata.json");
                List<HCGNumeData> HCGNUM = JsonConvert.DeserializeObject<List<HCGNumeData>>(hcgnmmjsondata);
                string csn = saveModel.MainData["csn"].ToString();
                HCGNumeData NUMJSON = HCGNUM.Where(d => d.num == csn).FirstOrDefault();
                if (NUMJSON == null)
                {
                    return content.Error($"缓存柜编号中不存在:{csn},无法入库,请检查");
                }
                VV_ContainerInfo containerInfo = VV_ContainerInfoRepository.FindFirst(d => d.container_sn == saveModel.MainData["csn"].ToString());
                if (containerInfo != null)
                {
                    return content.Error($"当前缓存柜:{containerInfo.container_sn},已入库在货位地标:{containerInfo.L_Code}");
                }
                VV_ContainerInfo containerInfo2 = VV_ContainerInfoRepository.FindFirst(d => d.L_Code == saveModel.MainData["cnum"].ToString());
                if (containerInfo2 != null)
                {
                    return content.Error($"当前货位地标:{containerInfo2.L_Code},已被缓存柜:{containerInfo2.container_sn} 占用");
                }
                string code = saveModel.MainData["cnum"].ToString();
                base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == code);
                if (pda_Location != null)
                {
                    if (pda_Location.L_Type != "1F-QJHCG")
                    {
                        if (pda_Location.L_state == LoctionStateEnum.LocationState_Empty.ToString())
                        {
 
                            if (pda_Location.L_Task == 1)
                            {
                                return content.Error($"当前货位地标:{saveModel.MainData["cnum"].ToString()},已存在任务,请检查");
                            }
                            dt_materielinfo materielinfo = materielinfoRepository.FindFirst(d => d.materiel_id == saveModel.MainData["ctype"].ToString());
                            if (materielinfo != null)
                            {
                                dt_container dt_Container = new dt_container()
                                {
                                    container_id = Guid.NewGuid(),
                                    container_sn = saveModel.MainData["csn"].ToString(),
                                    container_barcode = saveModel.MainData["cnum"].ToString(),
                                    container_materielid = saveModel.MainData["ctype"].ToString(),
                                    container_state = saveModel.MainData["cstate"].ToString(),
                                    container_creator = "WCS",
                                    container_createtime = DateTime.Now
                                };
                                containerRepository.Add(dt_Container, true);
                                pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString();
                                ibase_Ware_Location.Update(pda_Location, true);
                                return content.OK($"缓存柜【{saveModel.MainData["csn"]}】入库完成");
                            }
                        }
                        else
                        {
                            return content.Error($"当前货位地标:{pda_Location.L_Code},货位状态不是空货位,无法入库,请检查");
                        }
 
                    }
                    else
                    {
                        //扫描的货位地标编号异常,不是二楼辅材的货位地标,无法入库
                        return content.Error($"当前货位地标:{pda_Location.L_Code},不是二楼辅材库货位,无法入库");
                    }
                }
 
                else
                {
                    return content.Error($"系统未找到pda扫码的货位地标:{saveModel.MainData["cnum"]},请检查");
                }
                return content;
            }
            catch (Exception ex)
            {
 
                return content.Error(ex.Message);
            }
            #endregion
        }
 
 
 
        /// <summary>
        /// 回流呼叫
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent RefluxCall(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            Idt_containerRepository containerRepository = new dt_containerRepository(Context);
            IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
            Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
            Ibase_ware_locationRepository ibase_Ware_Location = new base_ware_locationRepository(Context);
            try
            {
                //Console.WriteLine(AppContext.BaseDirectory);
                var hcgnmmjsondata = File.ReadAllText(AppContext.BaseDirectory + "/Database/HcgNumdata.json", Encoding.UTF8);
               // var hcgnmmjsondata = File.ReadAllText(Directory.GetCurrentDirectory() + @"/Database/HcgNumdata.json");
                List<HCGNumeData> HCGNUM = JsonConvert.DeserializeObject<List<HCGNumeData>>(hcgnmmjsondata);
                string csn = saveModel.MainData["csn"].ToString();
                HCGNumeData NUMJSON = HCGNUM.Where(d => d.num == csn).FirstOrDefault();
                if (NUMJSON == null)
                {
                    return content.Error($"缓存柜编号中不存在:{csn},无法回流,请检查");
                }
 
                VV_ContainerInfo containerInfo = VV_ContainerInfoRepository.FindFirst(d => d.L_Code == csn);
                if (containerInfo != null)
                {
                    return content.Error($"当前缓存柜:{csn},存在库存,请检查");
 
                }
                base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == saveModel.MainData["cnum"].ToString());
                if (pda_Location != null)
                {
                    string QJHCG = "1F-QJHCG";
                    string RKFCHCG = "1F-RKFCHCG";
                    if (pda_Location.L_Type == QJHCG || pda_Location.L_Type == RKFCHCG)
                    //if (pda_Location.L_Type == "1F-GMHCG1" || pda_Location.L_Type == "1F-QJHCG2" || pda_Location.L_Type == "1F-GMHCG3")
                    {
                        if (pda_Location.L_state == LoctionStateEnum.LocationState_Stored.ToString())
                        {
                            if (pda_Location.L_Task == 2)
                            {
                                dt_agvtask agvtaskfind = agvRepository.FindFirst(d => d.agv_fromaddress == saveModel.MainData["cnum"].ToString() || d.agv_toaddress == saveModel.MainData["cnum"].ToString());
                                if (agvtaskfind != null)
                                {
                                    return content.Error($"当前货位地标:{pda_Location.L_Code},已存在任务,请检查");
                                }
                                base_pda_location pda_Location2 = pdaloctionRepository.FindFirst(d => d.L_state == LoctionStateEnum.LocationState_Empty.ToString() && d.L_Type == "2F-FLKHCG"  && d.L_Status == 1 && d.L_Task == 2);
                                if (pda_Location2 == null)
                                {
                                    return content.Error($"二楼库房空柜区没有空位了,无法回流,请检查");
                                }
                                //生成空箱回流任务
                                dt_agvtask agvtask = new dt_agvtask()
                                {
                                    agv_id = Guid.NewGuid(),
                                    agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                    agv_fromaddress = pda_Location.L_Code,//以设备未起点
                                    agv_toaddress = pda_Location2.L_Code,
                                    agv_code = "组装AGV调度",
                                    agv_remark = "PDA回流任务",
                                    agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                                    agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
                                    agv_worktype = 1,//工作类型
                                    agv_materielid = "",
                                    agv_qty = 1,
                                    agv_createtime = DateTime.Now,
                                    agv_grade = 0,//任务优先级
                                    agv_userid = "WCS",
                                    agv_barcode = csn,
                                };
                                agvRepository.Add(agvtask, true);
 
                                pda_Location2.L_Task = 1;
                                ibase_Ware_Location.Update(pda_Location2, true);
                                pda_Location.L_Task = 1;
                                ibase_Ware_Location.Update(pda_Location, true);
                                return content.OK($"回流成功");
                            }
                            else
                            {
                                return content.Error($"当前货位地标:{pda_Location.L_Code},货位存在任务:{pda_Location.L_Task},无法叫料,请检查");
                            }
 
                        }
                        else
                        {
                            return content.Error($"当前货位地标:{pda_Location.L_Code},货位状态不是有货位,无法回流,请检查");
                        }
                    }
                    else
                    {
                        //扫描的货位地标编号异常,不是二楼辅材的货位地标,无法入库
                        return content.Error($"当前货位地标:{pda_Location.L_Code},不是切卷机缓存柜货位,无法回流");
                    }
                }
                else
                {
                    return content.Error($"系统未找到pda扫码的货位地标:{saveModel.MainData["cnum"]},请检查");
                }
 
 
                return content;
            }
            catch (Exception ex)
            {
 
                return content.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 产线叫料
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent ProductCall(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            Idt_containerRepository containerRepository = new dt_containerRepository(Context);
            IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
            Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_ware_locationRepository ibase_Ware_Location = new base_ware_locationRepository(Context);
            try
            {
                //产线边是否有缓存柜
                VV_ContainerInfo containerInfo = VV_ContainerInfoRepository.FindFirst(d => d.L_Code == saveModel.MainData["cnum"].ToString());
                if (containerInfo != null)
                {
                    return content.Error($"当前货位地标:{containerInfo.L_Code},已被缓存柜:{containerInfo.container_sn} 占用,请检查");
                }
 
                base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == saveModel.MainData["cnum"].ToString());
                if (pda_Location != null)
                {
                    string QJHCG = "1F-QJHCG";
                    string RKFCHCG = "1F-RKFCHCG";
                    if (pda_Location.L_Type == QJHCG || pda_Location.L_Type == RKFCHCG)
                    {
 
                        if (pda_Location.L_state == LoctionStateEnum.LocationState_Empty.ToString())
                        {
                            if (pda_Location.L_Task == 2)
                            {
                                dt_materielinfo materielinfo = materielinfoRepository.FindFirst(d => d.materiel_id == saveModel.MainData["ctype"].ToString());
                              
                                if (materielinfo != null)
                                {
                                    VV_ContainerInfo containerInfo2 = VV_ContainerInfoRepository.FindFirst(d => d.materiel_id == saveModel.MainData["ctype"].ToString() && d.L_Type == saveModel.MainData["ckf"].ToString() && d.L_Task == 2 && d.L_state == LoctionStateEnum.LocationState_Stored.ToString() && d.L_Status == 1);
           
                                    if (containerInfo2 == null)
                                    {
                                        return content.Error($"您当前选择的库房没有库存了");
                                    }
 
                                    //生成产线叫料任务
                                    dt_agvtask agvtask = new dt_agvtask()
                                    {
                                        agv_id = Guid.NewGuid(),
                                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                        agv_fromaddress = containerInfo2.L_Code,//以设备未起点
                                        agv_toaddress = pda_Location.L_Code,
                                        agv_code = "组装AGV调度",
                                        agv_remark = "PDA产线叫料任务",
                                        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                                        agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
                                        agv_worktype = 1,//工作类型
                                        agv_materielid = materielinfo.materiel_id,
                                        agv_qty = 1,
                                        agv_createtime = DateTime.Now,
                                        agv_grade = 0,//任务优先级
                                        agv_userid = "WCS",
                                        agv_barcode = containerInfo2.container_sn,
                                    };
                                
                                    agvRepository.Add(agvtask, true);
                                    base_pda_location pda_LocationTo = pdaloctionRepository.FindFirst(d => d.L_Code == containerInfo2.L_Code);
                                    if (pda_LocationTo == null)
                                    {
                                   
                                        throw new NotImplementedException();
                                    }
                                    pda_LocationTo.L_Task = 1;
                                    ibase_Ware_Location.Update(pda_LocationTo, true);
                                    pda_Location.L_Task = 1;
                                    ibase_Ware_Location.Update(pda_Location, true);
                                    return content.OK($"叫料成功");
                                }
                                else {
                                    return content.Error($"当前pda输入的物料类型:{saveModel.MainData["ctype"].ToString()},WCS后台物料管理中不存在,请检查");
                                }
                            }
                            else
                            {
                                return content.Error($"当前货位地标:{pda_Location.L_Code},货位存在任务:{pda_Location.L_Task},无法叫料,请检查");
                            }
 
                        }
                        else
                        {
                            return content.Error($"当前货位地标:{pda_Location.L_Code},货位状态不是空货位,无法入库,请检查");
                        }
 
                    }
                    else
                    {
                        //扫描的货位地标编号异常,不是二楼辅材的货位地标,无法入库
                        return content.Error($"当前货位地标:{pda_Location.L_Code},不是产线叫料地标区货位,无法产线叫料");
                    }
                }
                else
                {
                    return content.Error($"系统未找到pda扫码的货位地标:{saveModel.MainData["cnum"]},请检查");
                }
 
 
 
            }
            catch (Exception ex)
            {
 
                return content.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 库房叫料
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent StoreroomCall(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            Idt_containerRepository containerRepository = new dt_containerRepository(Context);
            IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
            Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
 
            try
            {
                string cnum = saveModel.MainData["cnum"].ToString();//货物二维码(货位编号)
                VV_ContainerInfo containerInfo = VV_ContainerInfoRepository.FindFirst(d => d.L_Code == saveModel.MainData["cnum"].ToString());
                if (containerInfo != null)
                {
                    return content.Error($"当前货位地标:{containerInfo.L_Code},已被缓存柜:{containerInfo.container_sn} 占用,请检查");
 
                }
 
 
                base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == saveModel.MainData["cnum"].ToString());
                if (pda_Location != null)
                {
                    if (pda_Location.L_Type == "1F-GMHCG1" || pda_Location.L_Type == "1F-GMHCG2" || pda_Location.L_Type == "1F-GMHCG3")
                    {
                        if (pda_Location.L_state == LoctionStateEnum.LocationState_Empty.ToString())
                        {
                            if (pda_Location.L_Task == 2)
                            {
                                dt_agvtask agvtaskfind = agvRepository.FindFirst(d => d.agv_fromaddress == saveModel.MainData["cnum"].ToString() || d.agv_toaddress == saveModel.MainData["cnum"].ToString());
                                if (agvtaskfind != null)
                                {
                                    return content.Error($"当前货位地标:{containerInfo.L_Code},已存在任务,请检查");
                                }
                                dt_materielinfo materielinfo = materielinfoRepository.FindFirst(d => d.materiel_id == saveModel.MainData["ctype"].ToString());
                                if (materielinfo != null)
                                {
                                    VV_ContainerInfo containerInfo2 = VV_ContainerInfoRepository.FindFirst(d => d.materiel_id == saveModel.MainData["ctype"].ToString() && d.L_Type == "2F-FLHCG" && d.L_Task == 2 && d.L_state == LoctionStateEnum.LocationState_Stored.ToString() && d.L_Status == 1);
                                    if (containerInfo2 == null)
                                    {
                                        return content.Error($"二楼库房没有库存了");
                                    }
 
                                    //生成库房叫料任务
                                    dt_agvtask agvtask = new dt_agvtask()
                                    {
                                        agv_id = Guid.NewGuid(),
                                        agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
                                        agv_fromaddress = containerInfo2.L_Code,//以设备未起点
                                        agv_toaddress = pda_Location.L_Code,
                                        agv_code = "组装AGV调度",
                                        agv_remark = "PDA库房叫料任务",
                                        agv_taskstate = AGVTaskStateEnum.Create.ToString(),
                                        agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
                                        agv_worktype = 1,//工作类型
                                        agv_materielid = materielinfo.materiel_id,
                                        agv_qty = 1,
                                        agv_createtime = DateTime.Now,
                                        agv_grade = 0,//任务优先级
                                        agv_userid = "WCS",
                                        agv_barcode = containerInfo2.container_sn,
                                    };
                                    agvRepository.Add(agvtask, true);
                                    base_pda_location pda_LocationTo = pdaloctionRepository.FindFirst(d => d.L_Code == containerInfo2.L_Code);
                                    if (pda_LocationTo == null)
                                    {
                                        throw new NotImplementedException();
                                    }
                                    pda_LocationTo.L_Task = 1;
                                    pdaloctionRepository.Update(pda_LocationTo, true);
                                    pda_Location.L_Task = 1;
                                    pdaloctionRepository.Update(pda_Location, true);
                                    return content.OK($"叫料完成");
                                }
                                else
                                {
                                    return content.Error($"当前pda输入的物料类型:{saveModel.MainData["ctype"].ToString()},WCS后台物料管理中不存在,请检查");
                                }
                            }
                            else
                            {
                                return content.Error($"当前货位地标:{pda_Location.L_Code},货位存在任务:{pda_Location.L_Task},无法叫料,请检查");
                            }
 
                        }
                        else
                        {
                            return content.Error($"当前货位地标:{pda_Location.L_Code},货位状态不是空货位,无法入库,请检查");
                        }
 
                    }
                    else
                    {
                        //扫描的货位地标编号异常,不是二楼辅材的货位地标,无法入库
                        return content.Error($"当前货位地标:{pda_Location.L_Code},不是二楼辅材库货位,无法入库");
                    }
                }
                else
                {
                    return content.Error($"系统未找到pda扫码的货位地标:{saveModel.MainData["cnum"]},请检查");
                }
                return content;
            }
            catch (Exception ex)
            {
 
                return content.Error(ex.Message);
            }
        }
 
 
        /// <summary>
        /// 库存解绑
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent ReleaseStock(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            Idt_containerRepository containerRepository = new dt_containerRepository(Context);
            IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
            Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            try
            {
                //var hcgnmmjsondata = File.ReadAllText(Directory.GetCurrentDirectory() + @"/Database/HcgNumdata.json");
                Console.WriteLine(AppContext.BaseDirectory); 
                string hcgnmmjsondata = File.ReadAllText(AppContext.BaseDirectory + "/Database/HcgNumdata.json", Encoding.UTF8);
            
                List<HCGNumeData> HCGNUM = JsonConvert.DeserializeObject<List<HCGNumeData>>(hcgnmmjsondata);
            
                string csn = saveModel.MainData["barcode"].ToString();
            
                HCGNumeData NUMJSON = HCGNUM.Where(d => d.num == csn).FirstOrDefault();
            
                if (NUMJSON == null)
                {
                    return content.Error($"缓存柜编号中不存在:{csn},无法解绑,请检查");
                }
                VV_ContainerInfo containerInfo = VV_ContainerInfoRepository.FindFirst(d => d.container_sn == saveModel.MainData["barcode"].ToString());
        
                if (containerInfo == null)
                {
                    return content.Error($"未找到缓存柜条码【{saveModel.MainData["barcode"].ToString()}】的库存,请检查");
                }
                dt_container dt_Container = containerRepository.FindFirst(d => d.container_id == Guid.Parse(containerInfo.container_id.ToString()));
            
                if (dt_Container == null)
                {
                    return content.Error($"库存查询异常");
                }
                base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == containerInfo.container_barcode);
                if (pda_Location == null)
                {
                    return content.Error($"当前库存的货位地标【{containerInfo.container_barcode}】 在PDA货位列表中不存在,数据异常,请检查");
                }
                if (pda_Location.L_Task == 1)
                {
                    return content.Error($"当前库存存在AGV任务,无法解绑,请检查");
                }
                if (pda_Location.L_Type.Contains("2F-FL") )
                {
                    pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString();
                    int a = pdaloctionRepository.Update(pda_Location,d=>new { d.L_state }, true);
                    if (a != 1)
                    {
                        return content.Error($"库存货位初始化失败");
                    }
                    containerRepository.Delete(dt_Container, true);
                }
                else
                {
                    //pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString();
                    //int a = pdaloctionRepository.Update(pda_Location, true);
                    //if (a != 1)
                    //{
                        return content.Error($"当前货位地标【{pda_Location.L_Code}】不是2F的货位,无法解绑,请检查");
                    //}
                }
             
             
             
                return content.OK($"缓存柜【{saveModel.MainData["barcode"]}】解绑成功");
            }
            catch (Exception ex)
            {
 
                return content.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 物料档位设置
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent Gearsetting(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_ware_locationRepository locationRepository = new base_ware_locationRepository(Context);
            try
            {
                base_ware_location location = locationRepository.FindFirst(d => d.upper_code == saveModel.MainData["locde"].ToString());
                if (location == null)
                {
                    return content.Error($"未找到【{saveModel.MainData["locde"].ToString()}】的货位,请检查");
                }
                dt_agvtask agvtask = agvRepository.FindFirst(d => d.agv_fromaddress == location.upper_code || d.agv_toaddress == location.upper_code);
                if (agvtask != null)
                {
                    return content.Error($"【{saveModel.MainData["locde"].ToString()}】的货位,有任务存在,无法操作此功能进行设置,请检查");
                }
 
                if (string.IsNullOrEmpty(saveModel.MainData["gtype"].ToString()))
                {
                    return content.Error($"客户端传入物料档位数据错误,传入值:【{saveModel.MainData["gtype"].ToString()}】,请检查");
                }
                if (location.geartype == saveModel.MainData["gtype"].ToString())
                {
                    return content.Error($"货架:【{location.upper_code}】已是 {location.geartype}类,无需设置");
                }
                location.geartype = saveModel.MainData["gtype"].ToString();
                int up = locationRepository.Update(location, d => d.geartype, true);
                if (up == 1)
                {
                    return content.OK($"设置成功");
                }
                else
                {
                    return content.Error($"设置失败,修改异常【{up}】");
                }
            }
            catch (Exception ex)
            {
 
                return content.Error($"{ex.Message}");
            }
        }
 
        /// <summary>
        /// pda货位编辑
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent LoctionUpdate(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            Idt_containerRepository containerRepository = new dt_containerRepository(Context);
            IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
            Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
            try
            {
              dt_agvtask agvtask=  agvRepository.FindFirst(d=>d.agv_toaddress== saveModel.MainData["barcode"].ToString());
                if (agvtask!=null)
                {
                    return content.Error($"当前货位:【{saveModel.MainData["barcode"].ToString()}】,存在AGV任务列表中,任务编号:【{agvtask.agv_tasknum}】,无法编辑,请检查");
                }
                VV_ContainerInfo containerInfo = VV_ContainerInfoRepository.FindFirst(d => d.L_Code == saveModel.MainData["barcode"].ToString());
                if (containerInfo != null)
                {
                    return content.Error($"当前货位有【{saveModel.MainData["barcode"].ToString()}】的库存,无法解绑为空货位,请检查");
                }
                base_pda_location pda_Location= pdaloctionRepository.FindFirst(d => d.L_Code == saveModel.MainData["barcode"].ToString());
                if (pda_Location==null)
                {
                    return content.Error($"当前PDA货位列表中不存在【{saveModel.MainData["barcode"].ToString()}】货位,请检查");
                }
                pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString();
                pda_Location.L_Task  = 2;
              int x=  pdaloctionRepository.Update(pda_Location,true);
                if (x!=1)
                {
                    return content.Error($"解绑空货位失败,反馈值:{x},请检查");
                }
                else
                {
                    return content.OK($"解绑空货位成功");
                }
            }
            catch (Exception ex)
            {
 
                return content.Error($"解绑空货位失败,异常内容:{ex.Message}");
            }
        }
        private static int _lock = 0;
        /// <summary>
        /// PDA货位一键解绑
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public static WebResponseContent LoctionOneclickUpdate(SaveModel saveModel)
        {
 
            WebResponseContent content = new WebResponseContent();
            VOLContext Context = new VOLContext();
            Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
            Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
            try
            {
                List<base_pda_location> pda_Location = pdaloctionRepository.Find(d => d.L_region == saveModel.MainData["region"].ToString());
                if (pda_Location.Count < 0)
                {
                    return content.Error($"当前PDA货位列表中不存在【{saveModel.MainData["region"].ToString()}】区货位,请检查");
                }
                foreach (var item in pda_Location)
                {
                    dt_agvtask agvtask1 = agvRepository.FindFirst(d => d.agv_toaddress == item.L_Code);
                    if (agvtask1 != null)
                    {
                        return content.Error($"当前【{saveModel.MainData["region"].ToString()}】区货位有【{item.L_Code}】存在任务,无法一键解绑,请检查");
                    }
                }
                pdaloctionRepository.DbContextBeginTransaction(() =>
                {
                    foreach (var item in pda_Location)
                    {
                        base_pda_location Location = pdaloctionRepository.FindFirst(d => d.L_Code == item.L_Code);
                        if (Location == null)
                        {
                            return content.Error($"当前PDA货位列表中不存在【{saveModel.MainData["barcode"].ToString()}】货位,请检查");
                        }
                        Location.L_state = LoctionStateEnum.LocationState_Empty.ToString();
 
                        Location.L_Task = 2;
                        int x = pdaloctionRepository.Update(Location, true);
                        if (x != 1)
                        {
                            return content.Error($"货位编辑失败,反馈值:{x},请检查");
                        }
                        else
                        {
                            content.OK($"一键成功");
                        }
                    }
                    return content;
                });
                return content;
            }
            catch (Exception ex)
            {
 
                return content.Error($"编辑失败,异常内容:{ex.Message}");
            }
 
 
 
 
        }
 
 
 
        public class HCGNumeData
        {
            public string num { get; set; }
 
        }
    }
}