schangxiang@126.com
2025-04-17 37184b1d1ac000a6ee40e397e2336b213e705902
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
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCC.StationService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DBModel;
using iWareSql.WmsDBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection.Emit;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel.Configuration;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using XiGang.Core.Model;
 
namespace iWareCC.ThreadService
{
    /// <summary>
    /// BZ01工位(清灰,洗板后工位)
    /// </summary>
    public static class DataProcess_BZ01
    {
        public static string timingForWait = "";//定时器,等待数据
 
        /// <summary>
        /// BZ01工位(清灰,洗板后工位)
        /// </summary>
        public static async void Handler()
        {
            var alertMsg = "";
            LogType logType = LogType.DataProcess_BZ01;
            string lastUpi = "";//最后记录的UPI数据
 
            while (true)
            {
                Thread.Sleep(1000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = string.Empty;
                try
                {
                    if (SystemValue.isStartedModel)//SystemValue.isAllowRuning_DataProcess_BZ01 &&
                    {
                        if (FormCC.IsAllowRunOutMode == true)
                        {
                            SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"正在干出库模式,此方法暂停。。 ";
                            continue;
                        }
 
 
                        var rgvLocation = StationLocationEnum.BZ01.ToString();
                        /*
                         * 1、从数据库中判断是否齐套
                         * 2、根据齐套结果,推送给PLC
                         */
                        if (FormCC.stationView == null)
                        {
                            SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-获取PLC对象为null";
                            continue;
                        }
                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
                        if (obj.R_ReqParseData)
                        {
                            var result = obj.R_ReadCodeResult;
                            if (string.IsNullOrEmpty(result))
                            {
                                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束";
                                continue;
                            }
 
                            if (lastUpi == result)
                            {
                                //寻找上次的BZ01验证记录 
                                using (WmsDBModel wmsDB = new WmsDBModel())
                                {
                                    var lastRecord = wmsDB.wms_record_upi_process.Where(x => x.Upi == lastUpi && x.Location == "BZ01").OrderByDescending(x => x.Id).FirstOrDefault();
                                    if (lastRecord != null)
                                    {
                                        //取是否 齐包
                                        bool my_qitaoReault = false;
                                        if (lastRecord.UpiStatus == (int)UpiStatusEnum.已齐包)
                                        {
                                            my_qitaoReault = true;
                                        }
                                        //推送PLC
                                        using (StationServiceClient client = new StationServiceClient())
                                        {
                                            var res = await client.WriteQiTaoInfoAsync((int)EDevice.Station, rgvLocation, my_qitaoReault);
                                            if (!res.result)
                                            {
                                                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-【单独推送PLC】推送齐套结果失败,WriteQiTaoInfoAsync返回:{res.resMsg}";
                                                continue;
                                            }
                                            else
                                            {
                                                Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-【单独推送PLC】推送齐套结果成功,WriteQiTaoInfoAsync,参数: 站点{rgvLocation},齐套结果:{my_qitaoReault}");
                                                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-【单独推送PLC】推送齐套结果成功";
                                                continue;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-重复的UPI{result}";
                                        continue;
                                    }
                                }
                            }
                            //*/
                            var upiCode = result;
 
 
                            var qitaoReault = false;//齐包结果
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
                                if (upiObj == null)
                                {
                                    //写入报警信息
                                    await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ01_1);
 
                                    SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                                    continue;
                                }
 
                                var isAllow = IsAllloRunOutTaskMode(wmsDB, upiObj);
                                if (isAllow)
                                {
                                    SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()},判断要执行出库模式了,此方法暂停。。 ";
                                    continue;
                                }
 
                                //增加对参数配置的管理 【Editby shaocx,2024-12-13】
                                var sysConfig = wmsDB.SysConfig.Where(x => x.Code == "LastUpi_BZ01").FirstOrDefault();
                                if (sysConfig == null)
                                {
                                    SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"没有获取到 LastUpi_BZ01的配置信息 ";
                                    continue;
                                }
                                var config_value = sysConfig.Value;
                                if (config_value.IndexOf('|') > -1)
                                {//格式为  包号|UPI|次序|齐包状态
                                    var arr = config_value.Split('|');
                                    var lastPackageCode = arr[0];
                                    var lastUpi_BZ01 = arr[1];
                                    var lastShelf = Convert.ToInt32(arr[2]);
                                    var lastQitaoReault = arr[3];
 
                                    if (upiObj.PackageCode == lastPackageCode)
                                    {
                                        if (upiObj.Shelf == (lastShelf + 1))
                                        {
                                            //齐包状态
                                            if (lastQitaoReault == "齐包")
                                            {
                                                qitaoReault = true;
                                            }
                                            else
                                            {
                                                qitaoReault = false;
                                            }
                                        }
                                        else
                                        {//不齐包
                                            qitaoReault = false;
                                        }
                                    }
                                    else
                                    {//说明是换了包号,重新验证 齐包状态
                                        #region 计算是否齐包
                                        qitaoReault = ValidateQiBao(wmsDB, upiObj);
                                        #endregion
                                    }
                                }
                                else
                                {//表示还没有配置 ,重新验证 齐包状态
                                    #region 计算是否齐包
                                    qitaoReault = ValidateQiBao(wmsDB, upiObj);
                                    #endregion
                                }
                                //包中只有一块板时,认定为 不齐包 【Editby shaocx,2025-04-01】
                                var isOnlyOne = MyExtendHelper.IsOnlyOneInPackage(wmsDB, upiObj.UPI);
                                if (isOnlyOne)
                                {
                                    qitaoReault = false;
                                }
 
                                //增加优化验证 【Editby shaocx,2024-12-16】
                                if (qitaoReault == false)
                                {
                                    var lastPackageUpi_269 = FormCC.Globle_269_LastPackageUpi;
                                    if (!string.IsNullOrEmpty(lastPackageUpi_269))
                                    {
                                        var arr = lastPackageUpi_269.Split('|');
                                        if (upiObj.PackageCode == arr[0])
                                        {//最后一次在269扫描的包号 跟 现在BZ01的包号一致,要等待
                                         //wait
                                            var isWaitOutTime = Wait269(wmsDB);
                                            if (isWaitOutTime == false)
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            //继续往下走
                                        }
                                    }
                                    else
                                    {
                                        //wait
                                        var isWaitOutTime = Wait269(wmsDB);
                                        if (isWaitOutTime == false)
                                        {
                                            continue;
                                        }
                                    }
                                }
 
                                timingForWait = "";//重置数据
                                if (qitaoReault == false)
                                {
                                    upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                }
                                else
                                {
                                    upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
                                }
                                /*
                                //查询是否齐包
                                var allList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList();
                                var isQiTaoList = allList.Where(x => x.AreaCode == (int)AreaCodeEnum.待缓存分拣区
                                ||
                                x.AreaCode == (int)AreaCodeEnum.缓存分拣区
                                 ||
                                x.AreaCode == (int)AreaCodeEnum.码垛区域
                                ).ToList();
                                if (isQiTaoList.Count() != allList.Count())
                                {//不齐包
                                    qitaoReault = false;
                                    upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                }
                                else
                                {//齐包
                                 //这里再增加个逻辑,必须是按照次序进入的才真正的算齐包 [Editby shaocx,2024-12-06]
                                 //寻找本包内的前一块板的位置
                                    int queryAreaCode = (int)AreaCodeEnum.待缓存分拣区;
                                    var lastUpiLineQueue = wmsDB.mes_upi_linequeue.Where(x => x.PackageCode == upiObj.PackageCode && x.AreaCode == queryAreaCode)
                                        .OrderBy(x => x.Id).FirstOrDefault();//查询该包队列的第一块板
                                    if (lastUpiLineQueue == null)
                                    {//说明 队列中没有该包的数据
                                        qitaoReault = false;
                                        upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                    }
                                    else
                                    {
                                        if (lastUpiLineQueue.Shelf != upiObj.Shelf)
                                        {
                                            qitaoReault = false;
                                            upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                        }
                                        else
                                        {
                                            var isJiXuValidate = true;
                                            if (upiObj.Shelf != 1)
                                            {
                                                var qianmianList = allList.Where(x => x.Shelf < upiObj.Shelf).ToList();
                                                //看以前的板在哪里,必须都在 码垛区域
                                                var yiqianQuyu = AreaCodeEnum.码垛区域;
                                                var count_MD = qianmianList.Where(x => x.AreaCode == (int)yiqianQuyu).Count();
                                                if (count_MD != qianmianList.Count())
                                                {
                                                    isJiXuValidate = false;
                                                    qitaoReault = false;
                                                    upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                                }
                                            }
 
                                            if (isJiXuValidate)
                                            {//是否继续验证
                                                //还需要验证在这些区域中,是否正确排队,如果没有正确排队,那么就认为不齐套 【Editby shaocx,2024-12-12】
                                                var queueList = wmsDB.mes_upi_linequeue.Where(x => x.PackageCode == upiObj.PackageCode && x.AreaCode == queryAreaCode)
                                                    .OrderBy(x => x.Id).ToList();
                                                var fisrtId = queueList.OrderBy(x => x.Id).First().Id;
                                                var endId = queueList.OrderByDescending(x => x.Id).First().Id;
                                                //继续查询这个时间段内的队列数据
                                                //重写该队列
                                                queueList = wmsDB.mes_upi_linequeue.Where(x => x.Id >= fisrtId && x.Id <= endId).OrderBy(x => x.Id).ToList();
                                                var syCount = allList.Where(x => x.Shelf >= upiObj.Shelf).Count();
                                                if (queueList.Count() != syCount)
                                                {
                                                    qitaoReault = false;
                                                    upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                                }
                                                else
                                                {
                                                    //判断是否乱序
                                                    bool isLuanXuan = false;
                                                    int temp_shelf = 0;
                                                    for (int i = 0; i < queueList.Count; i++)
                                                    {
                                                        if (i == 0)
                                                        {
                                                            temp_shelf = queueList[i].Shelf;
                                                            if (temp_shelf != upiObj.Shelf)
                                                            {
                                                                qitaoReault = false;
                                                                isLuanXuan = true;
                                                                upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                                                break;//跳出循环
                                                            }
                                                            if (queueList[i].Upi != upiObj.UPI)
                                                            {
                                                                qitaoReault = false;
                                                                isLuanXuan = true;
                                                                upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                                                break;//跳出循环
                                                            }
                                                        }
                                                        else
                                                        {
                                                            temp_shelf = temp_shelf + 1;
                                                            if (temp_shelf != queueList[i].Shelf)
                                                            {//认为乱序了
                                                                qitaoReault = false;
                                                                isLuanXuan = true;
                                                                upiObj.AreaCode = (int)AreaCodeEnum.缓存分拣区;
                                                                break;//跳出循环
                                                            }
                                                        }
                                                    }
 
                                                    if (isLuanXuan == false)
                                                    {
                                                        qitaoReault = true;
                                                        upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
                                                    }
                                                }
                                            }
                                        }
 
                                        //注意:要删除该队列数据哦
                                        wmsDB.mes_upi_linequeue.Remove(lastUpiLineQueue);
                                    }
                                }
                                //*/
                                //if (qitaoReault == false) {
                                //    //临时
                                //    SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"模拟啊啊,暂停啊啊";
                                //    continue;
                                //}
 
 
                                lastUpi = upiCode;
                                using (StationServiceClient client = new StationServiceClient())
                                {
                                    var res = await client.WriteQiTaoInfoAsync((int)EDevice.Station, rgvLocation, qitaoReault);
                                    if (!res.result)
                                    {
                                        SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-推送齐套结果失败,WriteQiTaoInfoAsync返回:{res.resMsg}";
                                        continue;
                                    }
                                    else
                                    {
                                        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送齐套结果成功,WriteQiTaoInfoAsync,参数: 站点{rgvLocation},齐套结果:{qitaoReault}");
                                    }
                                }
 
                                var str_qitaoReault = (qitaoReault ? "齐包" : "不齐包");
                                //记录下结果
                                sysConfig.Value = upiObj.PackageCode + "|" + upiObj.UPI + "|" + upiObj.Shelf + "|" + str_qitaoReault;
 
                                //删除该UPI的缓存队列数据
                                int queryAreaCode2 = (int)AreaCodeEnum.待缓存分拣区;
                                var curUpiLineQueue = wmsDB.mes_upi_linequeue.Where(x => x.Upi == upiObj.UPI && x.AreaCode == queryAreaCode2)
                               .FirstOrDefault();
                                if (curUpiLineQueue != null)
                                {
                                    wmsDB.mes_upi_linequeue.Remove(curUpiLineQueue);
                                }
 
                                //更新UPI状态
                                var upiObjList = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).ToList();
                                foreach (var item in upiObjList)
                                {
                                    if (qitaoReault)
                                    {
                                        item.UpiStatus = (int)UpiStatusEnum.已齐包;
                                    }
                                    else
                                    {
                                        item.UpiStatus = (int)UpiStatusEnum.不齐包;
                                    }
                                }
                                //更新包状态 [Editby shaocx,2024-12-15]
                                var packageObj = wmsDB.mes_package_gather.Where(x => x.PackageCode == upiObj.PackageCode).FirstOrDefault();
                                if (packageObj != null)
                                {
                                    if (qitaoReault)
                                    {
                                        packageObj.UpiStatus = (int)UpiStatusEnum.已齐包;
                                        packageObj.IsQiBao = true;
                                    }
                                    else
                                    {
                                        packageObj.UpiStatus = (int)UpiStatusEnum.不齐包;
                                        packageObj.IsQiBao = false;
                                    }
                                }
 
                                //更新 最后一次在 BZ_01的系统处理的板件 数据
                                var rbRunMode = wmsDB.wms_rbline_runmode.FirstOrDefault();
                                rbRunMode.UPI = upiObj.UPI;
                                rbRunMode.PlanNo = upiObj.PlanNo;
                                rbRunMode.OrderId = upiObj.OrderId;
                                rbRunMode.PackageCode = upiObj.PackageCode;
 
                                WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, "BZ01", "齐包验证:" + str_qitaoReault);
 
                                wmsDB.SaveChanges();
                            }
                        }
                        else
                        {
                            SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-没有要处理的数据";
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var isAllow = IsAllloRunOutTaskMode(wmsDB, null);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_alert_DataProcess_BZ01 += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
                }
            }
        }
 
