电梯代码优化
This commit is contained in:
@@ -13,6 +13,7 @@ using JNPF.Systems.Interfaces.System;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.OpenXmlFormats.Dml;
|
||||
using SqlSugar;
|
||||
@@ -24,6 +25,7 @@ using Tnb.WarehouseMgr.Entities.Configs;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Queries;
|
||||
using Tnb.WarehouseMgr.Entities.Entity;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
@@ -33,7 +35,7 @@ namespace Tnb.WarehouseMgr
|
||||
/// <summary>
|
||||
/// 库房业务类(出入库)
|
||||
/// </summary>
|
||||
public class WareHouseService : ServiceLoggerBase<WareHouseService>, IWareHouseService
|
||||
public class WareHouseService : DevServBase<WareHouseService>, IWareHouseService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IDictionaryDataService _dictionaryDataService;
|
||||
@@ -44,11 +46,14 @@ namespace Tnb.WarehouseMgr
|
||||
private static readonly Dictionary<string, int> _elevatorAgvCtlStatusMap = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
|
||||
private static Dictionary<string, object> locMap = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly IConfiguration _configuration;
|
||||
public Func<string, int, Task> AddUnExecuteTask { get; set; }
|
||||
|
||||
|
||||
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService,
|
||||
IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService)
|
||||
//: base(repository.AsSugarClient())
|
||||
IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService
|
||||
//IConfiguration configuration
|
||||
) : base(repository.AsSugarClient())
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_dictionaryDataService = dictionaryDataService;
|
||||
@@ -56,7 +61,7 @@ namespace Tnb.WarehouseMgr
|
||||
_userManager = userManager;
|
||||
_cacheManager = cacheManager;
|
||||
_elevatorControlService = elevatorControlService;
|
||||
_ = InitializationTask;
|
||||
//_configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,7 +245,7 @@ namespace Tnb.WarehouseMgr
|
||||
try
|
||||
{
|
||||
//获取电梯数据
|
||||
List<WmsElevatorH> elevatorList = await db.Queryable<WmsElevatorH>().InnerJoin<WmsElevatorD>((a, b) => a.id == b.bill_id)
|
||||
/*List<WmsElevatorH> elevatorList = await db.Queryable<WmsElevatorH>().InnerJoin<WmsElevatorD>((a, b) => a.id == b.bill_id)
|
||||
.Where((a, b) => a.enabled == 1)
|
||||
.Select((a, b) => new WmsElevatorH
|
||||
{
|
||||
@@ -252,14 +257,14 @@ namespace Tnb.WarehouseMgr
|
||||
point_code = b.point_code,
|
||||
floor = b.floor
|
||||
|
||||
}, true).ToListAsync();
|
||||
}, true).ToListAsync();*/
|
||||
|
||||
|
||||
//获取所有未下发的预任务申请
|
||||
List<WmsPretaskH> preTasks = await db.Queryable<WmsPretaskH>().InnerJoin<WmsCarryH>((a, b) => a.startlocation_id == b.location_id && a.carry_id == b.id)
|
||||
.InnerJoin<WmsAreaH>((a, b, c) => a.area_id == c.id)
|
||||
.InnerJoin<BasLocation>((a, b, c, d) => a.endlocation_id == d.id && d.is_use == "0")
|
||||
.Where(a => a.status != WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID && !string.IsNullOrWhiteSpace(a.startlocation_id))
|
||||
.Where(a => a.status == WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID && !string.IsNullOrWhiteSpace(a.startlocation_id))
|
||||
.OrderBy(a => new { priority = SqlFunc.Desc(a.priority), a.bill_code })
|
||||
.Select((a, b, c, d) => new WmsPretaskH
|
||||
{
|
||||
@@ -268,7 +273,7 @@ namespace Tnb.WarehouseMgr
|
||||
}, true)
|
||||
.ToListAsync();
|
||||
|
||||
List<WmsPretaskH> executedPreTasks = await db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID && it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID).ToListAsync();
|
||||
//List<WmsPretaskH> executedPreTasks = await db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID && it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID).ToListAsync();
|
||||
|
||||
List<WmsPretaskH> agvElevatorTasks = preTasks
|
||||
.Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase) &&
|
||||
@@ -283,11 +288,6 @@ namespace Tnb.WarehouseMgr
|
||||
IEnumerable<WmsPretaskH?> firstEleGrp = agvElevatorTasks.GroupBy(g => g.endlocation_code).Select(t => t.OrderBy(o => o.bill_code).FirstOrDefault());
|
||||
agvElevatorTasks = firstEleGrp?.ToList() ?? Enumerable.Empty<WmsPretaskH>().ToList()!;
|
||||
|
||||
var diffEndLocPreTasks = executedPreTasks.Where(it => firstEleGrp.Select(x => x.endlocation_id).Contains(it.endlocation_id)).ToList();
|
||||
if(diffEndLocPreTasks?.Count> 0)
|
||||
{
|
||||
agvElevatorTasks = agvElevatorTasks.Where(it => !diffEndLocPreTasks.Select(x => x.endlocation_id).Contains(it.endlocation_id)).ToList();
|
||||
}
|
||||
|
||||
//如果电梯任务,预Agv任务存在相同目标库位,删除Agv任务保证电梯任务先行
|
||||
var equalEndLocPreTasks = elePreTasks.Select(x => x.endlocation_code).Intersect(agvElevatorTasks.Select(x => x.endlocation_code));
|
||||
@@ -388,27 +388,6 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
await db.Ado.BeginTranAsync();
|
||||
|
||||
List<string> endPointIds = disTasks.Where(t => t.area_code.StartsWith("ELE", StringComparison.OrdinalIgnoreCase)).Select(t => t.endpoint_id).ToList();
|
||||
Logger.Information($"endPointIds:{string.Join(",", endPointIds)}");
|
||||
if (endPointIds?.Count > 0)
|
||||
{
|
||||
elevatorList = elevatorList.FindAll(x => endPointIds.Contains(x.point_id));
|
||||
|
||||
|
||||
if (elevatorList?.Count > 0)
|
||||
{
|
||||
foreach (WmsElevatorH? e in elevatorList)
|
||||
{
|
||||
WmsDistaskH? disTask = disTasks.Find(x => x.endpoint_id == e.point_id);
|
||||
if (disTask != null)
|
||||
{
|
||||
disTask.device_id = e.elevator_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int row = await db.Insertable(disTasks).ExecuteCommandAsync();
|
||||
if (preTaskCodes?.Count > 0)
|
||||
{
|
||||
@@ -423,15 +402,27 @@ namespace Tnb.WarehouseMgr
|
||||
await db.Ado.CommitTranAsync();
|
||||
|
||||
Logger.Information("预任务执行完成");
|
||||
|
||||
Logger.Information($"_eleCtlCfg.Environment={_eleCtlCfg.Environment}");
|
||||
if (string.Equals(_eleCtlCfg.Environment, ElevatorConsts.EnvironmentName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
//呼梯操作
|
||||
//获取目标库位为电梯库位的任务
|
||||
Logger.Information("操作设备");
|
||||
|
||||
var agvDTTasks = disTasks.Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase) &&
|
||||
!it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
foreach (var at in agvDTTasks)
|
||||
|
||||
foreach (var task in agvDTTasks)
|
||||
{
|
||||
ElevagorInfoQuery q = new() { endlocation_id = task.endlocation_id };
|
||||
var e = await FindElevatorFromPars(q);
|
||||
if (e != null)
|
||||
{
|
||||
task.device_id = e.device_id;
|
||||
}
|
||||
}
|
||||
|
||||
/*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}");
|
||||
@@ -439,10 +430,12 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
at.device_id = ele.elevator_id;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
List<(string endlocation_code, string device_id, string id, int start_floor)> endLocCodes = agvDTTasks
|
||||
.Select(it => (it.endlocation_code, it.device_id, it.id, it.start_floor)).ToList();
|
||||
var callLiftCnt = endLocCodes?.Count ?? 0;
|
||||
Logger.Information($"呼梯任务数:{callLiftCnt}");
|
||||
if (endLocCodes?.Count > 0)
|
||||
{
|
||||
if (endLocCodes.Select(x => x.device_id).All(x => !x.IsNullOrWhiteSpace()))
|
||||
@@ -468,18 +461,14 @@ namespace Tnb.WarehouseMgr
|
||||
_ = ExecuteTargetFloorTask(elevatorTask);
|
||||
}
|
||||
}
|
||||
List<WmsDistaskH> agvTasks = disTasks.Where(it => !it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
if (agvTasks?.Count > 0)
|
||||
{
|
||||
Logger.Information($"Agv任务数量:{agvTasks.Count},taskCodes:{string.Join(",", agvTasks.Select(x => x.bill_code).Distinct())}");
|
||||
_ = AgvDispatch(agvTasks, agvCts.Token);
|
||||
}
|
||||
}
|
||||
//调用AGV创建任务链接口
|
||||
List<WmsDistaskH> agvTasks = disTasks.Where(it => !it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
|
||||
if (agvTasks?.Count > 0)
|
||||
{
|
||||
Logger.Information($"Agv任务数量:{agvTasks.Count},taskCodes:{string.Join(",", agvTasks.Select(x => x.bill_code).Distinct())}");
|
||||
_ = AgvDispatch(agvTasks, agvCts.Token);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is HttpRequestException hReqEx)
|
||||
|
||||
Reference in New Issue
Block a user