电梯代码优化
This commit is contained in:
98
WarehouseMgr/Tnb.WarehouseMgr/DevServBase`1.cs
Normal file
98
WarehouseMgr/Tnb.WarehouseMgr/DevServBase`1.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Text;
|
||||
using JNPF;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Queries;
|
||||
using Tnb.WarehouseMgr.Entities.Entity;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class DevServBase<TService> : BaseWareHouseService
|
||||
{
|
||||
protected static Dictionary<string, object> s_elevatorMap = new();
|
||||
|
||||
private static readonly Lazy<Task> initializationTask;
|
||||
private static SqlSugarScope context;
|
||||
private readonly ISqlSugarClient _db;
|
||||
|
||||
static DevServBase()
|
||||
{
|
||||
//initializationTask = new Lazy<Task>(InitializeAsync);
|
||||
_ = Task.Run(() => InitializeAsync());
|
||||
}
|
||||
|
||||
public DevServBase(ISqlSugarClient db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
|
||||
private static async Task InitializeAsync()
|
||||
{
|
||||
|
||||
ConnectionStringsOptions connectionOpts = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
ConnectionConfig cfg = new()
|
||||
{
|
||||
ConfigId = connectionOpts.ConfigId,
|
||||
ConnectionString = connectionOpts.ConnectString,
|
||||
DbType = DbType.PostgreSQL,
|
||||
IsAutoCloseConnection = true,
|
||||
};
|
||||
context = new(cfg);
|
||||
|
||||
s_elevatorMap = await context.Queryable<WmsElevatorH>().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code);
|
||||
|
||||
}
|
||||
//public static Task InitializationTask => initializationTask.Value;
|
||||
|
||||
/// <summary>
|
||||
/// 获取电梯根据任务单号
|
||||
/// </summary>
|
||||
/// <param name="input">
|
||||
/// taskCode:子任务编号
|
||||
/// endlocation_id:目标库位ID
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
protected async Task<WmsElevatorH> FindElevatorFromPars(ElevagorInfoQuery input)
|
||||
{
|
||||
var ele = await _db.CopyNew().Queryable<WmsElevatorH>().InnerJoin<WmsElevatorD>((a, b) => a.id == b.bill_id)
|
||||
.InnerJoin<WmsDistaskH>((a, b, c) => b.location_code == c.endlocation_code)
|
||||
.WhereIF(!SqlFunc.IsNullOrEmpty(input.taskCode), (a, b, c) => c.bill_code == input.taskCode)
|
||||
.WhereIF(!SqlFunc.IsNullOrEmpty(input.endlocation_id), (a, b, c) => b.location_id == input.endlocation_id)
|
||||
.Select((a, b, c) => new WmsElevatorH
|
||||
{
|
||||
bill_code = c.bill_code,
|
||||
device_id = a.elevator_id,
|
||||
end_floor = c.end_floor
|
||||
}, true)
|
||||
.FirstAsync();
|
||||
|
||||
return ele;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomLoggerExtenstions
|
||||
{
|
||||
public static void Debug(this ILogger logger, string message, params object[] parameters)
|
||||
{
|
||||
logger.Debug(message, parameters);
|
||||
}
|
||||
|
||||
public static void Information(this ILogger logger, string message, params object[] parameters)
|
||||
{
|
||||
logger.LogInformation(message, parameters);
|
||||
}
|
||||
|
||||
public static void Error(this ILogger logger, string message, Exception ex, params object[] parameters)
|
||||
{
|
||||
logger.LogError(ex, message, parameters);
|
||||
}
|
||||
|
||||
public static void Error(this ILogger logger, string message, params object[] parameters)
|
||||
{
|
||||
logger.LogError(message, parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user