From 201293b82fcbdc9183306aeaca1e49ab19f4526c Mon Sep 17 00:00:00 2001 From: majian <780924089@qq.com> Date: Thu, 25 Jul 2024 14:59:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=83=E8=B7=B3=E3=80=81=E8=AF=BB=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 87 ++++++++++--------- .../Tnb.WarehouseMgr/DeviceProviderService.cs | 25 ++++-- .../TimedTaskBackgroundService.cs | 30 +++++-- .../Tnb.WarehouseMgr/WareHouseService.cs | 6 +- 4 files changed, 92 insertions(+), 56 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index f299b535..b68c8076 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -1895,11 +1895,16 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA try { string jsonString = await _redisData.GetHash(DevName, field); + Log.Information($"查询X2Server数据 {DevName} {field}:" + jsonString); if (string.IsNullOrEmpty(jsonString)) return false; JObject jsonObject = JObject.Parse(jsonString); - + if (jsonObject.TryGetValue("StatusCode", out JToken valueToken1)) + { + if (valueToken1.ToString() == "-1") + return false; + } if (jsonObject.TryGetValue("Value", out JToken valueToken2)) { return bool.Parse(valueToken2.ToString()); @@ -1920,59 +1925,59 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA public async Task GetStringTag(string DevName, string field) { #region - //try - //{ - // string jsonString = await _redisData.GetHash(DevName, field); - - // JObject jsonObject = JObject.Parse(jsonString); - // if (jsonObject.TryGetValue("StatusCode", out JToken valueToken1)) - // { - // if (valueToken1.ToString() == "-1") - // return ""; - // } - // if (jsonObject.TryGetValue("Value", out JToken valueToken2)) - // { - // return valueToken2.ToString(); - // } - // else - // { - // Console.WriteLine($"未找到匹配项 {DevName} {field}"); - // } - //} - //catch (Exception ex) - //{ - // // 捕获并处理异常 - // Console.WriteLine($"发生异常: {ex.Message}"); - //} - - //return $"未找到匹配项 {DevName} {field}"; - #endregion - try { string jsonString = await _redisData.GetHash(DevName, field); - if (string.IsNullOrEmpty(jsonString)) - return ""; - - string pattern = "\"Value\":\"(.*?)\""; - - System.Text.RegularExpressions.Match match = Regex.Match(jsonString, pattern); - if (match.Success) + Log.Information($"查询X2Server数据 {DevName} {field}:" + jsonString); + JObject jsonObject = JObject.Parse(jsonString); + if (jsonObject.TryGetValue("StatusCode", out JToken valueToken1)) { - - return match.Groups[1].Value; + if (valueToken1.ToString() == "-1") + return ""; + } + if (jsonObject.TryGetValue("Value", out JToken valueToken2)) + { + return valueToken2.ToString(); } else { - Console.WriteLine($"未找到匹配项{DevName} {field}"); + Console.WriteLine($"未找到匹配项 {DevName} {field}"); } } catch (Exception ex) { - Console.WriteLine($"未找到匹配项{DevName} {field}"); + // 捕获并处理异常 + Console.WriteLine($"发生异常: {ex.Message}"); } return $"未找到匹配项 {DevName} {field}"; + #endregion + + //try + //{ + // string jsonString = await _redisData.GetHash(DevName, field); + // if (string.IsNullOrEmpty(jsonString)) + // return ""; + + // string pattern = "\"Value\":\"(.*?)\""; + + // System.Text.RegularExpressions.Match match = Regex.Match(jsonString, pattern); + // if (match.Success) + // { + + // return match.Groups[1].Value; + // } + // else + // { + // Console.WriteLine($"未找到匹配项{DevName} {field}"); + // } + //} + //catch (Exception ex) + //{ + // Console.WriteLine($"未找到匹配项{DevName} {field}"); + //} + + //return $"未找到匹配项 {DevName} {field}"; } private async Task Floor2UpDownMachinecode_SetTag(string tag, string value) @@ -2524,7 +2529,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA Floor4DMC2CPKtimer = new Timer(Floor4DMC2CPK, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); F2KTPsupplementtimer = new Timer(F2KTPsupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - YCLInternalTransfertimer = new Timer(YCLInternalTransfer, null, TimeSpan.Zero, TimeSpan.FromSeconds(180)); + //YCLInternalTransfertimer = new Timer(YCLInternalTransfer, null, TimeSpan.Zero, TimeSpan.FromSeconds(180)); return Task.CompletedTask; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs b/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs index 0cda661e..a5b4e024 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs @@ -123,8 +123,8 @@ namespace Tnb.WarehouseMgr } catch (Exception ex) { - Logger.LogError(ex.Message); - Logger.LogError(ex.StackTrace); + Logger.LogError("【LoadConfirm】" + ex.Message); + Logger.LogError("【LoadConfirm】" + ex.StackTrace); return await ToApiResult(HttpStatusCode.InternalServerError, $"取货确认..................失败 原因是{ex.Message}"); throw; } @@ -159,6 +159,11 @@ namespace Tnb.WarehouseMgr { if (elevator != null && s_elevatorMap.TryGetValue(elevator.device_id, out object? elevatorCode)) { + if (!TimedTaskBackgroundService.elevatorStatus[elevatorCode.ToString()]) + { + Logger.LogError($"【LoadConfirm】 {elevatorCode} 电梯心跳中断,请重试!"); + return await ToApiResult(HttpStatusCode.InternalServerError, $"{elevatorCode} 电梯心跳中断,请重试!"); + } //s_eleUseStatusDic[elevator.device_id] = (int)EnumElevatorUseStatus.空闲; string devName = elevatorCode?.ToString(); Logger.Information($"【LoadConfirm】 获取设备:{devName},状态"); @@ -180,7 +185,7 @@ namespace Tnb.WarehouseMgr if (curFloor != floorNo) { Logger.Information($"【LoadConfirm】 电梯还未开门,请重试!curFloor != floorNo"); - return await ToApiResult(HttpStatusCode.InternalServerError, "【LoadConfirm】 电梯还未开门,请重试!"); + return await ToApiResult(HttpStatusCode.InternalServerError, "电梯还未开门,请重试!"); } if (doorStatus.ToEnum() != EnumDoorStatus.开门到位保持 && runStatus.ToEnum() == EnumRunStatus.停梯 && floorNo == curFloor) //判断电梯楼层与当前放货在同一楼层在允许放货 { @@ -202,9 +207,11 @@ namespace Tnb.WarehouseMgr } } } - catch (Exception) + catch (Exception ex) { - return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!"); + Logger.LogError("【LoadConfirm】" + ex.Message); + Logger.LogError("【LoadConfirm】" + ex.StackTrace); + return await ToApiResult(HttpStatusCode.InternalServerError, $"取货确认..................失败 原因是{ex.Message}"); throw; } return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!"); @@ -339,6 +346,11 @@ namespace Tnb.WarehouseMgr } if (s_elevatorMap.TryGetValue(elevator.device_id, out object? elevatorCode)) { + if (!TimedTaskBackgroundService.elevatorStatus[elevatorCode.ToString()]) + { + Logger.LogError($"【UnloadConfirm】 {elevatorCode} 电梯心跳中断,请重试!"); + return await ToApiResult(HttpStatusCode.InternalServerError, $"{elevatorCode} 电梯心跳中断,请重试!"); + } string devName = elevatorCode?.ToString(); @@ -397,7 +409,8 @@ namespace Tnb.WarehouseMgr } catch (Exception ex) { - Logger.Error("【UnloadConfirm】 放货确认失败", ex); + Logger.Error("【UnloadConfirm】 放货确认失败", ex.Message); + Logger.Error("【UnloadConfirm】 放货确认失败", ex.StackTrace); return await ToApiResult(HttpStatusCode.InternalServerError, "电梯还未开门,请重试!"); throw; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index 131012f9..289fa198 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -9,7 +9,9 @@ using JNPF.Logging; using JNPF.Systems.Entitys.System; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; using NPOI.OpenXmlFormats.Dml.Diagram; +using NPOI.SS.Format; using Tnb.Common.Extension; using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities.Configs; @@ -32,14 +34,19 @@ namespace Tnb.WarehouseMgr private readonly IHostApplicationLifetime _lifeTime; private List s_heartbeatDevNames = new(); //private static Dictionary> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase); + + public static Dictionary elevatorStatus = new Dictionary(); public TimedTaskBackgroundService() { + s_heartbeatDevNames = _elevatorControlConfiguration.HeartbeatDevNames; + if (elevatorStatus.Count == 0) + foreach (var devName in s_heartbeatDevNames) + elevatorStatus.Add(devName, false); } protected override Task ExecuteAsync(CancellationToken stoppingToken) { IsStarted = true; - s_heartbeatDevNames = _elevatorControlConfiguration.HeartbeatDevNames; Task timedTask = Task.Run(() => { _eventPublisher = App.GetRequiredService(); @@ -56,12 +63,23 @@ namespace Tnb.WarehouseMgr ["token"] = _elevatorControlConfiguration.token }; Log.Information($"{devName.Match(@"\d+")}#梯, 心跳检测"); - string result = await HttpClientHelper.GetAsync(_elevatorControlConfiguration.WriteTagUrl, pars: parameter); - Log.Information($"{devName.Match(@"\d+")}#梯, 心跳检测结果:{result}"); - - //var result = await RedisHelper.HSetAsync(devName, ElevatorConsts.AGVKeepalive, "123"); - await Console.Out.WriteLineAsync($"{devName.Match(@"\d+")}#梯, 心跳检测结果:{result}"); + try + { + string result = await HttpClientHelper.GetAsync(_elevatorControlConfiguration.WriteTagUrl, pars: parameter); + Log.Information($"{devName.Match(@"\d+")}#梯, 心跳检测结果:{result}"); + JObject resObj = JObject.Parse(result); + elevatorStatus[devName] = resObj["Result"].ToString() == "Ok"; + //var result = await RedisHelper.HSetAsync(devName, ElevatorConsts.AGVKeepalive, "123"); + await Console.Out.WriteLineAsync($"{devName.Match(@"\d+")}#梯, 心跳检测结果:{result}"); + } + catch (Exception ex) + { + Log.Error($"{devName.Match(@"\d+")}#梯, 心跳检测结果:{ex.Message}"); + elevatorStatus[devName] = false; + } } + + }, stoppingToken, 30); }); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 6cd1e9f1..a945e867 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -800,7 +800,7 @@ namespace Tnb.WarehouseMgr string data = await _redisData.GetHash(strs[0], strs[1]); Logger.Information("wcs请求CheckPut接口查询X2Server数据:" + data); JObject? res = JsonConvert.DeserializeObject(data); - bool result = res != null && res["Value"] != null ? res.Value("Value") : false; + bool result = res != null && res["Value"] != null && res["StatusCode"].ToString() == "0" ? res.Value("Value") : false; if (!result) throw new AppFriendlyException("点位" + input.targetName + "不可放", 500); Logger.Information("wcs请求CheckPut接口结果:CTU可放货" + data); @@ -921,7 +921,7 @@ namespace Tnb.WarehouseMgr } string data = _redisData.GetHash(strs[0], strs[1]).Result; JObject? res = JsonConvert.DeserializeObject(data); - bool result = res != null && res["Value"] != null ? res.Value("Value") : false; + bool result = res != null && res["Value"] != null && res["StatusCode"].ToString() == "0" ? res.Value("Value") : false; Logger.Information($"【Check】{action} 判断KIVA是否可以取货(信号是否允许) 获取{code}的标签{strs[1]}信号值 结果为:{result} "); if (!result) { @@ -943,7 +943,7 @@ namespace Tnb.WarehouseMgr } string data = _redisData.GetHash(strs[0], strs[1]).Result; JObject? res = JsonConvert.DeserializeObject(data); - bool result = res != null && res["Value"] != null ? res.Value("Value") : false; + bool result = res != null && res["Value"] != null && res["StatusCode"].ToString() == "0" ? res.Value("Value") : false; Logger.Information($"【Check】 判断CTU是否可以放货(信号是否允许) 获取{code}的标签{strs[1]}信号值 结果为:{result}"); if (!result) {