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.Reflection.Emit; 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 { /// /// 下发合包任务 /// public static class DataProcess_BZ21_IssueTask { public static async void Handler() { var alertMsg = ""; LogType logType = LogType.DataProcess_BZ21_IssueTask; while (true) { Thread.Sleep(1000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】 SystemWarningMsg._lbl_Alert_DataProcess_BZ21_IssueTask = string.Empty; try {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_IssueOutboundTask && if (SystemValue.isStartedModel) { var rgvLocation = StationLocationEnum.BZ21.ToString(); using (WmsDBModel wmsDB = new WmsDBModel()) { //不需要验证,有任务就下发,提高效率 /* //要是有已下发的任务,就不要执行 var isValidate = TaskHandler.ValidateIssueOutTaskForRobotBuffer(wmsDB); if (!isValidate) { SystemWarningMsg._lbl_Alert_DataProcess_BZ21_IssueTask = $"{rgvLocation.ToString()}-有‘已下发’的任务,不能处理,此次循环结束"; continue; } //*/ var task = wmsDB.wms_rbline_task.Where(x => x.RbTaskType == (int)RbTaskTypeEnum.合包任务 && x.TaskStatus == (int)TaskStatusEnum.新建).OrderBy(x => x.CreateTime).FirstOrDefault(); if (task == null) { SystemWarningMsg._lbl_Alert_DataProcess_BZ21_IssueTask = $"{rgvLocation.ToString()},根据 没有找到 新建 的任务 "; FormCC.currHandlerPackageCodeForIssueOutboundTask = ""; continue; } var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == task.UPI).FirstOrDefault(); if (upiObj == null) { SystemWarningMsg._lbl_Alert_DataProcess_BZ21_IssueTask = $"{rgvLocation.ToString()},根据UPI:{task.UPI}没有找到对象 "; continue; } short cartonwidth = 0;//纸箱宽 short cartonhigh = 0;//纸箱高 var upilist = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList(); var upilength = upilist.Max(x => x.Length); var upiwidth = upilist.Max(x => x.Width); cartonhigh = (short)upiObj.Info3; cartonwidth = (short)upiObj.Info2; //这里下发 任务 using (StationServiceClient client = new StationServiceClient()) { var plcres = client.WriteSurroundTaskInfo((int)EDevice.Station, rgvLocation, short.Parse(task.TaskNo), (short)upilength, (short)upiwidth, cartonhigh, cartonwidth, 0, 0); if (!plcres.result) { SystemWarningMsg._lbl_Alert_DataProcess_BZ21_IssueTask = $"{rgvLocation.ToString()}-下发入库任务 失败,WriteInStoreTaskInfoAsync 返回:{plcres.resMsg}"; continue; } else { Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,WriteInStoreTaskInfoAsync,参数: 站点{rgvLocation}"); } } task.TaskStatus = (int)TaskStatusEnum.已下发; task.TaskStatusName = TaskStatusEnum.已下发.ToString(); wmsDB.SaveChanges(); } } } catch (Exception ex) { SystemWarningMsg._lbl_Alert_DataProcess_BZ21_IssueTask += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR; Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex); } } } } }