qx
czw
2025-06-18 9862f9e1237c3d360cb4fb5547d8b11e33578d39
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
 
using HH.WCS.QingXigongchang.core;
using HH.WCS.QingXigongchang.device;
using HH.WCS.QingXigongchang.process;
using HH.WCS.QingXigongchang.util;
using HH.WCS.QingXigongchang.wms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web.Http;
using System.Web.Http.Results;
using static HH.WCS.QingXigongchang.api.ApiHelper;
using static HH.WCS.QingXigongchang.api.ApiModel;
using static HH.WCS.QingXigongchang.process.DeviceProcess;
using static HH.WCS.QingXigongchang.util.HttpHelper;
using Monitor = HH.WCS.QingXigongchang.core.Monitor;
 
namespace HH.WCS.QingXigongchang.api
{
    /// <summary>
    /// 第三方调用的接口
    /// </summary>
    [RoutePrefix("api")]
    public class WmsController : System.Web.Http.ApiController
    {
        //[HttpPost]
        //public SimpleResult AddTask(AddTaskModel model) {
        //    ApiHelper.AddTask(model);
        //    return new SimpleResult();
        //}
 
        //已经改用mobox上lua脚本处理
        //[HttpPost]
        //[Route("CleanReport")]
        //public SimpleResult CleanReport(LocationModel model) {
        //    LogHelper.Debug("CleanReport Request:" + JsonConvert.SerializeObject(model));
        //    return ApiHelper.CleanReport(model);
 
        //}
 
 
 
        [HttpPost]
        [Route("ResetDevice")]
        public SimpleResult ResetDevice(DeviceModel model)
        {
            LogHelper.Info("ResetDevice Request:" + JsonConvert.SerializeObject(model));
            return ApiHelper.ResetDevice(model);
 
        }
 
 
        /// <summary>
        /// 锁一排
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="qty"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("LockRow")]
        public SimpleResult LockRow(string area, int row)
        {
            SimpleResult result = new SimpleResult();
            List<int> rows = new List<int>();
            var areas = area?.Split(':').ToList();
            var index = 0;
            if (areas.Count() > 1) //KKQ split count =1
            {
                area = areas[0];
                index = 1;
                areas.RemoveAt(0);
                rows = Array.ConvertAll<string, int>(areas.ToArray(), s => int.Parse(s)).ToList();
            }
            else
            {
                if (index < 1 && row == 0)
                {
                    result.resultCode = 2;
                    result.resultMsg = $"库区排不可为空;";
                    return result;
                }
                rows.Add(row);
            }
            if (rows.Count == 0)
            {
                result.resultCode = 2;
                result.resultMsg = $"库区排不可为空;";
                return result;
            }
 
            return ApiHelper.Outgo1(area, rows);
        }
 
        [HttpGet]
        [Route("ClearLoc")]
        public SimpleResult ClearLoc(string area, int row)
        {
            SimpleResult result = new SimpleResult() { resultCode = 0 };
 
            if (string.IsNullOrEmpty(area) || row < 1)
            {
                result.resultCode = 2;
                result.resultMsg = $"库区排不可为空;";
                return result;
            }
 
            return ApiHelper.clearLoc(area, new List<int> { row });
        }
 
        [HttpGet]
        [Route("LockR")]
        public SimpleResult LockR(string area, int row)
        {
            SimpleResult result = new SimpleResult() { resultCode = 0 };
 
            if (string.IsNullOrEmpty(area) || row < 1)
            {
                result.resultCode = 2;
                result.resultMsg = $"库区排不可为空;";
                return result;
            }
 
            return ApiHelper.clearloc(area, new List<int> { row });
        }
 
