Product_Wms/WcsMain/CirculationJob/Stacker/CheckAccount.cs

155 lines
6.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CirculateTool.Attribute;
using WcsMain.Business.CommonAction;
using WcsMain.Common;
using WcsMain.Constant.Enum;
using WcsMain.Constant.ExtendMethod;
using WcsMain.DataBase.Dao;
using WcsMain.DataBase.TableEntity;
using WcsMain.EquipOperation.Entity;
using WcsMain.EquipOperation.Stacker;
namespace WcsMain.CirculationJob.Stacker;
/// <summary>
/// 过账PLC任务回告
/// </summary>
//[Circulation()]
public class CheckAccount(StackerOperation stackerOperation, AppWcsTaskDao wcsTaskDao, WCSTaskExecuteEvent wcsTaskEvent)
{
/// <summary>
/// PLC过账
/// </summary>
/// <returns></returns>
[Circulation("监控PLC地址过账", 1000)]
public bool CheckAccountTask()
{
var openStackers = CommonData.AppStackers.Open(); // 只获取开放的堆垛机
List<TaskFeedBackEntity>? taskFeedBackEntities = stackerOperation.GetTaskFeedBackData(20, openStackers);
if (taskFeedBackEntities == default || taskFeedBackEntities.Count < 1)
{
return true;
}
foreach (TaskFeedBackEntity taskFeedBackEntity in taskFeedBackEntities)
{
if (taskFeedBackEntity.PlcId == 0) { continue; }
List<AppWcsTask>? 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.ResetFeedBackData(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;
}
/// <summary>
/// 过账任务取消
/// </summary>
/// <param name="taskFeedBackEntity"></param>
/// <param name="wcsTask"></param>
private void CancelTask(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask)
{
ConsoleLog.Warning($"【提示】过账区反馈PlcId{taskFeedBackEntity.PlcId} 已经被取消,后续任务也一并取消,任务号:{wcsTask.TaskId},箱号:{wcsTask.VehicleNo}");
string? cleanAccountErr = stackerOperation.ResetFeedBackData(taskFeedBackEntity); // 清除过账
if (!string.IsNullOrEmpty(cleanAccountErr))
{
ConsoleLog.Warning($"【警告】取消任务清除过账区发生异常,信息:{cleanAccountErr}");
}
/* 执行 WMS 任务异常动作 */
wcsTaskEvent.ErrTaskEvent(wcsTask, "任务被PLC取消");
}
/// <summary>
/// 过账任务完成
/// </summary>
/// <param name="taskFeedBackEntity"></param>
/// <param name="wcsTask"></param>
private void CompleteTask(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask)
{
ConsoleLog.Tip($"【提示】过账区获取任务ID{taskFeedBackEntity.PlcId},任务已经完成,任务号:{wcsTask.TaskId},箱号:{wcsTask.VehicleNo}");
var cleanAccountErr = stackerOperation.ResetFeedBackData(taskFeedBackEntity); // 清除过账
if (!string.IsNullOrEmpty(cleanAccountErr))
{
ConsoleLog.Warning($"【警告】完成任务清除过账区发生异常,信息:{cleanAccountErr}");
}
/* 执行 WMS 任务完成动作 */
wcsTaskEvent.CompleteTaskEvent(wcsTask, "PLC上报完成");
}
/// <summary>
/// 过账卸货位置有货
/// </summary>
/// <param name="taskFeedBackEntity"></param>
/// <param name="wcsTask"></param>
private void DoubleInFeedBackType(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask)
{
ConsoleLog.Warning($"[提示]过账区获取任务ID{taskFeedBackEntity.PlcId},卸货位置有货,任务号:{wcsTask.TaskId},箱号:{wcsTask.VehicleNo}");
string? cleanAccountErr = stackerOperation.ResetFeedBackData(taskFeedBackEntity); // 清除过账
if (!string.IsNullOrEmpty(cleanAccountErr))
{
ConsoleLog.Warning($"[警告]取消任务清除过账区发生异常,信息:{cleanAccountErr}");
}
/* 执行 WMS 任务异常动作 */
wcsTaskEvent.DoubleInTaskEvent(wcsTask, "卸货位置有货");
}
/// <summary>
/// 过账取货位置无货
/// </summary>
/// <param name="taskFeedBackEntity"></param>
/// <param name="wcsTask"></param>
private void EmptyOutFeedBackType(TaskFeedBackEntity taskFeedBackEntity, AppWcsTask wcsTask)
{
ConsoleLog.Warning($"[警告]过账区获取任务ID{taskFeedBackEntity.PlcId},取货位置无货,任务号:{wcsTask.TaskId},箱号:{wcsTask.VehicleNo}");
string? cleanAccountErr = stackerOperation.ResetFeedBackData(taskFeedBackEntity); // 清除过账
if (!string.IsNullOrEmpty(cleanAccountErr))
{
ConsoleLog.Warning($"[警告]取消任务清除过账区发生异常,信息:{cleanAccountErr}");
}
/* 执行 WMS 任务异常动作 */
wcsTaskEvent.EmptyOutTaskEvent(wcsTask, "取货位置无货");
}
/// <summary>
/// 其他过账类型
/// </summary>
/// <param name="taskFeedBackEntity"></param>
private void OtherTaskFeedBackType(TaskFeedBackEntity taskFeedBackEntity)
{
ConsoleLog.Warning($"[警告]过账区获取任务ID{taskFeedBackEntity.PlcId},无法识别的过账类型:{taskFeedBackEntity.FeedBackType}");
stackerOperation.ClearFeedBackData(taskFeedBackEntity); // 清除过账
}
}