This commit is contained in:
Adam 2025-11-18 11:09:33 +01:00
commit 2cd76a58a5
5 changed files with 55 additions and 19 deletions

View File

@ -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<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
=> await stockQuantityHistoryDtoDbTable.GetAll(true).ToListAsync();
=> await ctx.StockQuantityHistoryDtos.GetAll(true).ToListAsync();
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
=> await stockQuantityHistoryDtoDbTable.GetByProductIdAsync(productId, true).ToListAsync();
=> await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).ToListAsync();
[SignalR(SignalRTags.GetPartners)]
public async Task<List<Partner>> GetPartners()

View File

@ -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<Customer> Customers { get; set; }
public IRepository<CustomerRole> 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<Order> orderRepository,
IRepository<OrderItem> orderItemRepository,
@ -120,6 +122,7 @@ public class FruitBankDbContext : MgDbContextBase,
StockQuantityHistories = stockQuantityHistories;
StockQuantityHistoriesExt = stockQuantityHistoriesExt;
StockQuantityHistoryDtos = stockQuantityHistoryDtos;
}
public IQueryable<Customer> 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>(product.Id, weightToChange, true, true);
var storeId = (await _storeContext.GetCurrentStoreAsync()).Id;
var newStockWeight = await _fruitBankAttributeService.InsertOrUpdateNetWeightAsync<Product>(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, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight)), 1);
//var stockWeight = double.Round(await _fruitBankAttributeService.GetGenericAttributeValueAsync<Product, double>(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);

View File

@ -119,7 +119,7 @@ public class FruitBankEventConsumer :
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight)
{
//await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(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

View File

@ -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<OrderDtoDbTable>();
services.AddScoped<OrderItemDtoDbTable>();
services.AddScoped<OrderItemPalletDbTable>();
services.AddScoped<PartnerDbTable>();
services.AddScoped<ShippingDbTable>();
services.AddScoped<ShippingDocumentDbTable>();
@ -71,15 +72,15 @@ public class PluginNopStartup : INopStartup
services.AddScoped<ShippingItemPalletDbTable>();
services.AddScoped<FilesDbTable>();
services.AddScoped<ShippingDocumentToFilesDbTable>();
services.AddScoped<StockQuantityHistoryDtoDbTable>();
services.AddScoped<FruitBankDbContext>();
services.AddScoped<SignalRSendToClientService>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>();
//services.AddScoped<CustomModelFactory, ICustomerModelFactory>();
services.AddScoped<IPriceCalculationService, CustomPriceCalculationService>();
services.AddScoped<PriceCalculationService, CustomPriceCalculationService>();
@ -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<DevAdminSignalRHub>(fruitBankHubEndPoint);
endpoints.MapHub<DevAdminSignalRHub>(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}";

View File

@ -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)
/// <returns>Inserted NetWeight</returns>
private async Task<double> UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate)
{
await UpdateGenericAttributeAsync(genericAttribute, double.Round((cumulativeWeightUpdate ? CommonHelper.To<double>(genericAttribute.Value) + newWeightValue : newWeightValue), 1));
var newNetWeight = double.Round((cumulativeWeightUpdate ? CommonHelper.To<double>(genericAttribute.Value) + newWeightValue : newWeightValue), 1);
await UpdateGenericAttributeAsync(genericAttribute, newNetWeight);
return newNetWeight;
}
/// <returns>Inserted NetWeight</returns>
public async Task<double> InsertOrUpdateNetWeightAsync<TEntity>(int entityId, double netWeight, bool cumulativeWeightUpdate)
=> await InsertOrUpdateNetWeightAsync<TEntity>(entityId, netWeight, cumulativeWeightUpdate, (await storeContext.GetCurrentStoreAsync()).Id);
/// <returns>Inserted NetWeight</returns>
public async Task<double> InsertOrUpdateNetWeightAsync<TEntity>(int entityId, double netWeight, bool cumulativeWeightUpdate, int storeId)
{
var netWeightGa = await GetGenericAttributeAsync<TEntity>(entityId, NET_WEIGHT_KEY, storeId);
if (netWeightGa != null) return await UpdateMeasuringWeightAttributeValueAsync(netWeightGa, netWeight, cumulativeWeightUpdate);
netWeight = double.Round(netWeight, 1);
await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, double.Round(netWeight, 1), storeId);
return netWeight;
}
public async Task DeleteAllMeasuringAttributesAsync<TEntity>(int entityId, int storeId)