This commit is contained in:
2024-04-11 17:31:32 +08:00
parent f6eaa2f481
commit 4fbc6c0267
200 changed files with 1252 additions and 1860 deletions

View File

@@ -1,119 +0,0 @@
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);
}
//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);
}
}
}

View File

@@ -1,5 +1,4 @@
using Aop.Api.Domain;
using JNPF;
using JNPF;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
@@ -35,7 +34,7 @@ namespace Tnb.WarehouseMgr
/// Wms设备接口提供程序服务类
/// </summary>
public class DeviceProviderService : DevServBase<DeviceProviderService>
public class DeviceProviderService : ServiceLoggerBase<DeviceProviderService>
{
private readonly ISqlSugarClient _db;
private readonly IWareHouseService _wareHouseService;
@@ -46,6 +45,7 @@ namespace Tnb.WarehouseMgr
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
private readonly ILoggerFactory _loggerFactory;
public static Dictionary<string, int> s_eleUseStatusDic = new();
public static Dictionary<string, int> s_loadedStatusDic = new();
@@ -54,7 +54,7 @@ namespace Tnb.WarehouseMgr
IEventPublisher eventPublisher,
IUserManager userManger,
IElevatorControlService elevatorControlService
) : base(repository.AsSugarClient())
) //: base(repository.AsSugarClient())
{
_db = repository.AsSugarClient();
_wareHouseService = wareHouseService;
@@ -187,6 +187,49 @@ namespace Tnb.WarehouseMgr
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
}
/// <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;
}
/// <summary>
/// 放货确认/申请放货
/// </summary>

View File

@@ -0,0 +1,84 @@
using System.Text;
using JNPF;
using Microsoft.Extensions.Logging;
using SqlSugar;
using Tnb.WarehouseMgr.Entities;
namespace Tnb.WarehouseMgr
{
public class ServiceLoggerBase<TService> : BaseWareHouseService
{
protected static Dictionary<string, object> s_elevatorMap = new();
private static readonly Lazy<Task> initializationTask;
static ServiceLoggerBase()
{
initializationTask = new Lazy<Task>(InitializeAsync);
}
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,
};
SqlSugarScope context = new(cfg);
s_elevatorMap = await context.Queryable<WmsElevatorH>().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code);
}
public static Task InitializationTask => initializationTask.Value;
//protected ILogger Logger => LoggerFactory.Create(builder => builder.AddFile($"{AppContext.BaseDirectory}/logs/{this.GetType().Name}{DateTime.Now:yyyyMMdd}.log", cfgOpts =>
//{
// //cfgOpts.DateFormat = "yyyy-MM-dd HH:mm:ss.fff";
// cfgOpts.MessageFormat = (logMsg) =>
// {
// Span<char> span = logMsg.LogLevel.ToString().ToCharArray();
// StringBuilder sb = new();
// _ = sb.Append($"{span[..4]} ");
// _ = sb.Append($"{logMsg.LogName} ");
// _ = sb.Append($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} ");
// _ = sb.Append($"#{logMsg.EventId.Id} ");
// _ = sb.Append(logMsg.Message + " ");
// _ = sb.Append(logMsg.Exception?.ToString());
// return sb.ToString();
// };
//})).CreateLogger(this.GetType());
}
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);
}
}
}

View File

@@ -18,6 +18,7 @@
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
<ProjectReference Include="..\..\message\Tnb.Message.Interfaces\Tnb.Message.Interfaces.csproj" />
<ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
<!--<ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />-->
<ProjectReference Include="..\..\QcMgr\Tnb.QcMgr.Interfaces\Tnb.QcMgr.Interfaces.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\Tnb.WarehouseMgr.Interfaces\Tnb.WarehouseMgr.Interfaces.csproj" />

View File

