using CirculateTool; using WcsMain.Business.CommonAction; using WcsMain.Common; using WcsMain.DataBase.Dao; using WcsMain.DataBase.TableEntity; using WcsMain.Enum; using WcsMain.EquipOperation.Entity; using WcsMain.EquipOperation.Stacker; using WcsMain.ExtendMethod; namespace WcsMain.Business.CirculationTask.Stacker; /// /// 过账,PLC任务回告 /// [Circulation()] public class CheckAccount(StackerOperation stackerOperation, AppWcsTaskDao wcsTaskDao, WCSTaskExecuteEvent wcsTaskEvent) { private readonly WCSTaskExecuteEvent _wcsTaskEvent = wcsTaskEvent; private readonly AppWcsTaskDao _wcsTaskDao = wcsTaskDao; private readonly StackerOperation _stackerOperation = stackerOperation; /// /// PLC过账 /// /// [Circulation("监控PLC地址,过账", 1000)] public bool CheckAccountTask() { var openStackers = CommonData.AppStackers.Open(); // 只获取开放的堆垛机 List? taskFeedBackEntities = _stackerOperation.GetTaskFeedBackData(20, openStackers); if (taskFeedBackEntities == default || taskFeedBackEntities.Count < 1) { return true; } foreach (TaskFeedBackEntity taskFeedBackEntity in taskFeedBackEntities) { if (taskFeedBackEntity.PlcId == 0) { continue; } List? wcsTasks = _wcsTaskDao.Select(new AppWcsTask() { PlcId = taskFeedBackEntity.PlcId }); if (wcsTasks == default) { ConsoleLog.Error($"【异常】堆垛机过账查询任务数据失败,和数据库服务器连接中断"); Thread.Sleep(2000); continue; // 网络连接中断 } if (wcsTasks.Count < 1) { ConsoleLog.Warning($"【提示】堆垛机过账区获取任务ID:{taskFeedBackEntity.PlcId},无关联任务"); _stackerOperation.ClearFeedBackData(taskFeedBackEntity); // 清除过账 continue; // 任务无数据 } var wcsTask = wcsTasks[0]; switch (taskFeedBackEntity.FeedBackType) { case (int)TaskFeedBackTypeEnum.cancel: // 任务取消 CancelTask(taskFeedBackEntity, wcsTask); break; case (int)TaskFeedBackTypeEnum.complete: // 任务完成 CompleteTask(taskFeedBackEntity, wcsTask); break; case (int)TaskFeedBackTypeEnum.doubleIn: // 重复入库 DoubleInFeedBackType(taskFeedBackEntity, wcsTask); break; case (int)TaskFeedBackTypeEnum.emptyOut: // 空出库 EmptyOutFeedBackType(taskFeedBackEntity, wcsTask); break; default: OtherTaskFeedBackType(taskFeedBackEntity); // 其他任务类型 break; } } return true; } /// /// 过账任务取消 /// /// /// private void CancelTask(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask) { ConsoleLog.Warning($"【提示】过账区反馈:PlcId:{taskFeedBackEntity.PlcId} 已经被取消,后续任务也一并取消,任务号:{wcsTask.TaskId}"); string? cleanAccountErr = _stackerOperation.ClearFeedBackData(taskFeedBackEntity); // 清除过账 if (!string.IsNullOrEmpty(cleanAccountErr)) { ConsoleLog.Warning($"【警告】取消任务清除过账区发生异常,信息:{cleanAccountErr}"); } /* 执行 WMS 任务异常动作 */ _wcsTaskEvent.ErrTaskEvent(wcsTask, "任务被PLC取消"); } /// /// 过账任务完成 /// /// /// private void CompleteTask(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask) { ConsoleLog.Tip($"【提示】过账区获取任务ID:{taskFeedBackEntity.PlcId},任务已经完成,任务号:{wcsTask.TaskId}"); var cleanAccountErr = _stackerOperation.ClearFeedBackData(taskFeedBackEntity); // 清除过账 if (!string.IsNullOrEmpty(cleanAccountErr)) { ConsoleLog.Warning($"【警告】完成任务清除过账区发生异常,信息:{cleanAccountErr}"); } /* 执行 WMS 任务完成动作 */ _wcsTaskEvent.CompleteTaskEvent(wcsTask, "PLC上报完成"); } /// /// 过账卸货位置有货 /// /// /// private void DoubleInFeedBackType(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask) { ConsoleLog.Warning($"[提示]过账区获取任务ID:{taskFeedBackEntity.PlcId},卸货位置有货,任务号:{wcsTask.TaskId}"); string? cleanAccountErr = _stackerOperation.ResetFeedBackData(taskFeedBackEntity); // 清除过账 if (!string.IsNullOrEmpty(cleanAccountErr)) { ConsoleLog.Warning($"[警告]取消任务清除过账区发生异常,信息:{cleanAccountErr}"); } /* 执行 WMS 任务异常动作 */ _wcsTaskEvent.DoubleInTaskEvent(wcsTask, "卸货位置有货"); } /// /// 过账取货位置无货 /// /// /// private void EmptyOutFeedBackType(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask) { ConsoleLog.Warning($"[警告]过账区获取任务ID:{taskFeedBackEntity.PlcId},取货位置无货,任务号:{wcsTask.TaskId}"); string? cleanAccountErr = _stackerOperation.ResetFeedBackData(taskFeedBackEntity); // 清除过账 if (!string.IsNullOrEmpty(cleanAccountErr)) { ConsoleLog.Warning($"[警告]取消任务清除过账区发生异常,信息:{cleanAccountErr}"); } /* 执行 WMS 任务异常动作 */ _wcsTaskEvent.EmptyOutTaskEvent(wcsTask, "取货位置无货"); } /// /// 其他过账类型 /// /// private void OtherTaskFeedBackType(TaskFeedBackEntity taskFeedBackEntity) { ConsoleLog.Warning($"[警告]过账区获取任务ID:{taskFeedBackEntity.PlcId},无法识别的过账类型:{taskFeedBackEntity.FeedBackType}"); _stackerOperation.ClearFeedBackData(taskFeedBackEntity); // 清除过账 } }