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

@@ -11,6 +11,15 @@ const entityToQueryKeys: Record<string, string[]> = {
articoli: ['articoli', 'lookup'], articoli: ['articoli', 'lookup'],
'evento-costi': ['evento-costi', 'evento'], 'evento-costi': ['evento-costi', 'evento'],
demo: ['eventi', 'clienti', 'location', 'risorse', 'articoli', 'calendario', 'lookup'], demo: ['eventi', 'clienti', 'location', 'risorse', 'articoli', 'calendario', 'lookup'],
// Warehouse Module
warehouse_article: ['warehouse', 'articles'],
warehouse_category: ['warehouse', 'categories'],
warehouse_location: ['warehouse', 'locations'],
stock_movement: ['warehouse', 'movements'],
article_batch: ['warehouse', 'batches'],
article_serial: ['warehouse', 'serials'],
inventory_count: ['warehouse', 'inventories'],
stock_level: ['warehouse', 'stock-levels'],
}; };
/** /**

View File

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

Binary file not shown.

Binary file not shown.