schangxiang@126.com
2025-04-01 2b0d3b1a9f62e5ec48e4b559f95b3d4bdc3bee09
CC/iWareCC_ASRS/ThreadService/05_BZ30(ÆëÌ×ÑéÖ¤)/DataProcess_ValidateQiTao.cs
@@ -1,109 +1,149 @@
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCC.StationService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DataAccess;
using iWareSql.DBModel;
using iWareSql.WmsDBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Configuration;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WZ.Useful.Commons;
using XiGang.Core.Model;
//using Admin.NET.Application;
//using iWareCC.Common.Helper;
//using iWareCC.StationService;
//using iWareCommon.Common.Globle;
//using iWareCommon.Utils;
//using iWareModel;
//using iWareSql.DataAccess;
//using iWareSql.DBModel;
//using iWareSql.WmsDBModel;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Runtime.Remoting.Messaging;
//using System.ServiceModel.Configuration;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
//using WZ.Useful.Commons;
//using XiGang.Core.Model;
namespace iWareCC.ThreadService
{
    /// <summary>
    /// BZ30齐套验证
    /// </summary>
    public static class DataProcess_ValidateQiTao
    {
        public static async void Handler()
        {
            var alertMsg = "";
            LogType logType = LogType.DataProcess_ValidateQiTao;
            while (true)
            {
                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = string.Empty;
                try
                {
                    if (SystemValue.isAllowRuning_DataProcess_ValidateQiTao && SystemValue.isStartedModel)
                    {
                        var rgvLocation = StationLocationEnum.BZ39.ToString();
                        if (FormCC.IsAllowRunOutMode)
                        {
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var rbRunMode = wmsDB.wms_rbline_runmode.FirstOrDefault();
//namespace iWareCC.ThreadService
//{
//    /// <summary>
//    /// BZ30齐套验证
//    /// </summary>
//    public static class DataProcess_ValidateQiTao
//    {
//        public static async void Handler()
//        {
//            var alertMsg = "";
//            LogType logType = LogType.DataProcess_ValidateQiTao;
//            while (true)
//            {
//                Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
//                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = string.Empty;
//                try
//                {
//                    //if (SystemValue.isAllowRuning_DataProcess_ValidateQiTao && SystemValue.isStartedModel)
//                    if (SystemValue.isStartedModel)
//                    {
//                        var rgvLocation = StationLocationEnum.BZ30.ToString();
                                if (TaskHandler.ValidateNoFinishOutTaskForRobotBuffer(wmsDB))
                                {//不存在
                                    rbRunMode.LineRunMode = (int)RbRunModeEnum.入库模式;
                                    rbRunMode.LineRunModeName = RbRunModeEnum.入库模式.ToString();
                                    rbRunMode.UpdateTime = DateTime.Now;
//                        using (WmsDBModel wmsDB = new WmsDBModel())
//                        {
//                            var bz30Config = wmsDB.SysConfig.Where(x => x.Code == "wms_bz30_qitao").FirstOrDefault();
//                            if (bz30Config == null)
//                            {
//                                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"没有配置 wms_bz30_qitao å€¼";
//                                continue;
//                            }
//                            var configValue = bz30Config.Value;
//                            if (string.IsNullOrEmpty(configValue) || configValue.IndexOf('|') <= -1)
//                            {
//                                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"配置 wms_bz30_qitao å€¼{configValue}为空或不正确";
//                                continue;
//                            }
//                            var configValues = configValue.Split('|');
//                            var packageCode = configValues[0];
//                            var qitaoValue = configValues[1];//齐套  ä¸é½å¥—
//                            var _UnlinePerson = configValues[2];
//                            bool iscomplete = false;
//                            if (qitaoValue.Equals("齐套"))
//                            {
//                                iscomplete = true;
//                            }
//                            //TODO:推送给PLC åŽ»å“ªä¸ªæ–¹å‘ï¼Ÿ
                                    //推送给PLC切换模式
                                    using (StationServiceClient client = new StationServiceClient())
                                    {
                                        var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.入库模式, rgvLocation);
                                        if (!res.result)
                                        {
                                            SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"{rgvLocation.ToString()}-推送给PLC切换模式 å¤±è´¥,ChangeModeAsync è¿”回:{res.resMsg}";
                                            continue;
                                        }
                                        else
                                        {
                                            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
                                        }
                                    }
                                    FormCC.IsAllowRunOutMode = false;
                                }
                                else
                                {//存在
                                    if (rbRunMode.LineRunMode == (int)RbRunModeEnum.出库模式)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"已经是出库模式了,此次循环结束";
                                        continue;
                                    }
                                    rbRunMode.LineRunMode = (int)RbRunModeEnum.出库模式;
                                    rbRunMode.LineRunModeName = RbRunModeEnum.出库模式.ToString();
                                    rbRunMode.UpdateTime = DateTime.Now;
//                            using (StationServiceClient client = new StationServiceClient())
//                            {
//                                var res = client.WriteQiTaoInfo((int)EDevice.Station, rgvLocation, iscomplete);
//                                if (!res.result)
//                                {
//                                    SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"{rgvLocation.ToString()}-推送给PLC是否齐套失败,ChangeModeAsync è¿”回:{res.resMsg}";
//                                    continue;
//                                }
//                                else
//                                {
//                                    Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC是否齐套 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
//                                }
//                            }
//                            //
                                    //推送给PLC切换模式
                                    using (StationServiceClient client = new StationServiceClient())
                                    {
                                        var res = await client.ChangeModeAsync((int)EDevice.Station, (int)RbRunModeEnum.出库模式, rgvLocation);
                                        if (!res.result)
                                        {
                                            SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = $"{rgvLocation.ToString()}-推送给PLC切换模式 å¤±è´¥,ChangeModeAsync è¿”回:{res.resMsg}";
                                            continue;
                                        }
                                        else
                                        {
                                            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-推送给PLC切换模式 æˆåŠŸ,ChangeModeAsync,参数: ç«™ç‚¹{rgvLocation}");
                                        }
                                    }
                                }
                                wmsDB.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao += " å‡ºçް异叏:" + ex.Message + SysGloble.SPLIT_STR;
                    Log4NetHelper.WriteErrorLog(logType, " å‡ºçŽ°å¼‚å¸¸ï¼š" + ex.Message, ex);
                }
            }
        }
//                            //更新值
//                            bz30Config.Value = "";
//                            var package = wmsDB.mes_package_gather.Where(x => x.PackageCode == packageCode).FirstOrDefault();
//                            if (package != null)
//                            {
//                                package.UpiStatus = (int)UpiStatusEnum.已下线;
//                                package.AreaCode = (int)AreaCodeEnum.下线区域;
//                            }
//                            var upiList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == packageCode).ToList();
//                            foreach (var item in upiList)
//                            {
//                                item.UpiStatus = (int)UpiStatusEnum.已下线;
//                                item.AreaCode = (int)AreaCodeEnum.下线区域;
//                                item.UpdateTime = DateTime.Now;
//                            }
//                            //删除队列信息
//                            var lineQueue = wmsDB.mes_package_linequeue.Where(x => x.PackageCode == packageCode).FirstOrDefault();
//                            if (lineQueue != null)
//                            {
//                                wmsDB.mes_package_linequeue.Remove(lineQueue);
//                            }
    }
}
//                            //处理表  mes_order_gather
//                            var errmsg = "";
//                            var result = MyExtendHelper.HandlerOrderGather(wmsDB, package, qitaoValue, _UnlinePerson, out errmsg);
//                            if (result == false)
//                            {
//                                SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao = errmsg;
//                                continue;
//                            }
//                            //新增下线记录
//                            //判断如果包已经下线了,就不再写入下线记录了
//                            var existPackObj = wmsDB.mes_package_unline_record.Where(x => x.PackageCode == package.PackageCode).FirstOrDefault();
//                            if (existPackObj == null)
//                            {
//                                mes_package_unline_record record = new mes_package_unline_record();
//                                record = ClassHelper.RotationMapping<mes_package_unline_record, mes_package_gather>(package);
//                                record.Id = Yitter.IdGenerator.YitIdHelper.NextId();
//                                record.CreateTime = DateTime.Now;
//                                record.UpdateTime = DateTime.Now;
//                                record.OpRemark = "下线";
//                                wmsDB.mes_package_unline_record.Add(record);
//                            }
//                            WmsRecordUpiProcessHandler.SaveWmsRecordPackageProcess(wmsDB, package, "BZ30", "齐套验证");
//                            wmsDB.SaveChanges();
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_DataProcess_ValidateQiTao += " å‡ºçް异叏:" + ex.Message + SysGloble.SPLIT_STR;
//                    Log4NetHelper.WriteErrorLog(logType, " å‡ºçŽ°å¼‚å¸¸ï¼š" + ex.Message, ex);
//                }
//            }
//        }
//    }
//}