#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using AutoMapper; using HslCommunication; using Quartz; using System; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using WIDESEA_Common.Log; using WIDESEAWCS_BasicInfoService; using WIDESEAWCS_Common; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_DTO.BasicInfo; using WIDESEAWCS_IBasicInfoRepository; using WIDESEAWCS_IBasicInfoService; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_Model.Models.System; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_Tasks.ConveyorLineJob; namespace WIDESEAWCS_Tasks { /// /// 输送线出料作业类,负责处理输送线出料站的PLC请求和WCS响应逻辑 /// /// /// 1. 通过扫描条码获取订单信息
/// 2. 根据订单尺寸判断是否在允许范围内
/// 3. 生成任务并设置PLC站点的目标位置和任务编号
/// 4. 处理异常情况并记录错误日志
/// 5. 使用[DisallowConcurrentExecution]特性确保作业不会并发执行 ///
[DisallowConcurrentExecution] public class CommonConveyorLineOutJob : JobBase, IJob { private readonly ITaskService _taskService; private readonly IMapper _mapper; private readonly IOrderDetailsService _orderDetailsService; private readonly ITaskRepository _taskRepository; private readonly IContainerRepository _containerRepository; private static Dt_Container DischargeContainer; private static int dischargeStation = 8; public CommonConveyorLineOutJob(ITaskService taskService, IMapper mapper, IOrderDetailsService orderDetailsService, ITaskRepository taskRepository, IContainerRepository containerRepository) { _taskService = taskService; _mapper = mapper; _orderDetailsService = orderDetailsService; _taskRepository = taskRepository; _containerRepository = containerRepository; } public Task Execute(IJobExecutionContext context) { if (DischargeContainer == null) { DischargeContainer = _containerRepository.QueryFirst(x => x.ContainerEnable && x.ContainerType == ContainerTypeEnum.DischargeContainer.ObjToInt()); if (DischargeContainer != null) { dischargeStation = DischargeContainer.ContainerNo; } } bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); if (flag && value != null && value is OtherDevice otherDevice) { try { bool request = otherDevice.GetValue(ConveyorLineStationDBName.PLCStationRequest); //申请 bool response = otherDevice.GetValue(ConveyorLineStationDBName.PLCStationResponse); //应答 bool wcsResponse = otherDevice.GetValue(ConveyorLineStationDBName.WCSStationResponse); //应答 if (request && !response && !wcsResponse) { DeviceProDTO? devicePro = otherDevice.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == ConveyorLineStationDBName.PLCStationBarcode.ToString()); if (devicePro != null) { string barcode = otherDevice.GetValue(ConveyorLineStationDBName.PLCStationBarcode); if (!string.IsNullOrEmpty(barcode)) { OrderInfo orderInfo = _orderDetailsService.GetOrderInfoByBarcode(barcode); Task.Run(() => { _orderDetailsService.ToMes(barcode, 3); }); if (orderInfo.Width >= AppSettings.Get("MinWidth").ObjToInt() && orderInfo.Width <= AppSettings.Get("MaxWidth").ObjToInt() && orderInfo.Length >= AppSettings.Get("MinLength").ObjToInt() && orderInfo.Length <= AppSettings.Get("MaxLength").ObjToInt() || orderInfo.Length >= AppSettings.Get("MinWidth").ObjToInt() && orderInfo.Length <= AppSettings.Get("MaxWidth").ObjToInt() && orderInfo.Width >= AppSettings.Get("MinLength").ObjToInt() && orderInfo.Width <= AppSettings.Get("MaxLength").ObjToInt()) { Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == barcode); if (task == null) { try { var (taskFlag, gTask, message) = _taskService.GenerateTask(orderInfo); if (taskFlag && gTask != null) { task = gTask; if (!string.IsNullOrEmpty(task.ItemInfo)) { string[] itemInfos = task.ItemInfo.Split("*"); if (itemInfos.Length == 3) { otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[0])); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[1])); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[2])); } } otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(task.TargetAddress)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, task.TaskNum); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); } else { otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 998); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); WriteError(nameof(CommonConveyorLineOutJob), message); WriteError("板子排出错误原因记录日志", message); } } catch (Exception ex) { otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 999); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); WriteError("放板逻辑运算错误记录日志", ex.Message, ex); } } else { if (!string.IsNullOrEmpty(task.ItemInfo)) { string[] itemInfos = task.ItemInfo.Split("*"); if (itemInfos.Length == 3) { otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[0])); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[1])); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(itemInfos[2])); } } otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(task.TargetAddress)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, task.TaskNum); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); } } else { //todo 超宽处理 otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Length)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Width)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, Convert.ToInt32(orderInfo.Thickness)); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 999); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); } } else { otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 997); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); } } } else { if (wcsResponse && !request) otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false); //清除响应 } } catch (Exception ex) { otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 996); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex); } } else { WriteError(nameof(CommonConveyorLineOutJob), "参数错误,未传递设备参数或设备类型错误"); } return Task.CompletedTask; } } }