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.WmsDBModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace iWareCC.ThreadService._03_BZ12_机器人码包工位_ { public class DataProcess_BZ12 { public static async void Hander() { var alertMsg = ""; LogType logType = LogType.DataProcess_BZ12; while (true) { Thread.Sleep(600);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】 SystemWarningMsg._lbl_alert_DataProcess_BZ12 = string.Empty; try { if (SystemValue.isStartedModel) { var rgvLocation = StationLocationEnum.BZ12.ToString(); /* * 1、从数据库中判断是否齐套 * 2、根据齐套结果,推送给PLC */ if (FormCC.stationView == null) { SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-获取PLC对象为null"; continue; } var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault(); if (obj.R_PalletizingAck) { //给PLC推送任务完接收完成复位信号 using (StationServiceClient client = new StationServiceClient()) { var res = client.WriteStation_ACK((int)EDevice.Station, false, rgvLocation); if (!res.result) { SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-下发码板任务 失败,SetPalletizingTaskFinishAck 返回:{res.resMsg}"; continue; } else { Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,SetPalletizingTaskFinishAck,参数: 站点{rgvLocation}"); } } } if (obj.R_ReqParseData) { var result = obj.R_ReadCodeResult; if (string.IsNullOrEmpty(result)) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束"; continue; } var upiCode = result.Replace("/r", ""); ; short lastnum = 0;//是否末板 string place = ""; using (WmsDBModel wmsDB = new WmsDBModel()) { //要是有已下发的任务,就不要执行 var isValidate = TaskHandler.ValidateIssueTaskForNoFinishTaskByUpi(wmsDB, result, false); if (!isValidate) { SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-upi:{result}有‘已下发’的任务,不能处理,此次循环结束"; continue; } /* isValidate = TaskHandler.ValidateNoFinishOutTaskFor码板任务(wmsDB); if (!isValidate) { SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-有 未结束 的任务,不能处理,此次循环结束"; continue; } //*/ var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault(); if (upiObj == null) { //写入报警信息 await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_1); SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 "; continue; } //isrotate = short.Parse(upiObj.Info17); //placeX = (short)upiObj.MachineXCenter; //placeY = (short)upiObj.MachineYCenter; //placeZ = (short)upiObj.MachineZCenter; if (upiObj.UpiStatus == (int)UpiStatusEnum.已码垛 || upiObj.UpiStatus == (int)UpiStatusEnum.码垛中) { SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},根据UPI:{upiCode}状态已是'已码垛'或'码垛中' "; MyExtendHelper.SetValueControlRequestDicts(PlcWarningAddressGloble.Num_BZ12_3, false, SystemWarningMsg._lbl_alert_DataProcess_BZ12); var isAllow = MyExtendHelper.ValidateIsAllowRequest(PlcWarningAddressGloble.Num_BZ12_3, LogType.DataProcess_BZ12); if (isAllow == false) { continue; } else { //写入报警信息 await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_3); } continue; } MyExtendHelper.SetValueControlRequestDicts(PlcWarningAddressGloble.Num_BZ12_3, true, ""); upiObj.UpiStatus = (int)UpiStatusEnum.码垛中; upiObj.AreaCode = (int)AreaCodeEnum.码垛区域; //查处这包所有的数量 var upiList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList(); //查询是否末板并且判断有没有混批 //增加对参数配置的管理 【Editby shaocx,2024-12-13】 var sysConfig = wmsDB.SysConfig.Where(x => x.Code == "LastPalletizingData").FirstOrDefault(); if (sysConfig == null) { SystemWarningMsg._lbl_alert_DataProcess_BZ01 = $"没有获取到 LastPalletizingData 的配置信息 "; continue; } string palletizingUPI = ""; int palletizingStation = 0; var config_value = sysConfig.Value; if (config_value.IndexOf('|') > -1) {//格式为 包装号|站点 var arr = config_value.Split('|'); palletizingUPI = arr[0]; palletizingStation = Convert.ToInt32(arr[1]); } else {//表示还没有配置 } //查询是否混批 if (!string.IsNullOrEmpty(palletizingUPI)) { if (upiObj.PackageCode != palletizingUPI) { //写入报警信息 await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_4); SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}码包部件混批 "; continue; } } //获取码垛目标位 if (palletizingStation != 0) { place = palletizingStation.ToString(); } else {//表示这是 包的第一块板 palletizingUPI = upiObj.PackageCode; if (obj.R_PalletizingStation1 == 1) { place = "1"; } else if (obj.R_PalletizingStation2 == 1) { place = "2"; } else { //去掉报警,不再校验这个了 place = "1"; /* //写入报警信息 await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_6); SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}无可用码垛目标位 "; continue; //*/ } palletizingStation = int.Parse(place); } //如果次序等于当钱包总数量,是否末板置为true if (upiObj.Shelf == upiList.Count()) { lastnum = 2;//(1首件,2末件,0为中间板) palletizingUPI = null; palletizingStation = 0; } else if (upiObj.Shelf == 1) { lastnum = 1;//(1首件,2末件,0为中间板) } else { lastnum = 0;//(1首件,2末件,0为中间板) } //查询有没有次序小于当前次序并且没有码垛的 var oldupi = upiList.Where(x => x.Shelf < upiObj.Shelf && (x.UpiStatus != (int)UpiStatusEnum.已码垛 && x.UpiStatus != (int)UpiStatusEnum.码垛中)).FirstOrDefault(); if (oldupi != null) { //写入报警信息 await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_5); SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}码包顺序错误 "; continue; } //记录任务 var _id = Yitter.IdGenerator.YitIdHelper.NextId(); var plcTaskNo = BusinessHelper.CreatePlcTaskId(); plcTaskNo = MyExtendHelper.GetNewTaskNo(wmsDB, RbTaskTypeEnum.码板任务, plcTaskNo); var task = new wms_rbline_task() { Id = _id, TaskNo = plcTaskNo, Upi = upiObj.UPI, Length = upiObj.Length, Width = upiObj.Width, Thk = upiObj.Thk, PlanNo = upiObj.PlanNo, OrderId = upiObj.OrderId, PackageCode = upiObj.PackageCode, RbTaskType = (int)RbTaskTypeEnum.码板任务, TaskStatus = (int)TaskStatusEnum.新建, TaskMsg = "码板", CreateTime = DateTime.Now, CreateUserName = SysGloble.WCSSystem, UpdateTime = DateTime.Now, UpdateUserName = SysGloble.WCSSystem, PlaceCode = place, LastNum = lastnum, Info17 = upiObj.Info17, MachineXCenter = upiObj.MachineXCenter, MachineYCenter = upiObj.MachineYCenter, MachineZCenter = upiObj.MachineZCenter, Sequence = upiObj.Sequence, }; wmsDB.wms_rbline_task.Add(task); //更新配置 sysConfig.Value = palletizingUPI + "|" + palletizingStation + "|" + upiObj.UPI + "|第" + upiObj.Shelf + "块"; WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, "BZ12站点", "码包"); wmsDB.SaveChanges(); } } else { SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-没有要处理的数据"; } } } catch (Exception ex) { SystemWarningMsg._lbl_alert_DataProcess_BZ12 += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR; Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex); } } } } }