schangxiang@126.com
2025-04-17 37184b1d1ac000a6ee40e397e2336b213e705902
CC/iWareCC_ASRS/ThreadService/01_BZ01¹¤Î»£¨Çå»Ò£¬Ï´°åºó¹¤Î»£©/DataProcess_BZ01.cs
@@ -11,6 +11,7 @@
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;
@@ -24,6 +25,8 @@
    /// </summary>
    public static class DataProcess_BZ01
    {
        public static string timingForWait = "";//定时器,等待数据
        /// <summary>
        /// BZ01工位(清灰,洗板后工位)
        /// </summary>
@@ -32,6 +35,7 @@
            var alertMsg = "";
            LogType logType = LogType.DataProcess_BZ01;
            string lastUpi = "";//最后记录的UPI数据
            while (true)
            {
                Thread.Sleep(1000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
@@ -45,6 +49,7 @@
                            SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"正在干出库模式,此方法暂停。。 ";
                            continue;
                        }
                        var rgvLocation = StationLocationEnum.BZ01.ToString();
                        /*
@@ -65,13 +70,48 @@
                                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束";
                                continue;
                            }
                            if (lastUpi == result)
                            {
                                SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"{rgvLocation.ToString()}-重复的UPI{result}";
                                continue;
                                //寻找上次的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;
                            lastUpi = upiCode;
                            var qitaoReault = false;//齐包结果
                            using (WmsDBModel wmsDB = new WmsDBModel())
@@ -141,7 +181,46 @@
                                    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.缓存分拣区;
@@ -150,7 +229,7 @@
                                {
                                    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.待缓存分拣区
@@ -267,13 +346,15 @@
                                        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);
@@ -314,8 +395,25 @@
                                        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;
@@ -343,6 +441,46 @@
            }
        }
        /// <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>
        /// æ˜¯å¦å¯ä»¥æ‰§è¡Œå‡ºåº“模式
@@ -352,6 +490,10 @@
        /// <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.强制出库任务)
@@ -419,6 +561,8 @@
            FormCC.IsAllowRunOutMode = true;
            return true;
            //*/
        }
        /// <summary>
@@ -429,6 +573,10 @@
        /// <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.待缓存分拣区