using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Quartz; using WIDESEAWCS_Common; using WIDESEAWCS_IBasicInfoService; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_Tasks.ConveyorLineJob; namespace WIDESEAWCS_Tasks { /// /// 站点释放任务,用于自动释放指定设备的容器并更新灯光状态。 /// /// /// 1. 从任务上下文中获取设备参数
/// 2. 筛选出需要处理的设备子编码
/// 3. 检查每个设备的站台释放信号
/// 4. 若信号为真,则自动释放容器并更新对应设备的灯光状态为"已完成"
/// 5. 处理过程中捕获并记录异常 ///
[DisallowConcurrentExecution] public class StationReleaseJob : JobBase, IJob { private readonly IContainerService _containerService; public StationReleaseJob(IContainerService containerService) { _containerService = containerService; } public Task Execute(IJobExecutionContext context) { bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); if (flag && value != null && value is OtherDevice otherDevice) { try { List deviceChildCodes = otherDevice.DeviceProDTOs.Where(x => x.DeviceProParamType == nameof(ConveyorLineStationDBName.StationRelease)).GroupBy(x => x.DeviceChildCode).Select(x => x.Key).ToList(); foreach (string deviceChildCode in deviceChildCodes) { bool signal = otherDevice.GetValue(ConveyorLineStationDBName.StationRelease, deviceChildCode); if (signal) { WriteDebug($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", $"按钮释放工位【{deviceChildCode}】"); _containerService.AutoReleaseContainer(deviceChildCode); if (LightStatusStorage.LightStatusDic.ContainsKey(deviceChildCode)) { LightStatusStorage.LightStatusDic[deviceChildCode] = LightStatusEnum.LightCompleted; Thread.Sleep(5 * 1000); LightStatusStorage.LightStatusDic[deviceChildCode] = LightStatusEnum.None; } } } } catch (Exception ex) { WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex); } } else { WriteError(nameof(StationReleaseJob), "参数错误,未传递设备参数或设备类型错误"); } return Task.CompletedTask; } } }