From 46148de70301abd144d5f03d219cbbcfaa40b2f0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 21 Apr 2026 18:38:22 +0200 Subject: [PATCH] test positivo creazione ordini fornitore --- .../DataServiceCollectionExtensions.cs | 6 +- .../EgwCoreLib.Lux.Data.csproj | 1 - .../Services/Supplier/BuyOrderService.cs | 141 ++++++++++++++++++ .../Services/Supplier/IBuyOrderService.cs | 74 +++++++++ Lux.UI/Components/Pages/BuyOrder.razor.cs | 45 ++++-- 5 files changed, 252 insertions(+), 15 deletions(-) create mode 100644 EgwCoreLib.Lux.Data/Services/Supplier/BuyOrderService.cs create mode 100644 EgwCoreLib.Lux.Data/Services/Supplier/IBuyOrderService.cs diff --git a/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs b/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs index 8aea8210..7007fc62 100644 --- a/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs +++ b/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ -using EgwCoreLib.Lux.Data.Services.Catalog; +using EgwCoreLib.Lux.Data.Repository.Supplier; +using EgwCoreLib.Lux.Data.Services.Catalog; using EgwCoreLib.Lux.Data.Services.Config; using EgwCoreLib.Lux.Data.Services.Cost; using EgwCoreLib.Lux.Data.Services.General; @@ -7,6 +8,7 @@ using EgwCoreLib.Lux.Data.Services.Items; using EgwCoreLib.Lux.Data.Services.Job; using EgwCoreLib.Lux.Data.Services.Production; using EgwCoreLib.Lux.Data.Services.Sales; +using EgwCoreLib.Lux.Data.Services.Supplier; using EgwCoreLib.Lux.Data.Services.Utils; using EgwCoreLib.Lux.Data.Services.Warehouse; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -27,6 +29,7 @@ namespace EgwCoreLib.Lux.Data services.TryAddSingleton(); // Repository Scoped + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); @@ -60,6 +63,7 @@ namespace EgwCoreLib.Lux.Data services.TryAddScoped(); // Servizi Scoped + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); diff --git a/EgwCoreLib.Lux.Data/EgwCoreLib.Lux.Data.csproj b/EgwCoreLib.Lux.Data/EgwCoreLib.Lux.Data.csproj index b84c34a9..fed9128f 100644 --- a/EgwCoreLib.Lux.Data/EgwCoreLib.Lux.Data.csproj +++ b/EgwCoreLib.Lux.Data/EgwCoreLib.Lux.Data.csproj @@ -54,7 +54,6 @@ - diff --git a/EgwCoreLib.Lux.Data/Services/Supplier/BuyOrderService.cs b/EgwCoreLib.Lux.Data/Services/Supplier/BuyOrderService.cs new file mode 100644 index 00000000..00c6bf43 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Supplier/BuyOrderService.cs @@ -0,0 +1,141 @@ +using EgwCoreLib.Lux.Data.Repository.Supplier; + +namespace EgwCoreLib.Lux.Data.Services.Supplier +{ + public class BuyOrderService : BaseServ, IBuyOrderService + { + #region Public Constructors + + public BuyOrderService( + IConfiguration config, + IConnectionMultiplexer redis, + IBuyOrderRepository repo) : base(config, redis) + { + _className = "BuyOrder"; + _repo = repo; + } + + #endregion Public Constructors + + #region Public Methods + + /// + public async Task GenerateFromSelectionAsync(Dictionary> currSelDict) + { + return await TraceAsync($"{_className}.GetByIdAsync", async (activity) => + { + return await GetOrSetCacheAsync( + $"{_redisBaseKey}:{_className}:LastGen", + async () => await _repo.GenerateFromSelectionAsync(currSelDict), + UltraFastCache + ); + }); + } + + /// + public async Task> GetAllAsync() + { + return await TraceAsync($"{_className}.GetAllAsync", async (activity) => + { + return await GetOrSetCacheAsync( + $"{_redisBaseKey}:{_className}:ALL", + async () => await _repo.GetAllAsync(), + UltraLongCache + ); + }); + } + + /// + public async Task GetByIdAsync(int orderId) + { + return await TraceAsync($"{_className}.GetByIdAsync", async (activity) => + { + return await GetOrSetCacheAsync( + $"{_redisBaseKey}:{_className}:ById:{orderId}", + async () => await _repo.GetByIdAsync(orderId), + UltraLongCache + ); + }); + } + + /// + public async Task UpsertAsync(BuyOrderModel upsRec) + { + return await TraceAsync($"{_className}.Upsert", async (activity) => + { + var currRec = await _repo.GetByIdAsync(upsRec.BuyOrderID); + + string operation = "UPDATE"; + bool success = false; + if (currRec != null) + { + success = await _repo.UpdateAsync(upsRec); + } + else + { + operation = "INSERT"; + success = await _repo.AddAsync(upsRec); + } + + activity?.SetTag("db.operation", operation); + + if (success) + { + await ClearCacheAsync($"{_redisBaseKey}:{_className}:*"); + } + + return success; + }); + } + + #endregion Public Methods + + ///// + //public async Task> GetUnprocAsync() + //{ + // return await TraceAsync($"{_className}.GetUnprocAsync", async (activity) => + // { + // return await GetOrSetCacheAsync( + // $"{_redisBaseKey}:{_className}:Unproc", + // async () => await _repo.GetFiltAsync(null, null, null, false), + // UltraLongCache + // ); + // }); + //} + + ///// + //public async Task ReconcileOrderRowsAsync(List ListOrderRow, bool forceReset = false) + //{ + // return await TraceAsync($"{_className}.ReconcileOrderRowsAsync", async (activity) => + // { + // List listaSpesa = new(); + // // ciclo sulle righe x trasformare BOM in fabbisogni... + // foreach (var currItem in ListOrderRow) + // { + // var newReq = await GetFabbisogniAsync(currItem, forceReset); + // listaSpesa.AddRange(newReq); + // } + + // //bool success = await _repo.AddManyAsync(listaSpesa); + // bool success = await _repo.UpsertManyAsync(listaSpesa); + + // activity?.SetTag("db.operation", "ReconcileOrderRowsAsync"); + + // if (success) + // { + // await ClearCacheAsync($"{_redisBaseKey}:{_className}:*"); + // } + + // return success; + // }); + //} + + #region Private Fields + + private readonly string _className; + + private readonly IBuyOrderRepository _repo; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Services/Supplier/IBuyOrderService.cs b/EgwCoreLib.Lux.Data/Services/Supplier/IBuyOrderService.cs new file mode 100644 index 00000000..52b54cc5 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Supplier/IBuyOrderService.cs @@ -0,0 +1,74 @@ +namespace EgwCoreLib.Lux.Data.Services.Supplier +{ + /// + /// Interfaccia per la gestione degli ordini. + /// + public interface IBuyOrderService + { + #region Public Methods + + /// + /// Generazione di un nuovo BuyOrder + righe + associazione fabbisogni da dizionario + /// + /// Dizionario selezione CodGroup, List + /// + Task GenerateFromSelectionAsync(Dictionary> currSelDict); + + ///// + ///// Elimina un ordine dal database. + ///// + ///// L'ordine da eliminare. + ///// True se l'eliminazione ha successo, false altrimenti. + //Task DeleteAsync(BuyOrderModel entity); + /// + /// Recupera l'elenco di tutti gli ordini. + /// + /// L'elenco di tutti gli ordini con clienti, rivenditori e righe associate. + Task> GetAllAsync(); + + /// + /// Recupera un ordine per il suo identificatore. + /// + /// L'identificatore dell'ordine. + /// L'ordine corrispondente, o null se non esiste. + Task GetByIdAsync(int recId); + + /// + /// Upsert (add/update) per BuyOrder nel database. + /// + /// L'ordine da inserire. + /// True se l'inserimento ha successo, false altrimenti. + Task UpsertAsync(BuyOrderModel upsRec); + + #endregion Public Methods + + ///// + ///// Recupera gli ordini inseriti in un intervallo di date specifico. + ///// + ///// La data di inizio del periodo. + ///// La data di fine del periodo. + ///// L'elenco degli ordini nell'intervallo specificato. + //Task> GetFiltAsync(DateTime inizio, DateTime fine); + + ///// + ///// Recupera le righe dell'ordine per un ordine specifico. + ///// + ///// L'identificatore dell'ordine. + ///// L'elenco delle righe dell'ordine. + //Task> GetRowsAsync(int recId); + + ///// + ///// Aggiorna in batch le righe di un ordine. + ///// + ///// L'elenco delle righe da aggiornare. + ///// True se l'aggiornamento ha successo, false altrimenti. + //Task SaveRowsAsync(List rows); + + ///// + ///// Aggiorna un ordine esistente nel database. + ///// + ///// L'ordine aggiornato. + ///// True se l'aggiornamento ha successo, false altrimenti. + //Task UpdateAsync(BuyOrderModel entity); + } +} \ No newline at end of file diff --git a/Lux.UI/Components/Pages/BuyOrder.razor.cs b/Lux.UI/Components/Pages/BuyOrder.razor.cs index 05d517b3..22259b51 100644 --- a/Lux.UI/Components/Pages/BuyOrder.razor.cs +++ b/Lux.UI/Components/Pages/BuyOrder.razor.cs @@ -1,7 +1,38 @@ +using EgwCoreLib.Lux.Data.Services.Supplier; + namespace Lux.UI.Components.Pages { public partial class BuyOrder { + #region Private Fields + + private Dictionary> CurrSelDict = new(); + + private List CurrSelection = new(); + + #endregion Private Fields + + #region Private Properties + + [Inject] + private IBuyOrderService BOService { get; set; } = null; + + #endregion Private Properties + + #region Private Methods + + /// + /// Crea un ordine di acquisto + relative righe... + /// + /// + /// + /// + private Task CreateBuyOrder(KeyValuePair> ReqInfo) + { + Dictionary> dictReq = new Dictionary>(); + dictReq.Add(ReqInfo.Key, ReqInfo.Value); + return BOService.GenerateFromSelectionAsync(dictReq); + } private void RecordUpdate(Dictionary> newDictionary) { @@ -12,18 +43,6 @@ namespace Lux.UI.Components.Pages .ToList(); } - private Dictionary> CurrSelDict = new(); - private List CurrSelection = new(); - - /// - /// Crea un ordine di acquisto + relative righe... - /// - /// - /// - /// - private async Task CreateBuyOrder(KeyValuePair> ReqInfo) - { - - } + #endregion Private Methods } } \ No newline at end of file