This commit is contained in:
Adam 2025-11-12 17:57:44 +01:00
commit 995fa050ef
7 changed files with 49 additions and 20 deletions

View File

@ -170,7 +170,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos();
[NonAction]
public Task<List<OrderDto>> GetPendingOrderDtosForMeasuring() => _customOrderSignalREndpoint.GetPendingOrderDtosForMeasuring();
public Task<List<OrderDto>> GetPendingOrderDtosForMeasuring(int lastDaysCount) => _customOrderSignalREndpoint.GetPendingOrderDtosForMeasuring(lastDaysCount);
[NonAction]
public Task<OrderDto> StartMeasuring(int orderId, int userId) => _customOrderSignalREndpoint.StartMeasuring(orderId, userId);

View File

@ -41,9 +41,18 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, SignalRSendToCli
}
[SignalR(SignalRTags.GetPendingOrderDtosForMeasuring)]
public async Task<List<OrderDto>> GetPendingOrderDtosForMeasuring()
public async Task<List<OrderDto>> GetPendingOrderDtosForMeasuring(int lastDaysCount)
{
return await ctx.OrderDtos.GetAllForMeasuring().ToListAsync();
var fromDate = DateTime.Now.AddDays(-lastDaysCount);
return await ctx.OrderDtos.GetAllForMeasuring(fromDate).ToListAsync();
}
[SignalR(SignalRTags.GetOrderDatesForMeasuring)]
public async Task<List<OrderDto>> GetOrderDatesForMeasuring(int lastDaysCount)
{
var fromDate = DateTime.Now.AddDays(-lastDaysCount);
//return await ctx.OrderDtos.GetAllForMeasuring(fromDate).Select(x => new MeasuringOrderDate(...)).ToListAsync();
return null;
}
[SignalR(SignalRTags.GetAllOrderDtoByIds)]

View File

@ -179,7 +179,6 @@ public class FruitBankDbContext : MgDbContextBase,
return true;
});
}
public async Task DeleteShippingDocumentSafeAsync(ShippingDocument shippingDocument)
{
await TransactionSafeAsync(async _ =>
@ -205,11 +204,20 @@ public class FruitBankDbContext : MgDbContextBase,
Logger.Error("shippingItem.IsMeasurable && !shippingItem.IsValidMeasuringValues()");
return Task.FromResult(false);
}
public Task<bool> AddShippingItemSafeAsync(ShippingItem shippingItem)
=> TransactionSafeAsync(async _ => await AddShippingItemAsync(shippingItem));
public async Task<bool> AddShippingItemAsync(ShippingItem shippingItem)
{
var productId = shippingItem.ProductId.GetValueOrDefault(0);
if (productId > 0)
{
var productDto = await ProductDtos.GetByIdAsync(productId);
shippingItem.IsMeasurable = productDto?.IsMeasurable ?? false;
}
await ShippingItems.InsertAsync(shippingItem);
return true;
}
@ -528,16 +536,17 @@ public class FruitBankDbContext : MgDbContextBase,
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(productDto.Id, nameof(IMeasuringNetWeight.NetWeight), newProductNetWeight);
Logger.Info($"DeleteOrderItemConstraints; Product netWeight updated! productId: {productDto.Id}; newNetWeight: {newProductNetWeight}; oldNetWeight: {productDto.NetWeight}; deleted orderItemNetWeight: {validOrderItemNetWeight}; orderItem.Id: {orderItem.Id};");
Logger.Info($"DbContext->DeleteOrderItemConstraintsAsync(); Product netWeight updated! productId: {productDto.Id}; newNetWeight: {newProductNetWeight}; oldNetWeight: {productDto.NetWeight}; deleted orderItemNetWeight: {validOrderItemNetWeight}; orderItem.Id: {orderItem.Id};");
}
}
await _fruitBankAttributeService.DeleteGenericAttributesAsync(orderItemGenericAttributes);
var deletedPalletCount = await OrderItemPallets.DeleteAsync(x => x.OrderItemId == orderItem.Id);
//await OrderItems.DeleteAsync(orderItem, publishEvent);
var order = await Orders.GetByIdAsync(orderItem.OrderId);
// await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
Logger.Info($"DeleteOrderItemConstraints; OrderItem constraints deleted! deletedPalletCount: {deletedPalletCount}; orderItem.Id: {orderItem.Id};");
Logger.Info($"DbContext->DeleteOrderItemConstraintsAsync(); OrderItem constraints deleted! deletedPalletCount: {deletedPalletCount}; deletedAttributesCount: {orderItemGenericAttributes.Count}; orderItem.Id: {orderItem.Id};");
}
public async Task<OrderItemPallet?> AddOrderItemPalletAsync(OrderItemPallet orderItemPallet)

