using JSMachine.WMS.App.Dto; using JSMachine.WMS.App.Dto.Enum; using JSMachine.WMS.App.IService; using JSMachine.WMS.Business.Common.IService; using JSMachine.WMS.Infrastructure; using JSMachine.WMS.Infrastructure.Helper; using JSMachine.WMS.Job.Enum; using JSMachine.WMS.Job.JobAttributes; using Quartz; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSMachine.WMS.Job.Job { /// /// 中转区域调度作业 /// [DisallowConcurrentExecution] [PersistJobDataAfterExecution] [Job(Name = nameof(TransferAreaJob) , Group = nameof(TransferAreaJob) + "_Group" , Description = "中转区域作业调度" , ScheduleType = ScheduleType.Simple , IntervalMilliSeconds = 2000 , RepeatCount = 0 , StartTimeStr = null)] public class TransferAreaJob : IJob { private static readonly IERPTaskService ERPTaskService = GlobalServericeProvidor.GetService(); private static readonly IAGVTaskService AgvTaskService = GlobalServericeProvidor.GetService(); private static readonly ICommonService CommonService = GlobalServericeProvidor.GetService(); private static readonly IStorageRackService StorageRackService = GlobalServericeProvidor.GetService(); public async Task Execute(IJobExecutionContext context) { //1.查询关联的erp任务类型 //2.如果是出库,且任务批次和当前物料批次一致(这种情况是出库没有可用的提升机库位,从而暂时运到中转区),则该任务需要去往提升机出库 //3.除了2以外的所有情况,均搬运到存储区 StorageRackDto storageRack = await StorageRackService.GetSingalByExpression(p => p.Transport == TransportEnum.TransitArea && !p.IsLock && !p.IsDisabled && !string.IsNullOrEmpty(p.BarCode)); if (storageRack == null) { return; } AGVTaskDto lastAgvTaskRelated = await AgvTaskService.GetSingalByExpression( p => p.EndPositionCode == storageRack.StorageRackNo, p => p.CreationTime, SqlSugar.OrderByType.Desc ); if (lastAgvTaskRelated==null) { LogHelper.Error($"中转区业务 未查询到物料 {storageRack.BarCode} 上一次agv任务,无法调度该物料,需要手动处理"); return; } ERPTaskDto erpTask = await ERPTaskService.GetSingalByExpression(p => p.Id == lastAgvTaskRelated.ErpTaskId); if(erpTask==null) { LogHelper.Error($"中转区业务 未查询到物料 {storageRack.BarCode} 关联的erp任务,无法调度该物料,需要手动处理"); return; } bool bRet = await CommonService.CreateAgvTaskFromTransferArea(storageRack, lastAgvTaskRelated, erpTask); if(!bRet) { _ = ERPTaskService.UpdateTaskMsg(erpTask.Id, "中转区作业调度中,存储区已满或者无可用提升机库位,调度失败"); LogHelper.Error("中转区作业调度中,存储区已满或者无可用提升机库位,调度失败"); } else { _ = ERPTaskService.UpdateTaskMsg(erpTask.Id, ""); } } } }