1
z8018
2025-06-10 e46aa927d231af83724683c7286d9db503e24cf7
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs
@@ -41,6 +41,16 @@
namespace WIDESEAWCS_Tasks
{
    /// <summary>
    /// è¾“送线出料作业类,负责处理输送线出料站的PLC请求和WCS响应逻辑
    /// </summary>
    /// <remarks>
    /// 1. é€šè¿‡æ‰«ææ¡ç èŽ·å–è®¢å•ä¿¡æ¯ <br/>
    /// 2. æ ¹æ®è®¢å•尺寸判断是否在允许范围内 <br/>
    /// 3. ç”Ÿæˆä»»åŠ¡å¹¶è®¾ç½®PLC站点的目标位置和任务编号 <br/>
    /// 4. å¤„理异常情况并记录错误日志 <br/>
    /// 5. ä½¿ç”¨[DisallowConcurrentExecution]特性确保作业不会并发执行
    /// </remarks>
    [DisallowConcurrentExecution]
    public class CommonConveyorLineOutJob : JobBase, IJob
    {
@@ -64,8 +74,6 @@
            _containerRepository = containerRepository;
        }
        public Task Execute(IJobExecutionContext context)
        {
            if (DischargeContainer == null)
@@ -78,9 +86,8 @@
            }
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null && value is OtherDevice)
            if (flag && value != null && value is OtherDevice otherDevice)
            {
                OtherDevice otherDevice = (OtherDevice)value;
                try
                {
                    bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest);   //申请
@@ -95,17 +102,14 @@
                        {
                            string barcode = otherDevice.GetValue<ConveyorLineStationDBName, string>(ConveyorLineStationDBName.PLCStationBarcode);
                            //List<byte> bytes = otherDevice.Communicator.Read(devicePro.DeviceProAddress, devicePro.DeviceProDataLength).ToList();
                            //byte[] temp = bytes.ToArray().SelectMiddle(2, bytes.IndexOf(0) - 2);
                            //barcode = Encoding.Default.GetString(temp);
                            if (!string.IsNullOrEmpty(barcode))
                            {
                                OrderInfo orderInfo = _orderDetailsService.GetOrderInfoByBarcode(barcode);
                                _orderDetailsService.ToMes(barcode, 3);
                                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())
                                {
@@ -135,49 +139,6 @@
                                            }
                                            else
                                            {
                                                //if (message.Contains("10001"))
                                                //{
                                                //    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 if (message.Contains("10002"))
                                                //{
                                                //    WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", message);
                                                //}
                                                //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);
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            if (ex.Message.Contains("10001"))
                                            {
                                                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 if (ex.Message.Contains("10002"))
                                            {
                                                WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex);
                                            }
                                            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));
@@ -185,8 +146,20 @@
                                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 998);
                                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true);
                                                WriteError(nameof(CommonConveyorLineOutJob), ex.Message, ex);
                                                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
@@ -209,6 +182,7 @@
                                }
                                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));
@@ -222,7 +196,6 @@
                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation);
                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 997);
                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true);
                                //otherDevice.SetValue(ConveyorLineStationDBName.WCSStationNoBarcode, true);
                            }
                        }
@@ -248,19 +221,6 @@
                WriteError(nameof(CommonConveyorLineOutJob), "参数错误,未传递设备参数或设备类型错误");
            }
            return Task.CompletedTask;
        }
        public int[] GetIndexArray<T>(T[] values, T value)
        {
            List<int> result = new List<int>();
            for (int i = 0; i < values.Length; i++)
            {
                if (value.Equals(values[i]))
                {
                    result.Add(i);
                }
            }
            return result.ToArray();
        }
    }
}