View File

@ -21,12 +21,18 @@ public class OrderDtoDbTable : MgDtoDbTableBase<OrderDto, Order>
public IQueryable<OrderDto> GetAll(bool loadRelations)
{
return GetAll()
.LoadWith(o => o.GenericAttributes)
.LoadWith(o => o.Customer)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets);
if (loadRelations)
{
return GetAll()
.LoadWith(o => o.GenericAttributes)
.LoadWith(o => o.Customer)
.LoadWith(o => o.OrderNotes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets);
}
return GetAll().LoadWith(o => o.GenericAttributes);
}
public Task<OrderDto> GetByIdAsync(int orderId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
@ -34,10 +40,11 @@ public class OrderDtoDbTable : MgDtoDbTableBase<OrderDto, Order>
public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus, bool loadRelations = true)
=> GetAll(loadRelations).Where(o => o.OrderStatusId == (int)orderStatus);
public IQueryable<OrderDto> GetAllForMeasuring(bool loadRelations = true)
=> GetAll(loadRelations).Where(o => o.PaymentStatusId < (int)PaymentStatus.Paid && o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt)));
//=> GetAllByOrderStatus(OrderStatus.Pending, loadRelations).Where(o => o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt)));
public IQueryable<OrderDto> GetAllForMeasuring(DateTime fromDate, bool loadRelations = true)
=> GetAll(loadRelations).Where(o => o.PaymentStatusId < (int)PaymentStatus.Paid
&& o.OrderStatusId != (int)OrderStatus.Cancelled
&& o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt) && DateTime.Parse(ga.Value) >= fromDate.Date));
public IQueryable<OrderDto> GetAllByProductId(int productId, bool loadRelations = true) => GetAll(loadRelations).Where(o => o.OrderItemDtos.Any(oi => oi.ProductId == productId));
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds, bool loadRelations = true) => GetAll(loadRelations).Where(o => orderIds.Contains(o.Id));

View File

@ -21,7 +21,8 @@ public class OrderItemDtoDbTable : MgDtoDbTableBase<OrderItemDto, OrderItem>
{
return GetAll()
.LoadWith(oi => oi.GenericAttributes)
.LoadWith(oi => oi.OrderDto).ThenLoad(prod => prod.GenericAttributes)
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.OrderNotes)
.LoadWith(oi => oi.OrderDto).ThenLoad(o => o.GenericAttributes)
.LoadWith(oi => oi.OrderItemPallets).ThenLoad(oip => oip.OrderItemDto).ThenLoad(oi => oi.GenericAttributes)
.LoadWith(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes);
}

View File

@ -115,7 +115,7 @@ public class PluginNopStartup : INopStartup
services.AddSignalR(hubOptions =>
{
//hubOptions.EnableDetailedErrors = true;
hubOptions.MaximumReceiveMessageSize = 256 * 1024;
hubOptions.MaximumReceiveMessageSize = null;// 256 * 1024;
hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignalRKeepAliveIntervalSecond);
hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignarlRTimeoutIntervalSecond);
});

View File

@ -42,12 +42,15 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
public async Task DeleteOrderItemConstraintsAsync(OrderItem orderItem)
{
Logger.Info($"DeleteOrderItemConstraintsAsync invoked; orderItem.Id: {orderItem?.Id}");
Logger.Info($"MeasurementService->DeleteOrderItemConstraintsAsync() invoked; orderItem.Id: {orderItem?.Id}");
if (orderItem == null) return;
await _dbContext.DeleteOrderItemConstraintsSafeAsync(orderItem);
await _signalRSendToClientService.SendOrderItemDeleted(orderItem);
var order = await _dbContext.Orders.GetByIdAsync(orderItem.OrderId);
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
}
public async Task OrderItemInsertedOrUpdatedPostProcess(OrderItem orderItem)