From e46aa927d231af83724683c7286d9db503e24cf7 Mon Sep 17 00:00:00 2001 From: z8018 <1282578289@qq.com> Date: 星期二, 10 六月 2025 11:46:20 +0800 Subject: [PATCH] 1 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs | 112 ++++++++++++++++++++++++++++++-------------------------- 1 files changed, 60 insertions(+), 52 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" index 974e079..560b8f8 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineOutJob.cs" @@ -41,6 +41,16 @@ namespace WIDESEAWCS_Tasks { + /// <summary> + /// 杈撻�佺嚎鍑烘枡浣滀笟绫伙紝璐熻矗澶勭悊杈撻�佺嚎鍑烘枡绔欑殑PLC璇锋眰鍜學CS鍝嶅簲閫昏緫 + /// </summary> + /// <remarks> + /// 1. 閫氳繃鎵弿鏉$爜鑾峰彇璁㈠崟淇℃伅 <br/> + /// 2. 鏍规嵁璁㈠崟灏哄鍒ゆ柇鏄惁鍦ㄥ厑璁歌寖鍥村唴 <br/> + /// 3. 鐢熸垚浠诲姟骞惰缃甈LC绔欑偣鐨勭洰鏍囦綅缃拰浠诲姟缂栧彿 <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,34 +102,26 @@ { 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); - if (orderInfo.Width > AppSettings.Get("MaxWidth").ObjToInt() && orderInfo.Width < AppSettings.Get("MinWidth").ObjToInt()) + + Task.Run(() => { - 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 + _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 { - task = _taskService.GenerateTask(orderInfo); - if (task != null) + var (taskFlag, gTask, message) = _taskService.GenerateTask(orderInfo); + if (taskFlag && gTask != null) { + task = gTask; if (!string.IsNullOrEmpty(task.ItemInfo)) { string[] itemInfos = task.ItemInfo.Split("*"); @@ -138,22 +137,6 @@ otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, task.TaskNum); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); } - } - 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)); @@ -163,10 +146,49 @@ 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 + { + 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 @@ -174,7 +196,6 @@ otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, dischargeStation); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTaskNum, 997); otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true); - //otherDevice.SetValue(ConveyorLineStationDBName.WCSStationNoBarcode, true); } } @@ -200,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(); } } } -- Gitblit v1.9.3