        [HttpGet]
        [Route("unLockR")]
        public SimpleResult unLockR(string area, int row)
        {
            SimpleResult result = new SimpleResult() { resultCode = 0 };
 
            if (string.IsNullOrEmpty(area) || row < 1)
            {
                result.resultCode = 2;
                result.resultMsg = $"库区排不可为空;";
                return result;
            }
 
            return ApiHelper.unlockrow(area, new List<int> { row });
        }
 
 
        [HttpGet]
        [Route("unLockRow")]
        public SimpleResult unLockRow(string area, int row)
        {
            List<int> rows = new List<int>();
            var areas = area?.Split(':').ToList();
            var index = 0;
            if (areas.Count() > 1) //KKQ split count =1
            {
                area = areas[0];
                index = 1;
                areas.RemoveAt(0);
                rows = Array.ConvertAll<string, int>(areas.ToArray(), s => int.Parse(s)).ToList();
            }
            else
            {
                SimpleResult result = new SimpleResult();
                if (index < 1 && row == 0)
                {
                    result.resultCode = 2;
                    result.resultMsg = $"库区排不可为空;";
                    return result;
                }
                rows.Add(row);
            }
            return ApiHelper.Outgo2(area, rows);
        }
 
        /// <summary>
        ///  绑定单个
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="qty"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("BindLoc")]
        public SimpleResult BindLoc(string loc, string IsJCJY)
        {
            SimpleResult res;
            try
            {
                res = ApiHelper.Outgo3("---货位有库区。 。----", IsJCJY, loc);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = 2, resultMsg = ex.Message };
            }
            return res;
        }
 
        [HttpGet]
        [Route("RunOrder")]
        public SimpleResult RunOrder(string WorkNo)
        {
            LogHelper.Info("RunOrder" + WorkNo);
            SimpleResult res = new SimpleResult() { resultCode = 0, resultMsg = "" };
            try
            {
                var Order = WCSHelper.GetWorkOrderByOrderNo(WorkNo);
 
                if (Order == null)
                    return new SimpleResult() { resultCode = -1, resultMsg = "工单号不存在!" };
                var sdvi = Settings.GetDeviceInfoList().Find(x => x.deviceName == Order.SQL_PLineNo);
                if (sdvi == null)
                    return new SimpleResult() { resultCode = -1, resultMsg = "工单对应的产线号DeviceInfo不存在!" };
 
                for (var i = 0; i < sdvi.location.Length; i++)
                {
                    PlcHelper.SendHex(sdvi.address, "3F00" + (i + 1) + "0" + "0d0a");
                }
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = -1, resultMsg = ex.Message };
            }
            return res;
        }
 
        /// <summary>
        /// 成品绑定。 
        /// </summary>
        /// <param name="loc">货位。</param>
        /// <param name="LineNo">产线号 ,.防止因为后期增加多个产线 - </param>
        /// <returns></returns>
        [HttpGet]
        [Route("BindCP")]
        public SimpleResult BindLocCP(string loc, string LineNo, string arco)
        {
            SimpleResult res;
            try
            {
                res = ApiHelper.BindCp(loc, LineNo, arco);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = -1, resultMsg = ex.Message };
            }
            return res;
        }
 
        /// <summary>
        /// 绑定 货位所在aroc 成品用
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="btype"></param>
        /// <param name="arco"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("BindLoc2")]
        public SimpleResult BindLoc2(string loc, string btype, string arco)
        {
            SimpleResult res;
            try
            {
                res = ApiHelper.Outgo31(loc, btype, arco);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = 2, resultMsg = ex.Message };
            }
            return res;
        }
 
        /// <summary>
        ///  瓶坯。 满眶入库,转绑满眶出库。 
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="LineNo"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("BindLoc3")]
        public SimpleResult BindLoc3(dynamic ooo)
        {
            var loc = ooo.loc.ToString();
            var LineNo = ooo.LineNo.ToString();
            string ItemCode = ooo.ItemCode.ToString();
 
            LogHelper.Info("BindLoc3" + JsonConvert.SerializeObject(ooo));
            if (string.IsNullOrEmpty(ItemCode) || string.IsNullOrEmpty(LineNo))
            {
                return SimpleResult.Error($"物料{ItemCode}  或 产线{LineNo} 不能空。");
            }
            SimpleResult res;
            try
            {
                if (!ItemCode.Contains("纸箱"))
                {
                    var item = ContainerHelper.GetItem(ItemCode);
                    if (item == null) { return SimpleResult.Error(ItemCode + "数据不存在"); }
                    ItemCode = item.S_ITEM_CODE;
                }
                res = ApiHelper.Outgo33(loc, LineNo + ">" + ItemCode);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = 2, resultMsg = ex.Message };
            }
            return res;
        }
 
        /// <summary>
        ///  空筐解绑。
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="LineNo"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("unBindLoc3")]
        public SimpleResult unBindLoc3(dynamic ooo)
        {
            var loc = ooo.loc.ToString();
 
            LogHelper.Info("unBindLoc3" + JsonConvert.SerializeObject(ooo));
            if (string.IsNullOrEmpty(loc))
            {
                return SimpleResult.Error($"参数:{loc} 不能空。");
            }
            SimpleResult res;
            try
            {
                res = ApiHelper.unOutgo33(loc);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = 2, resultMsg = ex.Message };
            }
            return res;
        }
 
        /// <summary>
        /// 瓶坯 空 满 即产 绑定。
        /// </summary>
        /// <param name="loc">货位</param>
        /// <param name="arco">area  row  col  one</param>
        /// <param name="JF">J  即产   F 非即产</param>
        /// <returns></returns>
        [HttpPost]
        [Route("PPBindLocs")]
        public SimpleResult PPBindLocs(dynamic ooo)
        {
            string loc = ooo.loc.ToString();
            string arco = ooo.arco.ToString();
            string item = ooo.item.ToString();
 
            if (string.IsNullOrEmpty(item))
            {
                return SimpleResult.Error($"物料{item} 找不到物料");
            }
            SimpleResult res;
            try
            {
                res = ApiHelper.Outgo34(loc, "", arco, item);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = 2, resultMsg = ex.Message };
            }
            return res;
        }
        [HttpGet]
        [Route("PPunBindLocs")]
        public SimpleResult unPPBindLocs(string loc, string arco)
        {
            SimpleResult res;
            try
            {
                res = ApiHelper.Outgo34(loc, "", arco, "", false);
            }
            catch (Exception ex)
            {
                res = new SimpleResult() { resultCode = 2, resultMsg = ex.Message };
            }
            return res;
        }
 
 
 
        [HttpGet]
        [Route("unBindLoc")]
        public SimpleResult unBindLoc(string loc, string arco)
        {
            return ApiHelper.unOutgo3("--- 不用传。----", loc, arco);
        }
        /// <summary>
        /// 按列绑定
        /// </summary>
        /// <param name="area"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("BindLocs")]
        public SimpleResult BindLocs(string area, string col)
        {
            SimpleResult result = new SimpleResult();
            List<int> rows = new List<int>();
            var areas = area?.Split(':').ToList();
            var index = 0;
            if (areas.Count() > 1) //KKQ split count =1
            {
                area = areas[0];
                index = 1;
                areas.RemoveAt(0);
                rows = Array.ConvertAll<string, int>(areas.ToArray(), s => int.Parse(s)).ToList();
            }
            else
            {
                if (index < 1 && string.IsNullOrEmpty(col))
                {
                    result.resultCode = 2;
                    result.resultMsg = $"库区列不可为空;";
                    return result;
                }
                rows.Add(Convert.ToInt32(col));
            }
            //KKQ:1:2:3
            return ApiHelper.Outgo4(area, rows);
        }
 
 
 
        [HttpGet]
        [Route("GetAREACount")]
        public SimpleResult GetAREACount(string area, int count)
        {
            List<string> strl = new List<string>();
            IEnumerable<Settings.deviceInfo> Li = from x in Settings.GetDeviceInfoList()
                                                  where x.deviceType == 8
                                                  select x;
            Dictionary<string, int> dic = new Dictionary<string, int>();
            foreach (Settings.deviceInfo i in Li)
            {
                ApiModel.SimpleResult r = ApiHelper.GetAREACount(i.deviceNo[0]);
                string no = i.deviceNo[0];
                if (!string.IsNullOrEmpty(Regex.Match(no, "^[1-9]+").Groups[0].Value))
                {
                    no = "o" + no;
                }
                dic.Add(no, r.resultCode);
            }
 
            //dic.Add("o1PPMK", 1);
            //dic.Add("o2PPMK", 2);
            //dic.Add("o3PPMK", 3);
            //dic.Add("o4PPMK", 4);
            //dic.Add("o5PPMK", 5);
            //dic.Add("o6PPMK", 6);
            return new ApiModel.SimpleResult
            {
                resultCode = 1,
                result = new List<object>
                {
                    dic
                }
            };
            //return new SimpleResult { resultCode = strl.Count > 0 ? 1 : 0, resultMsg = strl.Count > 0 ? $"库区大于{count}的库区有" + string.Join(",", strl) : $"暂时没有满框大于{count}的库区!" };
        }
 
 
        //{"No":"TN23060665395","State":6}
        public class classs
        {
            public string No; public string State; public string ForkliftNo;
        }
 
        [HttpPost]
        [Route("TestTask")]
        public ReturnResult TestTask(classs c)
        {
            if (string.IsNullOrEmpty(c.No) || string.IsNullOrEmpty(c.State))
            {
                return new ReturnResult()
                {
                    ResultCode = -1,
                    ResultMsg = "参数为空"
                };
            }
            var b = c.State?.Split(';');
            string msg = c.No + "";
            foreach (string item in b)
            {
                ReturnResult rrr = TaskCore.OperateTaskStatus(new AgvTaskState
                {
                    No = c.No,
                    State = Convert.ToInt32(item),
                    ForkliftNo = c.ForkliftNo
                });
                msg += $"执行任务状态“{item}” {(rrr.ResultCode == 0 ? "成功" : "失败")}!";
                if (rrr.ResultCode != 0)
                {
                    rrr.ResultMsg += ":::::" + msg;
                    return rrr;
                }
                Thread.Sleep(200);
            }
 
            return new ReturnResult();
            //if (loc != "996")
            //    return loc ?? "222222222";
            //else throw new System.Exception("Exception");
        }
 
 
 
 
        /// <summary>
        ///  货位绑定 - 
        /// </summary>
        /// <param name="loc">货位</param>
        /// <param name="traylayers">层数  2、3</param>
        /// <param name="type"> 空框,  1234号瓶盖</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        [HttpGet]
        [Route("BindTrays")]
        public SimpleResult BindTrays(string loc, int traylayers, string Note)
        {
            if (string.IsNullOrEmpty(loc) || !new string[] { "空框", "1号瓶盖", "2号瓶盖", "3号瓶盖", "4号瓶盖" }.Contains(Note) || !new int[] { 2, 3 }.Contains(traylayers))
            {
                return new SimpleResult() { resultCode = 2, resultMsg = $"参数不符合!货位:{loc},标识:{Note},层数:{traylayers}" };
            }
            var _bindloc = LocationHelper.GetLoc(loc);
            if (_bindloc == null) return new SimpleResult() { resultCode = 2, resultMsg = "货位不存在。 " };
            if (_bindloc.S_AREA_CODE != "IWF360" && _bindloc.S_AREA_CODE != "IWT11") return new SimpleResult() { resultCode = 2, resultMsg = "货位库区不是瓶盖大库。 " };
            if ((_bindloc.N_CURRENT_NUM == 0 && traylayers == 3) || (_bindloc.N_CURRENT_NUM == 3 && traylayers == 2))
            {
                LocationHelper.lOCReSetValue(x => x.S_LOC_CODE == _bindloc.S_LOC_CODE, x =>
                {
                    x.N_CURRENT_NUM = _bindloc.N_CURRENT_NUM + traylayers;
                    x.S_NOTE = Note;
                });
            }
            else if (_bindloc.S_AREA_CODE == "IWT11")
            {
                LocationHelper.lOCReSetValue(x => x.S_LOC_CODE == _bindloc.S_LOC_CODE, x =>
                {
                    x.N_CURRENT_NUM = traylayers;
                    x.S_NOTE = Note;
                });
            }
            else
                return new SimpleResult() { resultCode = 2, resultMsg = $"托盘数{traylayers} 和货位托盘数{_bindloc.N_CURRENT_NUM} 无法叠筐" };
            return new SimpleResult() { resultCode = 0, resultMsg = "" };
        }
 
 
        /// <summary>
        /// 报废货位
        /// </summary>
        /// <param name="loc"></param
        /// <param name="all">1/0</param>
        /// <returns></returns>
        [HttpGet]
        [Route("BFloc")]
        public SimpleResult BFloc(string loc, string all)
        {
            if (string.IsNullOrEmpty(loc))
            {
                return new SimpleResult() { resultCode = 2, resultMsg = $"参数不符合!货位:{loc}" };
            }
            var _bindloc = LocationHelper.GetLoc(loc);
            if (_bindloc == null) return new SimpleResult() { resultCode = 2, resultMsg = "货位不存在。 " };
            //if (_bindloc.S_AREA_CODE != "IWF360") return new SimpleResult() { resultCode = 2, resultMsg = "货位库区不是瓶盖大库。 " };
            if ((_bindloc.S_LOCK_STATE != "无" && _bindloc.S_LOCK_STATE != "空间锁"))
                return new SimpleResult() { resultCode = 2, resultMsg = $"货位状态{_bindloc.S_LOCK_STATE} 不能报废。 " };
            else
            {
                if (all == "1")
                {
                    LocationHelper.lOCReSetValue(x => x.S_AREA_CODE == _bindloc.S_AREA_CODE && x.N_ROW == _bindloc.N_ROW, x =>
                    {
                        x.S_LOCK_STATE = "报废";
                    });
                }
                else
                    LocationHelper.lOCReSetValue(x => x.S_LOC_CODE == _bindloc.S_LOC_CODE, x =>
                    {
                        x.S_LOCK_STATE = "报废";
                    });
            }
            return new SimpleResult() { resultCode = 0, resultMsg = "" };
        }
 
        /// <summary>
        /// 报废货位解除
        /// </summary>
        /// <param name="loc"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("unBFloc")]
        public SimpleResult unBFloc(string loc, string all, string clear)
        {
            if (string.IsNullOrEmpty(loc))
            {
                return new SimpleResult() { resultCode = 2, resultMsg = $"参数不符合!货位:{loc}" };
            }
            var _bindloc = LocationHelper.GetLoc(loc);
            if (_bindloc == null) return new SimpleResult() { resultCode = 2, resultMsg = "货位不存在。 " };
            //if (_bindloc.S_AREA_CODE != "IWF360") return new SimpleResult() { resultCode = 2, resultMsg = "货位库区不是瓶盖大库。 " };
            if (_bindloc.S_LOCK_STATE != "报废" && all != "1" && clear != "1")
            {
                return new SimpleResult() { resultCode = 2, resultMsg = $"货位状态{_bindloc.S_LOCK_STATE} 无需解除。 " };
            }
 
            {
                if (all == "1")
                {
                    LocationHelper.lOCReSetValue(x => x.S_AREA_CODE == _bindloc.S_AREA_CODE && x.N_ROW == _bindloc.N_ROW, x =>
                    {
                        x.S_LOCK_STATE = "无";
                        if (clear == "1")
                        {
                            x.S_NOTE = "";
                            x.N_CURRENT_NUM = 0;
                            x.T_EMPTY_TIME = null;
                            x.T_FULL_TIME = null;
                        }
                    });
                }
                else
                    LocationHelper.lOCReSetValue(x => x.S_LOC_CODE == _bindloc.S_LOC_CODE, x =>
                    {
                        x.S_LOCK_STATE = "无";
                        if (clear == "1")
                        {
                            x.S_NOTE = "";
                            x.N_CURRENT_NUM = 0;
                            x.T_EMPTY_TIME = null;
                            x.T_FULL_TIME = null;
                        }
                    });
            }
            if (clear == "1")
            { //这里清 托盘 -- 上面是清货位数据。 
                if (all == "1")
                {
                    var loclist = LocationHelper.GetLocList(x => x.S_AREA_CODE == _bindloc.S_AREA_CODE && x.N_ROW == _bindloc.N_ROW)?.Select(x => x.S_LOC_CODE.Trim());
                    LocationHelper.DoAction(db =>
                    {
                        return db.Deleteable<LocCntrRel>().Where(it => loclist.Contains(it.S_LOC_CODE.Trim())).ExecuteCommand() > 0;
                    });
                }
                else
                {
                    LocationHelper.DoAction(db =>
                    {
                        return db.Deleteable<LocCntrRel>().Where(it => it.S_LOC_CODE == _bindloc.S_LOC_CODE).ExecuteCommand() > 0;
                    });
                }
            }
            return new SimpleResult() { resultCode = 0, resultMsg = "" };
        }
 
 
        [HttpGet]
        [Route("Testttt")]
        public string Testttt(string loc)
        {
            if (loc != "996")
                return loc ?? "222222222";
            else throw new System.Exception("Exception");
        }
 
        [HttpGet]
        [Route("MeFlux")]
        public dynamic Mescs()
        {
            var apih = new HttpHelper();
            string token = HttpHelper.GetMd5Hash(Settings.securityKey + "from" + Settings.tokenfrom + "timestamp" + apih._time);
 
            return new
            {
                token = token,
                from = Settings.tokenfrom,
                timestamp = apih._time
            };
        }
 
        [HttpPost]
        [Route("WebPost")]
        public string WebPost(PostStyle postStyle)
        {
            return new HttpHelper().WebPost(postStyle.url, postStyle.postData);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Floc"></param>
        /// <param name="Tloc"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("TakeP2P")]
        public SimpleResult TakeP2P(string Floc, string Tloc)
        {
            Console.WriteLine($"TakeP2P:::::==>>>>>> floc {Floc} tloc{Tloc}");
            LogHelper.Info($"floc {Floc} tloc{Tloc}");
            if (string.IsNullOrEmpty(Floc))
                Floc = "";
 
            try
            {
                var FlociNFO = LocationHelper.GetLoc(Floc.Trim());
                var TlociNFO = LocationHelper.GetLoc(Tloc.Trim());
 
                if (FlociNFO == null || TlociNFO == null)
                {
                    return SimpleResult.Error($"{(FlociNFO == null ? "起点货位数据为空。" : "")}{(TlociNFO == null ? "终点货位数据为空。" : "")}");
                }
                if (FlociNFO.S_LOCK_STATE != "无" || TlociNFO.S_LOCK_STATE != "无")
                {
                    return SimpleResult.Error($"{(FlociNFO.S_LOCK_STATE != "无" ? $"起点货位状态{FlociNFO.S_LOCK_STATE}。" : "")}{(TlociNFO.S_LOCK_STATE != "无" ? $"起点货位状态{TlociNFO.S_LOCK_STATE}。" : "")}");
                }
 
                var B = TaskProcess.CreateTransport("", Floc.Trim(), Tloc.Trim(), "自由点对点转运", new List<string> { "不管控托盘" }, 1, 1, 1, 60);
 
                LogHelper.Info($"创建自由点对点转运 指定点 {Floc.Trim()}->{Tloc.Trim()}");
                if (B) return new SimpleResult();
                return SimpleResult.Error("自由点对点转运 创建成功");
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message, ex);
                return SimpleResult.Error(ex.Message);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Floc"></param>
        /// <param name="Tloc"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("TakeP2PWithAllCntr")]
        public SimpleResult TakeP2PWithAllCntr(string Floc, string Tloc)
        {
            Console.WriteLine($"TakeP2P:::::==>>>>>> floc {Floc} tloc{Tloc}");
            LogHelper.Info($"floc {Floc} tloc{Tloc}");
            if (string.IsNullOrEmpty(Floc))
                Floc = "";
 
            try
            {
                var FlociNFO = LocationHelper.GetLoc(Floc.Trim());
                var TlociNFO = LocationHelper.GetLoc(Tloc.Trim());
 
                if (FlociNFO == null || TlociNFO == null)
                {
                    return SimpleResult.Error($"{(FlociNFO == null ? "起点货位数据为空。" : "")}{(TlociNFO == null ? "终点货位数据为空。" : "")}");
                }
                if (FlociNFO.S_LOCK_STATE != "无" || TlociNFO.S_LOCK_STATE != "无")
                {
                    return SimpleResult.Error($"{(FlociNFO.S_LOCK_STATE != "无" ? $"起点货位状态{FlociNFO.S_LOCK_STATE}。" : "")}{(TlociNFO.S_LOCK_STATE != "无" ? $"起点货位状态{TlociNFO.S_LOCK_STATE}。" : "")}");
                }
 
                if (FlociNFO.N_CURRENT_NUM == 0 || TlociNFO.N_CURRENT_NUM > 0)
                {
                    return SimpleResult.Error($"{Floc}起点无托盘 或者 {Tloc}终点有托盘。 任务不成立");
                }
                var loccntrs = LocationHelper.GetList<LocCntrRel>(x => x.S_LOC_CODE == FlociNFO.S_LOC_CODE);
                if (loccntrs.Count == 0)
                {
                    return SimpleResult.Error($"{Floc}起点有数量,但是没有绑定的托盘。");
                }
 
                var B = TaskProcess.CreateTransport("", Floc.Trim(), Tloc.Trim(), "带托盘点对点转运", loccntrs.Select(x => x.S_CNTR_CODE).ToList(), 1, 1, 1, 60);
 
                LogHelper.Info($"创建 带托盘点对点转运 指定点 {Floc.Trim()}->{Tloc.Trim()}");
                if (B) return new SimpleResult();
                return SimpleResult.Error("带托盘点对点转运 创建失败");
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message, ex);
                return SimpleResult.Error(ex.Message);
            }
        }
 
        /// <summary>
        /// 使用领料做 批量任务 
        /// </summary>
        /// <param name="Endloc">直接写终点 是 输送线流程。  写 area-2-终点 是提升机流程。</param>
        /// <param name="item"></param>
        /// <param name="qty"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GuoLai")]
        public SimpleResult GuoLai(dynamic dyc)
        {
            LogHelper.Info($"GuoLai 使用领料做 批量任务 {JsonConvert.SerializeObject(dyc)}");
            string Endloc = dyc.Endloc;
            string item = dyc.item;
            int qty = dyc.qty;
            if (string.IsNullOrEmpty(Endloc) || (string.IsNullOrEmpty(item) && !Endloc.Contains("-2-")) || qty <= 0)
                return SimpleResult.Error($"有参数为空或,数量不大于0{Endloc},{item},{qty}");
            var db = new SqlHelper<object>().GetInstance();
            var alr = db.Queryable<LingItemOrder>().Where(x => x.WorkFromNo == "Auto" && x.DeviceNo == Endloc.Trim() && x.State == "执行").First();
            if (alr != null)
                return SimpleResult.Error($"{Endloc} 已经存在执行中的。领料信息。 物料为{alr.ItemCode}");
            var res = db.Insertable(new LingItemOrder
            {
                WorkNo = "LIOauto" + DateTime.Now.ToString("yyMMdd HH:mm"),
                WorkFromNo = "Auto",
                ItemCode = item,
                OutAreaNum = qty + "",
                DeviceNo = Endloc.Trim(),//// 直接写终点 是 输送线流程。  写 area-2-终点-2-任务类型  是提升机流程。
                OutCurrentNum = "0",
                State = "执行"
            }).ExecuteCommand() > 0;
            return res ? new SimpleResult() : SimpleResult.Error($"{Endloc}-{item} 创建叫料单据失败!请重来。");
        }
 
        [HttpPost]
        [Route("GuoLaiCancle")]
        public SimpleResult GuoLaiCancle(string Endloc, string item)
        {
            if (string.IsNullOrEmpty(Endloc) || string.IsNullOrEmpty(item))
                return SimpleResult.Error($"有参数为空或,数量不大于0{Endloc},{item}");
            var db = new SqlHelper<object>().GetInstance();
            var alr = db.Queryable<LingItemOrder>().Where(x => x.WorkFromNo == "Auto" && x.DeviceNo == Endloc.Trim() && x.State == "执行").First();
            if (alr == null)
                return SimpleResult.Error($"{Endloc} 没有执行中的。领料信息。");
            alr.State = "取消";
            var res = db.Updateable(alr).UpdateColumns(it => new { it.State }).ExecuteCommand() > 0;
            return res ? new SimpleResult() : SimpleResult.Error($"{Endloc} 执行取消叫料单据失败!");
        }
 
        [HttpGet]
        [Route("Ctcp")]
        public List<string> WebGst()
        {
            return TcpServer.clients.Keys.ToList();
        }
 
        [HttpGet]
        [Route("Cdoor")]
        public string WebGstDoor()
        {
            return JsonConvert.SerializeObject(new
            {
                clients = TcpServer.clients.Keys.ToList(),
                doorStatus = DeviceProcess.doorStatus,
                dsi = Monitor.dsi
            });
            return JsonConvert.SerializeObject(DeviceProcess.doorStatus);
        }
 
 
 
        [HttpGet]
        [Route("GetUpu")]
        public dynamic GetUpu()
        {
            Process currentProcess = Process.GetCurrentProcess();
            string processName = currentProcess.ProcessName;
            int processId = currentProcess.Id;
            List<dynamic> data = new List<dynamic>();
            foreach (ProcessThread thread in currentProcess.Threads)
            {
                string counterPath = $"Process({processName})\\Thread({thread.Id})";
                var counter = new PerformanceCounter("Thread", "% Processor Time", thread.Id.ToString(), processName);
                float cpuUsage = counter.NextValue();
                data.Add(new
                {
                    thread.Id,
                    counter,
                    cpu = $"{cpuUsage:F2}%"
                });
            }
            return data;
        }
 
 
        [HttpGet]
        [Route("CntrSplit")]
        public SimpleResult CntrSplit()
        {
            List<LocCntrRel> lcrl = new List<LocCntrRel>();
            var db = new SqlHelper<object>().GetInstance();
            lcrl = db.Queryable<LocCntrRel>().Includes(x => x.CntrItemRel).Where(x => x.S_CNTR_CODE.Length == 48 && x.S_CNTR_CODE.StartsWith("F")).ToList();
            int si = 0;
            string msg = "";
            var gP = lcrl.GroupBy(x => x.S_LOC_CODE);
            Console.WriteLine($"托盘拆分。 总共{gP.Count()}个货位,{lcrl.Count}个合并的托盘。");
            foreach (var s in gP)
            {
                si++;
                db.BeginTran();
                msg = "";
                try
                {
                    var loc = db.Queryable<Location>().Where(x => x.S_LOC_CODE == s.Key).First();
                    if (loc == null)
                        continue;
                    else
                    {
                        foreach (LocCntrRel item in s.ToList())
                        {
                            string cntrCode = item.S_CNTR_CODE;
 
                            var lcr = item.Clone();
                            var lcr2 = item.Clone();
 
                            lcr.S_CNTR_CODE = cntrCode.Substring(1, 23);
                            lcr.S_ID = Guid.NewGuid().ToString();
 
                            lcr2.S_CNTR_CODE = cntrCode.Substring(25, 23);
                            lcr2.S_ID = Guid.NewGuid().ToString();
 
                            var cir = item.CntrItemRel.Clone();
                            var cir2 = cir.Clone();
 
                            cir.S_CNTR_CODE = lcr.S_CNTR_CODE;
                            cir.S_ID = lcr.S_ID;
 
                            cir2.S_CNTR_CODE = lcr2.S_CNTR_CODE;
                            cir2.S_ID = lcr2.S_ID;
 
                            db.Insertable(lcr).ExecuteCommand();
                            db.Insertable(lcr2).ExecuteCommand();
                            db.Insertable(cir).ExecuteCommand();
                            db.Insertable(cir2).ExecuteCommand();
 
                            db.Deleteable(item).ExecuteCommand();
                            db.Deleteable(item.CntrItemRel).ExecuteCommand();
                        }
                        //loc.N_CAPACITY *= 2;
                        //loc.N_CURRENT_NUM *= 2;
                        if (loc.N_CURRENT_NUM > 0)
                        {
                            loc.T_EMPTY_TIME = null;
                            db.Updateable(loc).UpdateColumns(it => new { it.T_EMPTY_TIME }).ExecuteCommand();
                        }
                        //db.Updateable(loc).UpdateColumns(it => new { it.N_CAPACITY, it.N_CURRENT_NUM }).ExecuteCommand();
                    }
                    db.CommitTran();
                    Console.WriteLine($"{DateTime.Now.ToShortTimeString()} 提交第{si}个货位{s.Key}拆分数据");
                }
                catch (Exception ex)
                {
                    db.RollbackTran();
                    Console.WriteLine(s.Key + "  " + ex.Message);
                }
                finally
                {
                    msg += s.Key;
                }
            }
 
            return SimpleResult.Success(msg);
        }
 
    }
    public class InmiTask
    {
        public string StartArea { get; set; }
        public string EndbitArea { get; set; }
        public string ItemCode { get; set; }
    }
}