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; namespace iWareCC.ThreadService { /// /// BZ39工位(补板后工位) /// public static class DataProcess_BZ39 { public static async void Handler() { var alertMsg = ""; LogType logType = LogType.DataProcess_BZ39; while (true) { Thread.Sleep(1000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】 SystemWarningMsg._lbl_alert_DataProcess_BZ39 = string.Empty; try { if (SystemValue.isAllowRuning_DataProcess_BZ39 && SystemValue.isStartedModel) { var rgvLocation = StationLocationEnum.BZ39.ToString(); /* * 1、从数据库中判断是否齐套 * 2、根据齐套结果,推送给PLC */ 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_BZ39 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束"; continue; } var upiCode = result; var qitaoReault = false; using (WmsDBModel wmsDB = new WmsDBModel()) { //不再拦截 /* //要是有已下发的任务,就不要执行 var isValidate = TaskHandler.ValidateIssueTaskForRobotBuffer(wmsDB); if (!isValidate) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-有‘已下发’的任务,不能处理,此次循环结束"; continue; } //*/ var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault(); if (upiObj == null) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 "; continue; } //了解他的长、宽、高,寻找空库位 var place = StationHandlerV2.FindBestEmptyPlace(wmsDB, upiObj); if (place == null) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到缓存区岛的空库位 "; continue; } //记录任务 var _id = Yitter.IdGenerator.YitIdHelper.NextId(); var plcTaskNo = BusinessHelper.CreatePlcTaskIdForSrmTask(); var task = new wms_rbline_task() { Id = _id, TaskNo = plcTaskNo, UPI = upiObj.UPI, Length = upiObj.Length, Width = upiObj.Width, Thk = upiObj.Thk, IssueTime = DateTime.Now, PlanNo = upiObj.PlanNo, OrderId = upiObj.OrderId, PackageCode = upiObj.PackageCode, PlaceCode = place.PlaceCode, RbTaskType = (int)RbTaskTypeEnum.入库任务, RbTaskTypeEnumName = RbTaskTypeEnum.入库任务.ToString(), TaskStatus = (int)TaskStatusEnum.已下发, TaskStatusName = TaskStatusEnum.已下发.ToString(), TaskMsg = "入库", CreateTime = DateTime.Now, CreateUserName = "CC", UpdateTime = DateTime.Now, UpdateUserName = "CC", }; wmsDB.wms_rbline_task.Add(task); using (StationServiceClient client = new StationServiceClient()) { //不再拦截 /* //首先先清理 var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation); if (!res.result) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-下发入库任务 失败,InboundFinishConfirmAsync 返回:{res.resMsg}"; continue; } else { Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,InboundFinishConfirmAsync,参数: 站点{rgvLocation}"); } //*/ var res = await client.WriteInStoreTaskInfoAsync((int)EDevice.Station, rgvLocation, place.PlaceCode, (short)upiObj.Length, (short)upiObj.Width, (short)upiObj.Thk, Convert.ToInt32(task.TaskNo)); if (!res.result) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-下发入库任务 失败,WriteInStoreTaskInfoAsync 返回:{res.resMsg}"; continue; } else { Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,WriteInStoreTaskInfoAsync,参数: 站点{rgvLocation}"); } } place.PlaceStatus = (int)PlaceStatusEnum.锁定; wmsDB.SaveChanges(); } } } } catch (Exception ex) { SystemWarningMsg._lbl_alert_DataProcess_BZ39 += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR; Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex); } } } } }