        /// <summary>
        /// 超时验证
        /// </summary>
        /// <param name="wmsDB"></param>
        /// <param name="time"></param>
        /// <returns>true:超时 false:未超时</returns>
        private static bool Wait269(WmsDBModel wmsDB)
        {
            var bz30Config = wmsDB.SysConfig.Where(x => x.Code == "Wait_269").FirstOrDefault();
            if (bz30Config == null)
            {
                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"没有配置 Wait_269 值";
                return false;
            }
            int i = 0;
            bool right = int.TryParse(bz30Config.Value, out i);
            if (right == false)
            {
                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"配置 Wait_269 值不是整数";
                return false;
            }
 
            if (string.IsNullOrEmpty(timingForWait))
            {
                timingForWait = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
 
            string time = timingForWait;
            //在269扫描的时间
            var time_269 = Convert.ToDateTime(time);
            TimeSpan ts = DateTime.Now - time_269;
            var sec = ts.Seconds;
            if (sec >= i)
            {
                //超时
                return true;
            }
            SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"配置 Wait_269 值是{i},当前间隔是{sec}秒,未超时。开始等待时间{timingForWait}";
            return false;
        }
 
        /// <summary>
        /// 是否可以执行出库模式
        /// </summary>
        /// <param name="wmsDB"></param>
        /// <param name="curUpiObj"></param>
        /// <returns></returns>
        private static bool IsAllloRunOutTaskMode(WmsDBModel wmsDB, mes_batchOrderUPI_new curUpiObj)
        {
            //不再判断 【Editby shaocx,2024-12-14】
            return false;
 
            /*
            //首先查询数据库中是否有 要出库的数据
            var isExistOutTaskForNewCreated = wmsDB.wms_rbline_task.Where(x =>
            (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
               && x.TaskStatus == (int)TaskStatusEnum.新建
              ).Count();
            if (isExistOutTaskForNewCreated == 0)
            {
                FormCC.IsAllowRunOutMode = false;
                return false;//不能执行 出库模式
            }
 
            var rbRunMode = wmsDB.wms_rbline_runmode.FirstOrDefault();
            var lastUpi = rbRunMode.UPI;
            var lastPackageCode = rbRunMode.PackageCode;
 
            if (curUpiObj == null)
            {//表示此时无新板过来
                if (!string.IsNullOrEmpty(lastUpi))
                {
                    var lastObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == lastUpi).FirstOrDefault();
                    if (lastObj.UpiStatus == (int)UpiStatusEnum.不齐包 || lastObj.UpiStatus == (int)UpiStatusEnum.初始)
                    {//表示最后过去的板是不齐包的板
                        //可以运行执行 出库模式
                    }
                    else
                    {//表示最后过去的板是齐包的板
                        //要继续判断后面 待分拣区域还存在相同包的板数据吗
                        var isExistSamePackageCode = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == lastPackageCode
                                && x.AreaCode == (int)AreaCodeEnum.待缓存分拣区).Count();
                        if (isExistSamePackageCode > 0)
                        {
                            FormCC.IsAllowRunOutMode = false;
                            return false;//不能执行 出库模式
                        }
                        else
                        {
                            //可以运行执行 出库模式
                        }
                    }
                }
                else
                {
                    //可以运行执行 出库模式
                }
            }
            else
            {//表示此时有新板过来
                if (!string.IsNullOrEmpty(lastUpi))
                {
                    if (lastPackageCode == curUpiObj.PackageCode)
                    {
                        FormCC.IsAllowRunOutMode = false;
                        return false;//不能执行 出库模式
                    }
                    else
                    {//新包过来了
                        //可以运行执行 出库模式
                    }
                }
                else
                {
                    //可以运行执行 出库模式
                }
            }
 
            FormCC.IsAllowRunOutMode = true;
            return true;
 
            //*/
        }
 
        /// <summary>
        /// 判断是否齐包
        /// </summary>
        /// <param name="wmsDB"></param>
        /// <param name="upiObj"></param>
        /// <returns></returns>
        private static bool ValidateQiBao(WmsDBModel wmsDB, mes_batchOrderUPI_new upiObj)
        {
            if (upiObj.Shelf != 1)
            {
                return false;
            }
            //查询是否齐包
            var allList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList();
            var isQiTaoList = allList.Where(x => x.AreaCode == (int)AreaCodeEnum.待缓存分拣区
            ||
            x.AreaCode == (int)AreaCodeEnum.码垛区域
            ).ToList();
            if (isQiTaoList.Count() != allList.Count())
            {//不齐包
                return false;
            }
            else
            {//齐包
             //这里再增加个逻辑,必须是按照次序进入的才真正的算齐包 [Editby shaocx,2024-12-06]
             //寻找本包内的前一块板的位置
                int queryAreaCode = (int)AreaCodeEnum.待缓存分拣区;
                var lastUpiLineQueue = wmsDB.mes_upi_linequeue.Where(x => x.PackageCode == upiObj.PackageCode && x.AreaCode == queryAreaCode)
                    .OrderBy(x => x.Id).FirstOrDefault();//查询该包队列的第一块板
                if (lastUpiLineQueue == null)
                {//说明 队列中没有该包的数据
                    return false;
                }
                else
                {
                    if (lastUpiLineQueue.Shelf != upiObj.Shelf)
                    {
                        return false;
                    }
                    else
                    {
                        var isJiXuValidate = true;
                        if (upiObj.Shelf != 1)
                        {
                            var qianmianList = allList.Where(x => x.Shelf < upiObj.Shelf).ToList();
                            //看以前的板在哪里,必须都在 码垛区域
                            var yiqianQuyu = AreaCodeEnum.码垛区域;
                            var count_MD = qianmianList.Where(x => x.AreaCode == (int)yiqianQuyu).Count();
                            if (count_MD != qianmianList.Count())
                            {
                                isJiXuValidate = false;
                                return false;
                            }
                        }
 
                        if (isJiXuValidate)
                        {//是否继续验证
                         //还需要验证在这些区域中,是否正确排队,如果没有正确排队,那么就认为不齐套 【Editby shaocx,2024-12-12】
                            var queueList = wmsDB.mes_upi_linequeue.Where(x => x.PackageCode == upiObj.PackageCode && x.AreaCode == queryAreaCode)
                                .OrderBy(x => x.Id).ToList();
                            var fisrtId = queueList.OrderBy(x => x.Id).First().Id;
                            var endId = queueList.OrderByDescending(x => x.Id).First().Id;
                            //继续查询这个时间段内的队列数据
                            //重写该队列
                            queueList = wmsDB.mes_upi_linequeue.Where(x => x.Id >= fisrtId && x.Id <= endId).OrderBy(x => x.Id).ToList();
                            var syCount = allList.Where(x => x.Shelf >= upiObj.Shelf).Count();
                            if (queueList.Count() != syCount)
                            {
                                return false;
                            }
                            else
                            {
                                //判断是否乱序
                                bool isLuanXuan = false;
                                int temp_shelf = 0;
                                for (int i = 0; i < queueList.Count; i++)
                                {
                                    if (i == 0)
                                    {
                                        temp_shelf = queueList[i].Shelf;
                                        if (temp_shelf != upiObj.Shelf)
                                        {
                                            isLuanXuan = true;
                                            return false;
                                        }
                                        if (queueList[i].Upi != upiObj.UPI)
                                        {
                                            isLuanXuan = true;
                                            return false;
                                        }
                                    }
                                    else
                                    {
                                        temp_shelf = temp_shelf + 1;
                                        if (temp_shelf != queueList[i].Shelf)
                                        {//认为乱序了
                                            isLuanXuan = true;
                                            return false;
                                        }
                                    }
                                }
 
                                if (isLuanXuan == false)
                                {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
 
            return false;
        }
    }
}