130 lines
4.8 KiB
C#
130 lines
4.8 KiB
C#
using System.Text;
|
|
using JNPF;
|
|
using JNPF.Common.Extension;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
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;
|
|
public static Dictionary<string, int> s_eleUseStatusDic = new();
|
|
public static Dictionary<string, int> s_loadedStatusDic = new();
|
|
|
|
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);
|
|
|
|
|
|
if (s_eleUseStatusDic.Count < 1)
|
|
{
|
|
foreach (var (k, _) in s_elevatorMap)
|
|
{
|
|
s_eleUseStatusDic[k] = 0;
|
|
s_loadedStatusDic[k] = 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
//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 whereExpable = Expressionable.Create<WmsElevatorH, WmsElevatorD, WmsDistaskH>()
|
|
.And((a, b, c) => a.enabled == 1);
|
|
if (!input.taskCode.IsNullOrEmpty())
|
|
{
|
|
whereExpable.AndIF(!SqlFunc.IsNullOrEmpty(input.taskCode), (a, b, c) => c.bill_code == input.taskCode);
|
|
}
|
|
if (!input.endlocation_id.IsNullOrEmpty())
|
|
{
|
|
whereExpable.AndIF(!SqlFunc.IsNullOrEmpty(input.endlocation_id), (a, b, c) => b.location_id == input.endlocation_id);
|
|
}
|
|
if (!input.startlocation_id.IsNullOrEmpty())
|
|
{
|
|
whereExpable.AndIF(!SqlFunc.IsNullOrEmpty(input.startlocation_id), (a, b, c) => b.location_id == input.startlocation_id);
|
|
}
|
|
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 || b.location_code == c.startlocation_code)
|
|
.Where(whereExpable.ToExpression())
|
|
.WhereIF(!SqlFunc.IsNullOrEmpty(input.sourceName) && SqlFunc.StartsWith("DT-R", input.sourceName), (a, b, c) => c.startpoint_code == input.sourceName)
|
|
.WhereIF(!SqlFunc.IsNullOrEmpty(input.sourceName) && SqlFunc.StartsWith("DT-C", input.sourceName), (a, b, c) => c.endpoint_code == input.sourceName)
|
|
.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);
|
|
}
|
|
}
|
|
}
|