| using Admin.NET.Application; | 
| using iWareCC.StationService; | 
| using iWareCommon.Common.Globle; | 
| using iWareCommon.Utils; | 
| using iWareModel; | 
| using iWareSql.DataAccess; | 
| using iWareSql.WmsDBModel; | 
| using System; | 
| using System.Linq; | 
| using System.Threading; | 
|   | 
| namespace iWareCC.ThreadService | 
| { | 
|     /// <summary> | 
|     /// 机器人缓存岛出库任务完成处理 | 
|     /// </summary> | 
|     public static class DataProcess_RobotBuffer_FinishTaskForOutbound | 
|     { | 
|         public static async void Handler() | 
|         { | 
|             var alertMsg = ""; | 
|             LogType logType = LogType.DataProcess_RobotBuffer_FinishTaskForOutbound; | 
|             while (true) | 
|             { | 
|                 Thread.Sleep(500);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】 | 
|                 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = string.Empty; | 
|                 try | 
|                 { | 
|                     if (SystemValue.isAllowRuning_DataProcess_RobotBuffer_FinishTaskForOutbound && SystemValue.isStartedModel) | 
|                     { | 
|                         var rgvLocation = StationLocationEnum.BZ39.ToString(); | 
|                         var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault(); | 
|                         if (obj.R_OutboundFinish) | 
|                         { | 
|                             //var result = obj.R_OutboundNumber; | 
|                             //if (string.IsNullOrEmpty(result)) | 
|                             //{ | 
|                             //    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}- 出库库位号是空的,此次循环结束"; | 
|                             //    continue; | 
|                             //} | 
|   | 
|                             var result2 = obj.R_Outbound_TaskID; | 
|                             if (result2 == 0) | 
|                             { | 
|                                 SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}- 出库任务号是空的,此次循环结束"; | 
|                                 continue; | 
|                             } | 
|   | 
|   | 
|   | 
|                             using (WmsDBModel wmsDB = new WmsDBModel()) | 
|                             { | 
|                                 var task = wmsDB.wms_rbline_task.Where(x => | 
|                                  x.TaskNo == obj.R_Outbound_TaskID.ToString() | 
|                                 && x.RbTaskType == (int)RbTaskTypeEnum.出库任务 | 
|                                 && x.TaskStatus == (int)TaskStatusEnum.已下发).FirstOrDefault(); | 
|                                 if (task == null) | 
|                                 { | 
|                                     SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据 R_OutboundNumber:{obj.R_OutboundNumber}没有找到已下发的任务 "; | 
|                                     continue; | 
|                                 } | 
|   | 
|                                 var upiCode = task.UPI; | 
|                                 var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault(); | 
|                                 if (upiObj == null) | 
|                                 { | 
|                                     SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 "; | 
|                                     continue; | 
|                                 } | 
|                                 //库存减少 | 
|                                 wms_stock_quan qun = wmsDB.wms_stock_quan.Where(x => x.PlaceCode == task.PlaceCode).FirstOrDefault(); | 
|                                 wmsDB.wms_stock_quan.Remove(qun); | 
|   | 
|                                 task.TaskStatus = (int)TaskStatusEnum.已完成; | 
|                                 task.TaskStatusName = TaskStatusEnum.已完成.ToString(); | 
|                                 task.FinishedTime = DateTime.Now; | 
|   | 
|                                 var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB); | 
|                                 place.PlaceStatus = (int)PlaceStatusEnum.正常; | 
|   | 
|                                 //给PLC推送任务完成确认信号 | 
|                                 using (StationServiceClient client = new StationServiceClient()) | 
|                                 { | 
|                                     var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation); | 
|                                     if (!res.result) | 
|                                     { | 
|                                         SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 失败,OutboundFinishConfirmAsync 返回:{res.resMsg}"; | 
|                                         continue; | 
|                                     } | 
|                                     else | 
|                                     { | 
|                                         Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 成功,OutboundFinishConfirmAsync,参数: 站点{rgvLocation}"); | 
|                                     } | 
|                                 } | 
|   | 
|                                 wmsDB.SaveChanges(); | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|                 catch (Exception ex) | 
|                 { | 
|                     SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR; | 
|                     Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex); | 
|                 } | 
|             } | 
|         } | 
|   | 
|     } | 
| } |