Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
2024-07-25 15:03:57 +08:00
4 changed files with 92 additions and 56 deletions

View File

@@ -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>() != EnumDoorStatus. && runStatus.ToEnum<EnumRunStatus>() == 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;
}

View File

@@ -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<string> s_heartbeatDevNames = new();
//private static Dictionary<string, Func<CancellationToken?, Task>> _timedFuncMap = new(StringComparer.OrdinalIgnoreCase);
public static Dictionary<string, bool> elevatorStatus = new Dictionary<string, bool>();
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<IEventPublisher>();
@@ -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);
});

View File

@@ -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<JObject>(data);
bool result = res != null && res["Value"] != null ? res.Value<bool>("Value") : false;
bool result = res != null && res["Value"] != null && res["StatusCode"].ToString() == "0" ? res.Value<bool>("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<JObject>(data);
bool result = res != null && res["Value"] != null ? res.Value<bool>("Value") : false;
bool result = res != null && res["Value"] != null && res["StatusCode"].ToString() == "0" ? res.Value<bool>("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<JObject>(data);
bool result = res != null && res["Value"] != null ? res.Value<bool>("Value") : false;
bool result = res != null && res["Value"] != null && res["StatusCode"].ToString() == "0" ? res.Value<bool>("Value") : false;
Logger.Information($"【Check】 判断CTU是否可以放货(信号是否允许) 获取{code}的标签{strs[1]}信号值 结果为:{result}");
if (!result)
{