diff --git a/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs b/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs index b59c5dc..5dde516 100644 --- a/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs @@ -30,7 +30,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers public class FruitBankDataController( FruitBankDbContext ctx, MeasurementService measurementService, - StockQuantityHistoryDtoDbTable stockQuantityHistoryDtoDbTable, IWorkContext workContext, ICustomerService customerService, ICustomerRegistrationService customerRegistrationService, @@ -54,11 +53,11 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers [SignalR(SignalRTags.GetStockQuantityHistoryDtos)] public async Task> GetStockQuantityHistoryDtos() - => await stockQuantityHistoryDtoDbTable.GetAll(true).ToListAsync(); + => await ctx.StockQuantityHistoryDtos.GetAll(true).ToListAsync(); [SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)] public async Task> GetStockQuantityHistoryDtosByProductId(int productId) - => await stockQuantityHistoryDtoDbTable.GetByProductIdAsync(productId, true).ToListAsync(); + => await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).ToListAsync(); [SignalR(SignalRTags.GetPartners)] public async Task> GetPartners() diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs index 3b273f0..fe05339 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs @@ -61,6 +61,7 @@ public class FruitBankDbContext : MgDbContextBase, public FilesDbTable Files { get; set; } public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; } + public StockQuantityHistoryDtoDbTable StockQuantityHistoryDtos { get; set; } public IRepository Customers { get; set; } public IRepository CustomerRoles { get; set; } @@ -75,6 +76,7 @@ public class FruitBankDbContext : MgDbContextBase, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable, ProductDtoDbTable productDtoDbTable, OrderDtoDbTable orderDtoDbTable, OrderItemDtoDbTable orderItemDtoDbTable, OrderItemPalletDbTable orderItemPalletDbTable, + StockQuantityHistoryDtoDbTable stockQuantityHistoryDtos, IProductService productService, IStaticCacheManager staticCacheManager, IRepository orderRepository, IRepository orderItemRepository, @@ -120,6 +122,7 @@ public class FruitBankDbContext : MgDbContextBase, StockQuantityHistories = stockQuantityHistories; StockQuantityHistoriesExt = stockQuantityHistoriesExt; + StockQuantityHistoryDtos = stockQuantityHistoryDtos; } public IQueryable GetCustomersBySystemRoleName(string systemRoleName) @@ -683,7 +686,7 @@ public class FruitBankDbContext : MgDbContextBase, { ProductId = product.Id, CombinationId = null, - WarehouseId = product.WarehouseId > 0 ? (int?)product.WarehouseId : null, + WarehouseId = product.WarehouseId > 0 ? product.WarehouseId : null, QuantityAdjustment = 0, StockQuantity = product.StockQuantity, Message = message, @@ -696,26 +699,29 @@ public class FruitBankDbContext : MgDbContextBase, if (weightToChange == 0) return; - await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync(product.Id, weightToChange, true, true); - + var storeId = (await _storeContext.GetCurrentStoreAsync()).Id; + var newStockWeight = await _fruitBankAttributeService.InsertOrUpdateNetWeightAsync(product.Id, weightToChange, true, storeId); + if (latStockQuantityHistoryId <= 0) { //A LastOrDefaultAsync elszáll! - J. latStockQuantityHistoryId = await StockQuantityHistories.Table.Where(x => x.ProductId == product.Id).MaxAsync(x => x.Id); if (latStockQuantityHistoryId == 0) { - Logger.Error($"UpdateProductDtoStockQuantityAndWeightAsync (latStockQuantityHistory == 0). product.Id: {product.Id}"); + Logger.Error($"UpdateStockQuantityAndWeightAsync(); (latStockQuantityHistory == 0). product.Id: {product.Id}"); return; } } - var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync(product.Id, nameof(IMeasuringNetWeight.NetWeight)), 1); + //var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync(product.Id, nameof(IMeasuringNetWeight.NetWeight), storeId), 1); + var lastStockQuantityHistoryExtNetWeight = await StockQuantityHistoryDtos.Table.Where(x => x.ProductId == product.Id && x.StockQuantityHistoryExt != null).Select(x => x.StockQuantityHistoryExt!.NetWeight).FirstOrDefaultAsync(netWeight => netWeight != null); var stockQuantityHistoryExt = new StockQuantityHistoryExt { StockQuantityHistoryId = latStockQuantityHistoryId, NetWeightAdjustment = weightToChange, - NetWeight = stockWeight, + NetWeight = newStockWeight, + IsInconsistent = lastStockQuantityHistoryExtNetWeight != null && double.Round(lastStockQuantityHistoryExtNetWeight.Value + weightToChange, 1) != newStockWeight }; await StockQuantityHistoriesExt.InsertAsync(stockQuantityHistoryExt, false); diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs b/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs index 6086d8f..6fcc4ca 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/EventConsumers/FruitBankEventConsumer.cs @@ -119,7 +119,7 @@ public class FruitBankEventConsumer : if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight) { //await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight); - await _ctx.UpdateStockQuantityAndWeightAsync(productDto, 0, $"Manuális készlet súly változtatás az admin felületen.", netWeight - productDtoNetWeight.GetValueOrDefault(0)); + await _ctx.UpdateStockQuantityAndWeightAsync(product, 0, $"Manuális készlet súly változtatás az admin felületen.", netWeight - productDtoNetWeight.GetValueOrDefault(0)); } //Tára diff --git a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs index a597f9a..ccc2565 100644 --- a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs @@ -10,6 +10,7 @@ using FruitBank.Common.Server.Services.SignalRs; using Mango.Nop.Services; using Mango.Nop.Services.Loggers; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Configuration; @@ -63,7 +64,7 @@ public class PluginNopStartup : INopStartup services.AddScoped(); services.AddScoped(); services.AddScoped(); - + services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -71,15 +72,15 @@ public class PluginNopStartup : INopStartup services.AddScoped(); services.AddScoped(); services.AddScoped(); - + services.AddScoped(); - + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); - + //services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -119,9 +120,12 @@ public class PluginNopStartup : INopStartup services.AddSignalR(hubOptions => { //hubOptions.EnableDetailedErrors = true; - hubOptions.MaximumReceiveMessageSize = null;// 256 * 1024; + hubOptions.MaximumReceiveMessageSize = null; // 256 * 1024; hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignalRKeepAliveIntervalSecond); hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignarlRTimeoutIntervalSecond); + //hubOptions.MaximumParallelInvocationsPerClient = 1; //default: 1; + //hubOptions.StatefulReconnectBufferSize = 1_000_000; //default: 100,000 bytes; + //hubOptions.HandshakeTimeout = TimeSpan.FromSeconds(15); //default timeout is 15 seconds }); } @@ -136,9 +140,15 @@ public class PluginNopStartup : INopStartup { app.UseEndpoints(endpoints => { - endpoints.MapHub(fruitBankHubEndPoint); + endpoints.MapHub(fruitBankHubEndPoint, options => + { + options.Transports = HttpTransportType.WebSockets;// | HttpTransportType.LongPolling; + options.WebSockets.CloseTimeout = new TimeSpan(0, 0, 10); //default: 5 sec. + //options.LongPolling.PollTimeout = new TimeSpan(0, 0, 90); //default: 90 sec. - }); + options.TransportSendTimeout = new TimeSpan(60); //default: 10 sec. + }); + }); }); var loggrHubEndPoint = $"/{FruitBankConstClient.LoggerHubName}"; diff --git a/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs b/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs index 1458992..ee51313 100644 --- a/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs +++ b/Nop.Plugin.Misc.AIPlugin/Services/FruitBankAttributeService.cs @@ -99,9 +99,30 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute //await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable); } - private async Task UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate) + /// Inserted NetWeight + private async Task UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate) { - await UpdateGenericAttributeAsync(genericAttribute, double.Round((cumulativeWeightUpdate ? CommonHelper.To(genericAttribute.Value) + newWeightValue : newWeightValue), 1)); + var newNetWeight = double.Round((cumulativeWeightUpdate ? CommonHelper.To(genericAttribute.Value) + newWeightValue : newWeightValue), 1); + await UpdateGenericAttributeAsync(genericAttribute, newNetWeight); + + return newNetWeight; + } + + /// Inserted NetWeight + public async Task InsertOrUpdateNetWeightAsync(int entityId, double netWeight, bool cumulativeWeightUpdate) + => await InsertOrUpdateNetWeightAsync(entityId, netWeight, cumulativeWeightUpdate, (await storeContext.GetCurrentStoreAsync()).Id); + + /// Inserted NetWeight + public async Task InsertOrUpdateNetWeightAsync(int entityId, double netWeight, bool cumulativeWeightUpdate, int storeId) + { + var netWeightGa = await GetGenericAttributeAsync(entityId, NET_WEIGHT_KEY, storeId); + + if (netWeightGa != null) return await UpdateMeasuringWeightAttributeValueAsync(netWeightGa, netWeight, cumulativeWeightUpdate); + + netWeight = double.Round(netWeight, 1); + await InsertGenericAttributeAsync(entityId, NET_WEIGHT_KEY, double.Round(netWeight, 1), storeId); + + return netWeight; } public async Task DeleteAllMeasuringAttributesAsync(int entityId, int storeId)