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 : BaseWareHouseService { protected static Dictionary s_elevatorMap = new(); private static readonly Lazy initializationTask; private static SqlSugarScope context; private readonly ISqlSugarClient _db; static DevServBase() { //initializationTask = new Lazy(InitializeAsync); _ = Task.Run(() => InitializeAsync()); } public DevServBase(ISqlSugarClient db) { _db = db; } private static async Task InitializeAsync() { ConnectionStringsOptions connectionOpts = App.GetConfig("ConnectionStrings", true); ConnectionConfig cfg = new() { ConfigId = connectionOpts.ConfigId, ConnectionString = connectionOpts.ConnectString, DbType = DbType.PostgreSQL, IsAutoCloseConnection = true, }; context = new(cfg); s_elevatorMap = await context.Queryable().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code); } //public static Task InitializationTask => initializationTask.Value; /// /// 获取电梯根据任务单号 /// /// /// taskCode:子任务编号 /// endlocation_id:目标库位ID /// /// protected async Task FindElevatorFromPars(ElevagorInfoQuery input) { var ele = await _db.CopyNew().Queryable().InnerJoin((a, b) => a.id == b.bill_id) .InnerJoin((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); } } }