@@ -28,7 +28,6 @@ using Tnb.BasicData.Entities;
using Tnb.Common.Extension;
using Tnb.Common.Redis;
using Tnb.Common.Utils;
using Tnb.ProductionMgr.Entities;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Configs;
using Tnb.WarehouseMgr.Entities.Consts;
@@ -44,7 +43,7 @@ namespace Tnb.WarehouseMgr
/// <summary>
/// 库房业务类(出入库)
/// </summary>
public class WareHouseService : DevServBase<WareHouseService>, IWareHouseService
public class WareHouseService : ServiceLoggerBase<WareHouseService>, IWareHouseService
{
private readonly ISqlSugarClient _db;
private readonly IDictionaryDataService _dictionaryDataService;
@@ -64,7 +63,7 @@ namespace Tnb.WarehouseMgr
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, RedisData redisData,
IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService
//IConfiguration configuration
) : base(repository.AsSugarClient())
)// : base(repository.AsSugarClient())
{
_db = repository.AsSugarClient();
_dictionaryDataService = dictionaryDataService;
@@ -663,6 +662,49 @@ namespace Tnb.WarehouseMgr
agvCts.Dispose();
}
}
/// <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;
}
#region CTU
/// <summary>
/// 生成CTU任务执行

View File

@@ -34,7 +34,7 @@ namespace Tnb.WarehouseMgr
/// 盘点任务
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSCHECKTASK_ID)]
public class WmsCheckTaskService : BaseWareHouseService
public class WmsCheckTaskService : ServiceLoggerBase<WmsCheckTaskService>
{
private readonly ISqlSugarClient _db;
private readonly IWareHouseService _warehouseService;

View File

@@ -6,11 +6,11 @@ using Tnb.WarehouseMgr.Entities.Consts;
namespace Tnb.WarehouseMgr
{
[OverideVisualDev(ModuleConsts.MODULE_WMSDISTASK_ID)]
public class WmsDistaskService : TaskManagerDelBase<WmsDistaskH>
public class WmsDistaskService : BaseWareHouseService
{
private readonly ISqlSugarClient _db;
public WmsDistaskService(ISqlSugarRepository<WmsDistaskH> repository):base(repository.AsSugarClient())
public WmsDistaskService(ISqlSugarRepository<WmsDistaskH> repository)
{
_db = repository.AsSugarClient();
OverideFuncs.DeleteAsync = Delete;

View File

@@ -35,7 +35,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSOUTSTOCK_ID)]
[ServiceModule(BizTypeId)]
public class WmsOutStockService : DevServBase<WmsOutStockService>, IWmsOutStockService
public class WmsOutStockService : ServiceLoggerBase<WmsOutStockService>, IWmsOutStockService
{
private const string BizTypeId = "26191522660645";
private readonly ISqlSugarClient _db;
@@ -59,7 +59,7 @@ namespace Tnb.WarehouseMgr
IBillRullService billRullService,
IWmsCarryMoveInStockService wmsCarryMoveInStockService,
IWmsCarryService wareCarryService,
IEventPublisher eventPublisher) : base(repository.AsSugarClient())
IEventPublisher eventPublisher)
{
_db = repository.AsSugarClient();
_dictionaryDataService = dictionaryDataService;
@@ -72,6 +72,7 @@ namespace Tnb.WarehouseMgr
_wareCarryService = wareCarryService;
OverideFuncs.CreateAsync = OutStockApplyFor;
_ = InitializationTask;
}
public async Task<dynamic> OutStockApplyFor(VisualDevModelDataCrInput input)
@@ -114,7 +115,7 @@ namespace Tnb.WarehouseMgr
List<string?> freeLocIds = fLocIds.Except(minTaskNumLocs.Select(x => x.endlocation_id)).ToList();
if (freeLocIds?.Count > 0)
{
int rIdx = Random.Shared.Next(0, freeLocIds.Count);
int rIdx = Random.Shared.Next(0, freeLocIds.Count);
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == freeLocIds[rIdx]);
}
else
@@ -711,7 +712,6 @@ namespace Tnb.WarehouseMgr
List<WmsPointH> points = new List<WmsPointH>();
if (sPoint.area_code != ePoint.area_code)
{
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
{
throw new AppFriendlyException("该路径不存在", 500);
@@ -739,11 +739,6 @@ namespace Tnb.WarehouseMgr
startlocation_code = sPoint?.location_code ?? string.Empty,
endlocation_id = ePoint?.location_id ?? string.Empty,
endlocation_code = ePoint?.location_code ?? string.Empty,
startpoint_id = sPoint.id,
startpoint_code = sPoint.point_code,
endpoint_id = ePoint.id,
endpoint_code = ePoint.point_code,
start_floor = sPoint?.floor.ToString(),
end_floor = ePoint?.floor.ToString(),
bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(),