1、调整电梯逻辑代码

2、新增内部测试类
This commit is contained in:
yang.lee
2023-12-01 22:16:39 +08:00
parent 7033db95e6
commit 33e4028853
4 changed files with 95 additions and 23 deletions

View File

@@ -250,7 +250,7 @@ namespace Tnb.WarehouseMgr
floor = b.floor
}, true).ToListAsync();
Logger.Information($"可用电梯信息:{elevatorList.Select(e => e.elevator_code)}");
Logger.Information($"可用电梯信息:{string.Join(",", elevatorList.Select(e => e.elevator_code).Distinct())}");
//获取所有未下发的预任务申请
@@ -265,6 +265,8 @@ namespace Tnb.WarehouseMgr
third_eqp_type = c.third_eqp_type,
}, true)
.ToListAsync();
Logger.Information("获取未下发的预任务列表完成的......");
List<WmsPretaskH> agvElevatorTasks = preTasks
.Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase) &&
!it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase))
@@ -392,7 +394,6 @@ namespace Tnb.WarehouseMgr
}
}
}
//disTasks.ForEach(x => x.id = SnowflakeIdHelper.NextId());
int row = await db.Insertable(disTasks).ExecuteCommandAsync();
@@ -408,6 +409,8 @@ namespace Tnb.WarehouseMgr
await db.Ado.CommitTranAsync();
Logger.Information("预任务执行完成");
if (string.Equals(_eleCtlCfg.Environment, ElevatorConsts.EnvironmentName, StringComparison.OrdinalIgnoreCase))
{
//呼梯操作
@@ -418,7 +421,7 @@ namespace Tnb.WarehouseMgr
foreach (var at in agvDTTasks)
{
var ele = elevatorList.Find(x => x.location_code == at.endlocation_code);
Logger.Information($"ele.elevator_id:{ele?.elevator_id},elevator_code:{ele.elevator_code}");
Logger.Information($"ele.elevator_id:{ele?.elevator_id},elevator_code:{ele?.elevator_code}");
if (ele != null)
{
at.device_id = ele.elevator_id;
@@ -429,6 +432,7 @@ namespace Tnb.WarehouseMgr
.Select(it => (it.endlocation_code, it.device_id, it.id, it.start_floor)).ToList();
if (endLocCodes?.Count > 0)
{
Logger.Information("呼梯操作");
await CallingLanding(endLocCodes);
}
//执行电梯任务
@@ -437,9 +441,6 @@ namespace Tnb.WarehouseMgr
if (elevatorTasks?.Count > 0)
{
Logger.Information($"当前电梯任务数:{elevatorTasks?.Count ?? 0}");
Logger.Information("准备执行电梯任务");
Logger.Information("执行电梯任务");
foreach (WmsDistaskH? elevatorTask in elevatorTasks)
{
await ExecuteTargetFloorTask(elevatorTask);
@@ -463,6 +464,7 @@ namespace Tnb.WarehouseMgr
catch (Exception ex)
{
Logger.Error("生成预任务执行时出现错误", ex);
Logger.Error(ex.StackTrace!);
await db.Ado.RollbackTranAsync();
throw;
}
@@ -479,6 +481,7 @@ namespace Tnb.WarehouseMgr
/// <returns></returns>
private async Task CallingLanding(List<(string endlocation_code, string device_id, string id, int floorNO)> endLocCodes)
{
Logger.Information("--------------------------------------------------------");
Logger.Information($" 开始呼梯操作.............");
Logger.Information($"电梯信息:{JsonConvert.SerializeObject(s_elevatorMap)}");
try
@@ -546,6 +549,8 @@ namespace Tnb.WarehouseMgr
//如果当前电梯有任务在做,将当前呼梯任务放入待执行队列
_ = await _db.Insertable(elevatorQueueItem).ExecuteCommandAsync();
Logger.Information("呼梯任务执行完成");
}
}
catch (Exception ex)
@@ -554,6 +559,7 @@ namespace Tnb.WarehouseMgr
Logger.Error($"呼梯操作错误堆栈跟踪:{Environment.NewLine}{ex.StackTrace}");
throw;
}
Logger.Information("--------------------------------------------------------");
}
/// <summary>
@@ -563,6 +569,7 @@ namespace Tnb.WarehouseMgr
/// <returns></returns>
private async Task ExecuteTargetFloorTask(WmsDistaskH disTask)
{
Logger.Information("--------------------------------------------------------");
//收到放货确认通知向电梯发送到3楼的指令
Logger.Information($"开始执行电梯任务任务ID:{disTask.id}");
try
@@ -631,6 +638,8 @@ namespace Tnb.WarehouseMgr
disTaskIds = disTaskIds,
};
await TaskComplate(tcUpInput);
Logger.Information("电梯任务执行完成");
}
}
@@ -639,6 +648,7 @@ namespace Tnb.WarehouseMgr
Logger.Error("执行到目标楼层电梯任务失败", ex);
throw;
}
Logger.Information("--------------------------------------------------------");
}
/// <summary>
/// Agv调度
@@ -780,7 +790,6 @@ namespace Tnb.WarehouseMgr
await _db.Updateable(eles).ReSetValue(it => it.task_nums--).ExecuteCommandAsync();
//更新载具,锁定状态为未锁定,更新载具的库位当前任务的目标库位
Logger.Information("更新载具及库位准备中.....");
List<(string carry_id, string carry_status, string endlocation_id, string endlocation_code)> multiList = disTasks.Select(it => (it.carry_id, it.carry_status, it.endlocation_id, it.endlocation_code)).ToList();
Dictionary<string, object> locWhIdMap = await _db.Queryable<BasLocation>().Where(it => multiList.Select(x => x.endlocation_id).Contains(it.id)).ToDictionaryAsync(it => it.id, it => it.wh_id);
@@ -819,7 +828,6 @@ namespace Tnb.WarehouseMgr
locIts.Add(loc);
}
Logger.Information("更新载具及库位开始.....");
_ = await _db.Updateable(carryIts).UpdateColumns(it => new { it.is_lock, it.location_id, it.location_code }).ExecuteCommandAsync();
//更新条码的库位和仓库信息
_ = await _db.Updateable(carryCodeIts).UpdateColumns(it => new { it.warehouse_id, it.location_id, it.location_code }).Where(it => multiList.Select(x => x.carry_id).Contains(it.carry_id)).ExecuteCommandAsync();
@@ -830,7 +838,6 @@ namespace Tnb.WarehouseMgr
*/ //更新业务主表的单据状态
foreach (WmsDistaskH? dt in disTasks)
{
Logger.Information("开始业务回更");
List<WmsDistaskCode> disTaskCodes = await _db.Queryable<WmsDistaskCode>().Where(it => it.bill_id == dt.id).ToListAsync();
WareHouseUpInput upInput = new() { bizTypeId = dt.biz_type, requireId = dt.require_id!, distaskCodes = disTaskCodes, carryIds = disTasks.Select(x => x.carry_id).ToList() };
@@ -845,12 +852,13 @@ namespace Tnb.WarehouseMgr
upInput.loginType = "web";//(!string.IsNullOrEmpty(_userManager?.LoginType) ? "app" : "web") ?? "web";
if (dt.is_sign == 1 && dt.chain_type == "3")
{
Logger.Information("执行业务回更操作.....");
await DoUpdate(upInput);
}
}
}
await _db.Ado.CommitTranAsync();
Logger.Information("任务操作完成");
}
catch (Exception ex)
{
@@ -993,7 +1001,6 @@ namespace Tnb.WarehouseMgr
{
if (points?.FindAll(x => x.location_code != null && x.location_code.Contains("dt", StringComparison.OrdinalIgnoreCase))?.Count > 0)
{
Logger.Information("包含电梯Agv任务");
//查询当前电梯点
List<WmsElevatorD> curEleDs = await _db.Queryable<WmsElevatorD>().InnerJoin<WmsElevatorH>((a, b) => a.bill_id == b.id).Where((a, b) => points.Select(x => x.id).Contains(a.point_id)).ToListAsync();
Logger.Information($"curEleDs==null :{curEleDs == null},curEleDs:{string.Join(",", curEleDs.Select(x => x.bill_id))}");
@@ -1002,7 +1009,6 @@ namespace Tnb.WarehouseMgr
{
//当前电梯
WmsElevatorH curEle = await _db.Queryable<WmsElevatorH>().SingleAsync(it => it.id == curEleDs.First().bill_id);
Logger.Information($"curEle==null :{curEle == null}");
//同电梯组电梯
List<WmsElevatorH> sGpEle = await _db.Queryable<WmsElevatorH>().Where(it => it.elevator_group == curEle.elevator_group && it.id != curEle.id && it.enabled == 1).ToListAsync();