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( public class FruitBankDataController(
FruitBankDbContext ctx, FruitBankDbContext ctx,
MeasurementService measurementService, MeasurementService measurementService,
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtoDbTable,
IWorkContext workContext, IWorkContext workContext,
ICustomerService customerService, ICustomerService customerService,
ICustomerRegistrationService customerRegistrationService, ICustomerRegistrationService customerRegistrationService,
@ -54,11 +53,11 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
[SignalR(SignalRTags.GetStockQuantityHistoryDtos)] [SignalR(SignalRTags.GetStockQuantityHistoryDtos)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos() public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtos()
=> await stockQuantityHistoryDtoDbTable.GetAll(true).ToListAsync(); => await ctx.StockQuantityHistoryDtos.GetAll(true).ToListAsync();
[SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)] [SignalR(SignalRTags.GetStockQuantityHistoryDtosByProductId)]
public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId) public async Task<List<StockQuantityHistoryDto>> GetStockQuantityHistoryDtosByProductId(int productId)
=> await stockQuantityHistoryDtoDbTable.GetByProductIdAsync(productId, true).ToListAsync(); => await ctx.StockQuantityHistoryDtos.GetByProductIdAsync(productId, true).ToListAsync();
[SignalR(SignalRTags.GetPartners)] [SignalR(SignalRTags.GetPartners)]
public async Task<List<Partner>> GetPartners() public async Task<List<Partner>> GetPartners()

View File

@ -61,6 +61,7 @@ public class FruitBankDbContext : MgDbContextBase,
public FilesDbTable Files { get; set; } public FilesDbTable Files { get; set; }
public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; } public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; }
public StockQuantityHistoryDtoDbTable StockQuantityHistoryDtos { get; set; }
public IRepository<Customer> Customers { get; set; } public IRepository<Customer> Customers { get; set; }
public IRepository<CustomerRole> CustomerRoles { get; set; } public IRepository<CustomerRole> CustomerRoles { get; set; }
@ -75,6 +76,7 @@ public class FruitBankDbContext : MgDbContextBase,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
ProductDtoDbTable productDtoDbTable, OrderDtoDbTable orderDtoDbTable, OrderItemDtoDbTable orderItemDtoDbTable, OrderItemPalletDbTable orderItemPalletDbTable, ProductDtoDbTable productDtoDbTable, OrderDtoDbTable orderDtoDbTable, OrderItemDtoDbTable orderItemDtoDbTable, OrderItemPalletDbTable orderItemPalletDbTable,
StockQuantityHistoryDtoDbTable stockQuantityHistoryDtos,
IProductService productService, IStaticCacheManager staticCacheManager, IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Order> orderRepository, IRepository<Order> orderRepository,
IRepository<OrderItem> orderItemRepository, IRepository<OrderItem> orderItemRepository,
@ -120,6 +122,7 @@ public class FruitBankDbContext : MgDbContextBase,
StockQuantityHistories = stockQuantityHistories; StockQuantityHistories = stockQuantityHistories;
StockQuantityHistoriesExt = stockQuantityHistoriesExt; StockQuantityHistoriesExt = stockQuantityHistoriesExt;
StockQuantityHistoryDtos = stockQuantityHistoryDtos;
} }
public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName) public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName)
@ -683,7 +686,7 @@ public class FruitBankDbContext : MgDbContextBase,
{ {
ProductId = product.Id, ProductId = product.Id,
CombinationId = null, CombinationId = null,
WarehouseId = product.WarehouseId > 0 ? (int?)product.WarehouseId : null, WarehouseId = product.WarehouseId > 0 ? product.WarehouseId : null,
QuantityAdjustment = 0, QuantityAdjustment = 0,
StockQuantity = product.StockQuantity, StockQuantity = product.StockQuantity,
Message = message, Message = message,
@ -696,7 +699,8 @@ public class FruitBankDbContext : MgDbContextBase,
if (weightToChange == 0) return; 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) if (latStockQuantityHistoryId <= 0)
{ {
@ -704,18 +708,20 @@ public class FruitBankDbContext : MgDbContextBase,
latStockQuantityHistoryId = await StockQuantityHistories.Table.Where(x => x.ProductId == product.Id).MaxAsync(x => x.Id); latStockQuantityHistoryId = await StockQuantityHistories.Table.Where(x => x.ProductId == product.Id).MaxAsync(x => x.Id);
if (latStockQuantityHistoryId == 0) if (latStockQuantityHistoryId == 0)
{ {
Logger.Error($"UpdateProductDtoStockQuantityAndWeightAsync (latStockQuantityHistory == 0). product.Id: {product.Id}"); Logger.Error($"UpdateStockQuantityAndWeightAsync(); (latStockQuantityHistory == 0). product.Id: {product.Id}");
return; 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 var stockQuantityHistoryExt = new StockQuantityHistoryExt
{ {
StockQuantityHistoryId = latStockQuantityHistoryId, StockQuantityHistoryId = latStockQuantityHistoryId,
NetWeightAdjustment = weightToChange, NetWeightAdjustment = weightToChange,
NetWeight = stockWeight, NetWeight = newStockWeight,
IsInconsistent = lastStockQuantityHistoryExtNetWeight != null && double.Round(lastStockQuantityHistoryExtNetWeight.Value + weightToChange, 1) != newStockWeight
}; };
await StockQuantityHistoriesExt.InsertAsync(stockQuantityHistoryExt, false); await StockQuantityHistoriesExt.InsertAsync(stockQuantityHistoryExt, false);

View File

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

View File

@ -10,6 +10,7 @@ using FruitBank.Common.Server.Services.SignalRs;
using Mango.Nop.Services; using Mango.Nop.Services;
using Mango.Nop.Services.Loggers; using Mango.Nop.Services.Loggers;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
@ -122,6 +123,9 @@ public class PluginNopStartup : INopStartup
hubOptions.MaximumReceiveMessageSize = null; // 256 * 1024; hubOptions.MaximumReceiveMessageSize = null; // 256 * 1024;
hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignalRKeepAliveIntervalSecond); hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignalRKeepAliveIntervalSecond);
hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignarlRTimeoutIntervalSecond); 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,8 +140,14 @@ public class PluginNopStartup : INopStartup
{ {
app.UseEndpoints(endpoints => 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.
});
}); });
}); });

View File

@ -99,9 +99,30 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
//await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable); //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) public async Task DeleteAllMeasuringAttributesAsync<TEntity>(int entityId, int storeId)