This commit is contained in:
2025-11-29 17:10:50 +01:00
parent 8cba8db549
commit 71071f42dc
4 changed files with 42 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ using Apollinare.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Apollinare.API.Hubs;
namespace Apollinare.API.Modules.Warehouse.Services;
/// <summary>
@@ -15,6 +17,7 @@ public class WarehouseService : IWarehouseService
private readonly IMemoryCache _cache;
private readonly ILogger<WarehouseService> _logger;
private readonly AutoCodeService _autoCodeService;
private readonly DataNotificationService _notificationService;
private const string WAREHOUSES_CACHE_KEY = "warehouse_locations";
private const string CATEGORIES_CACHE_KEY = "warehouse_categories";
@@ -25,12 +28,14 @@ public class WarehouseService : IWarehouseService
AppollinareDbContext context,
IMemoryCache cache,
ILogger<WarehouseService> logger,
AutoCodeService autoCodeService)
AutoCodeService autoCodeService,
DataNotificationService notificationService)
{
_context = context;
_cache = cache;
_logger = logger;
_autoCodeService = autoCodeService;
_notificationService = notificationService;
}
#region Articoli
@@ -141,6 +146,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Creato articolo {Code} - {Description}", article.Code, article.Description);
await _notificationService.NotifyCreated("warehouse_article", article);
return article;
}
@@ -159,6 +165,7 @@ public class WarehouseService : IWarehouseService
existing.UpdatedAt = DateTime.UtcNow;
await _context.SaveChangesAsync();
await _notificationService.NotifyUpdated("warehouse_article", existing);
return existing;
}
@@ -180,6 +187,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Eliminato articolo {Code}", article.Code);
await _notificationService.NotifyDeleted("warehouse_article", id);
}
#endregion
@@ -280,6 +288,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
InvalidateCategoriesCache();
await _notificationService.NotifyCreated("warehouse_category", category);
return category;
}
@@ -294,6 +303,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
InvalidateCategoriesCache();
await _notificationService.NotifyUpdated("warehouse_category", existing);
return existing;
}
@@ -315,6 +325,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
InvalidateCategoriesCache();
await _notificationService.NotifyDeleted("warehouse_category", id);
}
private void InvalidateCategoriesCache()
@@ -387,6 +398,7 @@ public class WarehouseService : IWarehouseService
InvalidateWarehousesCache();
_logger.LogInformation("Creato magazzino {Code} - {Name}", warehouse.Code, warehouse.Name);
await _notificationService.NotifyCreated("warehouse_location", warehouse);
return warehouse;
}
@@ -409,6 +421,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
InvalidateWarehousesCache();
await _notificationService.NotifyUpdated("warehouse_location", existing);
return existing;
}
@@ -426,6 +439,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
InvalidateWarehousesCache();
await _notificationService.NotifyDeleted("warehouse_location", id);
}
public async Task SetDefaultWarehouseAsync(int id)
@@ -445,6 +459,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
InvalidateWarehousesCache();
await _notificationService.NotifyUpdated("warehouse_location", warehouse);
}
private void InvalidateWarehousesCache()
@@ -517,6 +532,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Creato lotto {BatchNumber} per articolo {ArticleId}", batch.BatchNumber, batch.ArticleId);
await _notificationService.NotifyCreated("article_batch", batch);
return batch;
}
@@ -530,6 +546,7 @@ public class WarehouseService : IWarehouseService
existing.UpdatedAt = DateTime.UtcNow;
await _context.SaveChangesAsync();
await _notificationService.NotifyUpdated("article_batch", existing);
return existing;
}
@@ -558,6 +575,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Aggiornato stato lotto {Id} a {Status}", id, status);
await _notificationService.NotifyUpdated("article_batch", batch);
}
#endregion
@@ -618,6 +636,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Creato seriale {SerialNumber} per articolo {ArticleId}", serial.SerialNumber, serial.ArticleId);
await _notificationService.NotifyCreated("article_serial", serial);
return serial;
}
@@ -631,6 +650,7 @@ public class WarehouseService : IWarehouseService
existing.UpdatedAt = DateTime.UtcNow;
await _context.SaveChangesAsync();
await _notificationService.NotifyUpdated("article_serial", existing);
return existing;
}
@@ -645,6 +665,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Aggiornato stato seriale {Id} a {Status}", id, status);
await _notificationService.NotifyUpdated("article_serial", serial);
}
#endregion
@@ -767,6 +788,7 @@ public class WarehouseService : IWarehouseService
stockLevel.StockValue = stockLevel.Quantity * (stockLevel.UnitCost ?? 0);
await _context.SaveChangesAsync();
await _notificationService.NotifyUpdated("stock_level", stockLevel);
}
#endregion
@@ -879,6 +901,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Creato movimento {DocumentNumber} tipo {Type}", movement.DocumentNumber, movement.Type);
await _notificationService.NotifyCreated("stock_movement", movement);
return movement;
}
@@ -908,6 +931,7 @@ public class WarehouseService : IWarehouseService
}
await _context.SaveChangesAsync();
await _notificationService.NotifyUpdated("stock_movement", existing);
return existing;
}
@@ -936,6 +960,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Confermato movimento {DocumentNumber}", movement.DocumentNumber);
await _notificationService.NotifyUpdated("stock_movement", movement);
return movement;
}
@@ -959,6 +984,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogWarning("Annullato movimento {DocumentNumber}", movement.DocumentNumber);
await _notificationService.NotifyUpdated("stock_movement", movement);
return movement;
}
@@ -1493,6 +1519,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Creato inventario {Code}", inventory.Code);
await _notificationService.NotifyCreated("inventory_count", inventory);
return inventory;
}
@@ -1509,6 +1536,7 @@ public class WarehouseService : IWarehouseService
existing.UpdatedAt = DateTime.UtcNow;
await _context.SaveChangesAsync();
await _notificationService.NotifyUpdated("inventory_count", existing);
return existing;
}
@@ -1531,6 +1559,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Avviato inventario {Code} con {Count} righe", inventory.Code, inventory.Lines.Count);
await _notificationService.NotifyUpdated("inventory_count", inventory);
return inventory;
}
@@ -1563,6 +1592,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogInformation("Completato inventario {Code}", inventory.Code);
await _notificationService.NotifyUpdated("inventory_count", inventory);
return inventory;
}
@@ -1632,6 +1662,7 @@ public class WarehouseService : IWarehouseService
_logger.LogInformation("Confermato inventario {Code}, movimento rettifica: {MovementId}",
inventory.Code, inventory.AdjustmentMovementId);
await _notificationService.NotifyUpdated("inventory_count", inventory);
return inventory;
}
@@ -1650,6 +1681,7 @@ public class WarehouseService : IWarehouseService
await _context.SaveChangesAsync();
_logger.LogWarning("Annullato inventario {Code}", inventory.Code);
await _notificationService.NotifyUpdated("inventory_count", inventory);
return inventory;
}

Binary file not shown.

Binary file not shown.