与任务执行,新增信号量锁,解决并发环境下数据的一致性问题
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -13,19 +14,35 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class BaseWareHouseService<T> : BaseWareHouseService
|
||||
{
|
||||
protected static Dictionary<string, object> _elevatorMap = new Dictionary<string, object>();
|
||||
protected static Dictionary<string, object> s_elevatorMap = new Dictionary<string, object>();
|
||||
private static readonly Lazy<Task> initializationTask;
|
||||
|
||||
public BaseWareHouseService(ISqlSugarClient db)
|
||||
|
||||
static BaseWareHouseService()
|
||||
{
|
||||
if (_elevatorMap.Count < 1)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
_elevatorMap = await db.Queryable<WmsElevatorH>().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code);
|
||||
});
|
||||
}
|
||||
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/custom{DateTime.Now:yyyyMMdd}.log", cfgOpts =>
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user