//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 //{ // /// // /// 机器人缓存岛 自动下发出库任务 处理 // /// // public static class DataProcess_RobotBuffer_IssueOutboundTask // { // public static async void Handler() // { // var alertMsg = ""; // LogType logType = LogType.DataProcess_RobotBuffer_IssueOutboundTask; // while (true) // { // Thread.Sleep(1000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】 // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = string.Empty; // try // {//SystemValue.isAllowRuning_DataProcess_RobotBuffer_IssueOutboundTask && // if (SystemValue.isStartedModel) // { // var rgvLocation = StationLocationEnum.BZ39.ToString(); // /* // * 1、从数据库中判断是否齐套 // * 2、根据齐套结果,推送给PLC // */ // using (WmsDBModel wmsDB = new WmsDBModel()) // { // var noFinishOutTask = TaskHandler.ValidateIssueTaskForNoFinishTaskByOutStore(wmsDB); // if (noFinishOutTask == true) // {//表示没有未结束的出库任务,那么就 初始化请求出库指令 // using (StationServiceClient client = new StationServiceClient()) // { // var res = await client.WriteOutStoreTaskInfoAsync(true, (int)EDevice.Station, rgvLocation, "", 0); // if (!res.result) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-初始化请求出库指令 失败,WriteOutStoreTaskInfoAsync 返回:{res.resMsg}"; // continue; // } // else // { // //Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-初始化请求出库指令 成功,WriteOutStoreTaskInfoAsync,参数: 站点{rgvLocation}"); // } // } // } // //要是有已下发的任务,就不要执行 // var isValidate = TaskHandler.ValidateIssueOutTaskForRobotBuffer(wmsDB); // if (!isValidate) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-有‘已下发’的任务,不能处理,此次循环结束"; // continue; // } // //取创建时间最早的那个要出库的包 // if (string.IsNullOrEmpty(FormCC.currHandlerPackageCodeForIssueOutboundTask)) // { // var firstTask = wmsDB.wms_rbline_task.Where(x => // (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务) // && x.TaskStatus == (int)TaskStatusEnum.新建).OrderBy(x => x.CreateTime).FirstOrDefault(); // if (firstTask == null) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},根据 没有找到 新建 的任务 "; // FormCC.currHandlerPackageCodeForIssueOutboundTask = ""; // continue; // } // FormCC.currHandlerPackageCodeForIssueOutboundTask = firstTask.PackageCode; // } // else // { // var firstTask = wmsDB.wms_rbline_task.Where(x => // (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务) // && x.TaskStatus == (int)TaskStatusEnum.新建 // && x.PackageCode == FormCC.currHandlerPackageCodeForIssueOutboundTask // ).OrderBy(x => x.CreateTime).FirstOrDefault(); // if (firstTask == null) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},根据 没有找到 新建 的任务 "; // FormCC.currHandlerPackageCodeForIssueOutboundTask = ""; // continue; // } // } // var taskList = wmsDB.wms_rbline_task.Where(x => // (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务) // && x.TaskStatus == (int)TaskStatusEnum.新建).Where(x => x.PackageCode == FormCC.currHandlerPackageCodeForIssueOutboundTask).OrderBy(x => x.CreateTime).ToList(); // if (taskList == null) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()},根据 没有找到 新建 的任务 "; // continue; // } // var doTask = taskList.FirstOrDefault(); // ////这里下发 出库任务 // //using (StationServiceClient client = new StationServiceClient()) // //{ // // //首先要清理 // // //var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation); // // //if (!res.result) // // //{ // // // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 失败,OutboundFinishConfirmAsync 返回:{res.resMsg}"; // // // continue; // // //} // // //else // // //{ // // // Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 成功,OutboundFinishConfirmAsync,参数: 站点{rgvLocation}"); // // //} // // var res = await client.WriteOutStoreTaskInfoAsync(false, (int)EDevice.Station, rgvLocation, doTask.PlaceCode, Convert.ToInt32(doTask.TaskNo)); // // if (!res.result) // // { // // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-下发出库任务 失败,WriteOutStoreTaskInfoAsync 返回:{res.resMsg}"; // // continue; // // } // // else // // { // // Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 成功,WriteOutStoreTaskInfoAsync,参数: 站点{rgvLocation}"); // // } // //} // doTask.TaskStatus = (int)TaskStatusEnum.已下发; // doTask.IssueTime = DateTime.Now; // int changeNum = wmsDB.SaveChanges(); // if (changeNum > 0) // { // //必须要给PLC下发成功,解决可能会给PLC重复下发任务的情况 // var isRight = true; // while (isRight) // { // //这里下发 出库任务 // using (StationServiceClient client = new StationServiceClient()) // { // var res = await client.WriteOutStoreTaskInfoAsync(false, (int)EDevice.Station, rgvLocation, doTask.PlaceCode, Convert.ToInt32(doTask.TaskNo)); // if (!res.result) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask = $"{rgvLocation.ToString()}-下发出库任务 失败,WriteOutStoreTaskInfoAsync 返回:{res.resMsg}参数: PlaceCode:{doTask.PlaceCode},TaskNo:{doTask.TaskNo}"; // Log4NetHelper.WriteErrorLog(logType, $"{rgvLocation.ToString()}-下发出库任务 失败,WriteOutStoreTaskInfoAsync,参数: PlaceCode:{doTask.PlaceCode},TaskNo:{doTask.TaskNo},条码:{doTask.Upi}"); // continue; // } // else // { // Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 成功,WriteOutStoreTaskInfoAsync,参数: PlaceCode:{doTask.PlaceCode},TaskNo:{doTask.TaskNo},条码:{doTask.Upi}"); // isRight = false; // } // } // Thread.Sleep(1000); // } // } // } // } // } // catch (Exception ex) // { // SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_IssueOutboundTask += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR; // Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex); // } // } // } // } //}