From a44845ea196133fb67f14bfa347f9984810df348 Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 26 Dec 2023 09:13:36 +0800 Subject: [PATCH] change. --- .../Jobs/Job_BoxFoamInStoreTask_Quartz.cs | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs b/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs index be229546..c6254245 100644 --- a/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs +++ b/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs @@ -90,6 +90,8 @@ namespace Admin.Core.Tasks private string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code private List allSpaces = null; private List spaceAddresses = new List(); + private SemaphoreSlim _lock = new SemaphoreSlim(1); + public Job_BoxFoamInStoreTask_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService, IBaseSpaceInfoServices baseSpaceInfoServices, IRealTaskInfoServices realTaskInfoService, IProductPlanInfoServices productPlanInfoServices, IRecordInStoreServices recordInstoreServices, @@ -119,7 +121,7 @@ namespace Admin.Core.Tasks public async Task Execute(IJobExecutionContext context) { // 获取任务下发plc - // await ExecuteJob(context, async () => await PassDown(context)); + await ExecuteJob(context, async () => await PassDown(context)); // 监测入库,出库完成信号 // await ExecuteJob(context, async () => await RealInstoreFinish(context)); } @@ -140,7 +142,7 @@ namespace Admin.Core.Tasks if (obj.plc.ReadInt16(spaceAddress.outStoreFinish) == 1) { obj.plc.WriteInt16(spaceAddress.outStoreFinish, "0"); - // 减货道明细 + // 减货道明细 } } } @@ -152,39 +154,50 @@ namespace Admin.Core.Tasks /// public async Task PassDown(IJobExecutionContext context) { - - RealTaskInfo taskInfo = await GetAwaitSendTask(storeCode); - if (taskInfo != null) + + try { - logHelper.Info($"下发泡后入库任务:{taskInfo.TaskCode};仓库{taskInfo.StoreCode};货道:{taskInfo.SpaceCode}"); - if (SendFoamTask_InStore(taskInfo)) + RealTaskInfo taskInfo = await GetAwaitSendTask(storeCode); + if (taskInfo != null) { - logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发成功,等待PLC执行反馈"); - semaphore.Wait(); //一直堵塞直到信号量释放 - logHelper.Info($"箱壳入库任务:{taskInfo.TaskCode};开始执行"); - taskInfo.TaskStatus = 2; - await _realTaskInfoService.UpdateAsync(taskInfo); - #region 更新在途数 - BaseSpaceInfo spaceInfo = await _baseSpaceInfoServices.GetSpaceInfoBySpaceCode(taskInfo.StoreCode, taskInfo.SpaceCode); - spaceInfo.OnRouteAmount += 1; - _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo); - #endregion - - RefreshInStoreTaskEvent?.Invoke(taskInfo);//刷新datagrid 列表 - - // logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};执行完成"); - // 刷新入库任务列表 + logHelper.Info($"下发泡后入库任务:{taskInfo.TaskCode};仓库{taskInfo.StoreCode};货道:{taskInfo.SpaceCode}"); + if (SendFoamTask_InStore(taskInfo)) + { + logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发成功,等待PLC执行反馈"); + semaphore.Wait(); //一直堵塞直到信号量释放 + logHelper.Info($"箱壳入库任务:{taskInfo.TaskCode};开始执行"); + taskInfo.TaskStatus = 2; + await _realTaskInfoService.UpdateAsync(taskInfo); + + #region 更新在途数 + BaseSpaceInfo spaceInfo = await _baseSpaceInfoServices.GetSpaceInfoBySpaceCode(taskInfo.StoreCode, taskInfo.SpaceCode); + spaceInfo.OnRouteAmount += 1; + _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo); + #endregion + + RefreshInStoreTaskEvent?.Invoke(taskInfo);//刷新datagrid 列表 + + // logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};执行完成"); + // 刷新入库任务列表 + } + else + { + logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发失败,请排除PLC连接"); + } + } else { - logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发失败,请排除PLC连接"); + logHelper.Info("未获取到需要下发的泡后入库任务"); } - } - else + catch (Exception ex) { - logHelper.Info("未获取到需要下发的泡后入库任务"); + logHelper.Info("下发任务异常"); } + + + } /// /// 获取待执行的入库任务