From 35ba4950302ab0856cb01f2dcca9dcfcdddcca19 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 18 Mar 2026 12:44:27 +0100 Subject: [PATCH] Completo implementazione base porting OrdeRow a servizio a se --- .../Controllers/LuxController.cs | 52 ++++++------ .../Repository/Sales/IOrderRowRepository.cs | 7 +- .../Repository/Sales/OrderRowRepository.cs | 20 +++++ .../Services/DataLayerServices.cs | 84 ++++++++++--------- .../Services/Sales/IOrderRowService.cs | 7 ++ .../Services/Sales/OrderRowService.cs | 69 +++++++++++++++ 6 files changed, 171 insertions(+), 68 deletions(-) diff --git a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs index f370882c..df9b9f1d 100644 --- a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs +++ b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs @@ -610,31 +610,6 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } - /// - /// Validazione record: - /// - controllo state vs estimate - /// - segnala il numero dei record aggiornati - /// - /// Elenco record da verificare - internal async Task OrderRowListValidate(List list2chk) - { - int numDone = 0; - // verifica preliminare: serve SSE stato e estimate non corrispondono... - var list2fix = list2chk - .Where(x => x.OrderRowState == OrderStates.Created && !string.IsNullOrEmpty(x.ProdEstimate)) - .ToList(); - if (list2fix.Any()) - { - // per ogni record processo intera validazione - foreach (var item in list2fix) - { - bool fatto = await OrderRowUpsertProdEst(item.OrderRowUID, item.ProdEstimate); - numDone += fatto ? 1 : 0; - } - } - return numDone; - } - /// /// Effettua update stato await BOM/PRICE per l'Ordine indicato /// @@ -850,6 +825,8 @@ namespace EgwCoreLib.Lux.Data.Controllers return answ; } +#endif + /// /// Add record del solo ProdEstimate /// @@ -1019,8 +996,31 @@ namespace EgwCoreLib.Lux.Data.Controllers } return answ; } -#endif + /// + /// Validazione record: + /// - controllo state vs estimate + /// - segnala il numero dei record aggiornati + /// + /// Elenco record da verificare + internal async Task OrderRowListValidate(List list2chk) + { + int numDone = 0; + // verifica preliminare: serve SSE stato e estimate non corrispondono... + var list2fix = list2chk + .Where(x => x.OrderRowState == OrderStates.Created && !string.IsNullOrEmpty(x.ProdEstimate)) + .ToList(); + if (list2fix.Any()) + { + // per ogni record processo intera validazione + foreach (var item in list2fix) + { + bool fatto = await OrderRowUpsertProdEst(item.OrderRowUID, item.ProdEstimate); + numDone += fatto ? 1 : 0; + } + } + return numDone; + } /// /// Elenco record Fasi da DB diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/IOrderRowRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/IOrderRowRepository.cs index 1d34126c..a5fe46c0 100644 --- a/EgwCoreLib.Lux.Data/Repository/Sales/IOrderRowRepository.cs +++ b/EgwCoreLib.Lux.Data/Repository/Sales/IOrderRowRepository.cs @@ -1,5 +1,6 @@ using EgwCoreLib.Lux.Data.DbModel.Items; using EgwCoreLib.Lux.Data.DbModel.Sales; +using static EgwCoreLib.Lux.Core.Enums; namespace EgwCoreLib.Lux.Data.Repository.Sales { @@ -17,6 +18,10 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales Task> GetByParentAsync(int offerId); + Task> GetByStateAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd); + + Task> GetByStateMinAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd); + Task GetByUidAsync(string OrderRowUid); Task> GetItemGroupsAsync(); @@ -27,4 +32,4 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales #endregion Public Methods } -} +} \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/OrderRowRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/OrderRowRepository.cs index ad266acf..9e668842 100644 --- a/EgwCoreLib.Lux.Data/Repository/Sales/OrderRowRepository.cs +++ b/EgwCoreLib.Lux.Data/Repository/Sales/OrderRowRepository.cs @@ -94,6 +94,26 @@ namespace EgwCoreLib.Lux.Data.Repository.Sales .ToListAsync(); } + public async Task> GetByStateAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetOrderRow + .Where(x => x.OrderRowState == reqState && x.Inserted >= dtStart && x.Inserted <= dtEnd) + .Include(r => r.SellingItemNav) + .AsNoTracking() + .ToListAsync(); + } + + public async Task> GetByStateMinAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetOrderRow + .Where(x => x.OrderRowState >= reqState && x.Inserted >= dtStart && x.Inserted <= dtEnd) + .Include(r => r.SellingItemNav) + .AsNoTracking() + .ToListAsync(); + } + public async Task GetByUidAsync(string OrderRowUid) { await using var dbCtx = await CreateContextAsync(); diff --git a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs index bbe8a74c..694330a6 100644 --- a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs +++ b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs @@ -405,7 +405,6 @@ namespace EgwCoreLib.Lux.Data.Services LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); return answ; } -#endif /// /// Elenco righe Ordine specificato @@ -543,27 +542,6 @@ namespace EgwCoreLib.Lux.Data.Services return result; } - /// - /// Validazione record: - /// - controllo state vs estimate - /// - segnala il numero dei record aggiornati - /// - /// Elenco record da verificare - public async Task OrderRowListValidate(List list2chk) - { - using var activity = StartActivity(); - string source = "DB+REDIS"; - // calcolo - int numDone = await dbController.OrderRowListValidate(list2chk); - // svuoto cache... - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*"); - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*"); - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*"); - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return numDone; - } - /// /// Effettua update stato await BOM/PRICE per la riga Ordine indicata /// @@ -643,6 +621,49 @@ namespace EgwCoreLib.Lux.Data.Services return fatto; } + /// + /// Effettua Add della riga Ordine + /// + /// Riga Ordine con i dati da aggiornare + /// + public async Task OrderRowUpsert(OrderRowModel updRec) + { + using var activity = StartActivity(); + string source = "DB+REDIS"; + // calcolo + bool fatto = await dbController.OrderRowUpsert(updRec); + // svuoto cache... + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*"); + activity?.SetTag("data.source", source); + LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); + return fatto; + } + +#endif + /// + /// Validazione record: + /// - controllo state vs estimate + /// - segnala il numero dei record aggiornati + /// + /// Elenco record da verificare + public async Task OrderRowListValidate(List list2chk) + { + using var activity = StartActivity(); + string source = "DB+REDIS"; + // calcolo + int numDone = await dbController.OrderRowListValidate(list2chk); + // svuoto cache... + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*"); + activity?.SetTag("data.source", source); + LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); + return numDone; + } + + /// /// Aggiorna stato riga ordine al valore richiesto /// @@ -664,25 +685,6 @@ namespace EgwCoreLib.Lux.Data.Services return fatto; } - /// - /// Effettua Add della riga Ordine - /// - /// Riga Ordine con i dati da aggiornare - /// - public async Task OrderRowUpsert(OrderRowModel updRec) - { - using var activity = StartActivity(); - string source = "DB+REDIS"; - // calcolo - bool fatto = await dbController.OrderRowUpsert(updRec); - // svuoto cache... - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Orders:*"); - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRows:*"); - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OrderRowsByState:*"); - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return fatto; - } /// /// Elenco completo Fasi diff --git a/EgwCoreLib.Lux.Data/Services/Sales/IOrderRowService.cs b/EgwCoreLib.Lux.Data/Services/Sales/IOrderRowService.cs index 94d29003..5bc591d0 100644 --- a/EgwCoreLib.Lux.Data/Services/Sales/IOrderRowService.cs +++ b/EgwCoreLib.Lux.Data/Services/Sales/IOrderRowService.cs @@ -1,5 +1,6 @@ using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Sales; +using static EgwCoreLib.Lux.Core.Enums; namespace EgwCoreLib.Lux.Data.Services.Sales { @@ -17,6 +18,10 @@ namespace EgwCoreLib.Lux.Data.Services.Sales Task> GetByParentAsync(int OrderId); + Task> GetByStateAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd); + + Task> GetByStateMinAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd); + Task GetByUidAsync(string OrderRowUid); Task UpdateAwaitStateAsync(int OrderRowId, bool? awaitBom, bool? awaitPrice, bool flushCache = false); @@ -27,6 +32,8 @@ namespace EgwCoreLib.Lux.Data.Services.Sales Task UpdateSerStructAsync(int OrderRowID, string serStruct); + Task OrderRowUpdateState(int orderRowID, OrderStates reqState); + Task UpsertAsync(OrderRowModel upsRec); #endregion Public Methods diff --git a/EgwCoreLib.Lux.Data/Services/Sales/OrderRowService.cs b/EgwCoreLib.Lux.Data/Services/Sales/OrderRowService.cs index a58632bc..4a0d6ada 100644 --- a/EgwCoreLib.Lux.Data/Services/Sales/OrderRowService.cs +++ b/EgwCoreLib.Lux.Data/Services/Sales/OrderRowService.cs @@ -171,6 +171,44 @@ namespace EgwCoreLib.Lux.Data.Services.Sales }); } + /// + /// Elenco filtrato per stato + /// + /// + /// + /// + /// + public async Task> GetByStateAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd) + { + return await TraceAsync($"{_className}.GetByState", async (activity) => + { + return await GetOrSetCacheAsync( + $"{_redisBaseKey}:{_className}:ByState:{reqState}:{dtStart:yyyy-MM-dd}:{dtEnd:yyyy-MM-dd}", + async () => await _repo.GetByStateAsync(reqState, dtStart, dtEnd), + LongCache + ); + }); + } + + /// + /// Elenco filtrato per stato min o superiori + /// + /// + /// + /// + /// + public async Task> GetByStateMinAsync(OrderStates reqState, DateTime dtStart, DateTime dtEnd) + { + return await TraceAsync($"{_className}.GetByStateMin", async (activity) => + { + return await GetOrSetCacheAsync( + $"{_redisBaseKey}:{_className}:ByStateMin:{reqState}:{dtStart:yyyy-MM-dd}:{dtEnd:yyyy-MM-dd}", + async () => await _repo.GetByStateMinAsync(reqState, dtStart, dtEnd), + LongCache + ); + }); + } + public async Task GetByUidAsync(string OrderRowUid) { return await TraceAsync($"{_className}.GetByUid", async (activity) => @@ -323,6 +361,37 @@ namespace EgwCoreLib.Lux.Data.Services.Sales }); } + /// + /// Effettua update dello stato della Riga Order + /// + /// ID Riga Order da aggiornare + /// Serializzazione oggetto (es JWD) + /// + public async Task OrderRowUpdateState(int orderRowID, OrderStates reqState) + { + return await TraceAsync($"{_className}.UpdateSerStruct", async (activity) => + { + var currRec = await _repo.GetByIdAsync(orderRowID); + + if (currRec == null) + return false; + + currRec.OrderRowState = reqState; + + activity?.SetTag("db.operation", "UPDATE"); + + bool success = await _repo.UpdateAsync(currRec); + + if (success) + { + await ClearCacheAsync($"{_redisBaseKey}:Order:*"); + await ClearCacheAsync($"{_redisBaseKey}:{_className}:*"); + } + + return success; + }); + } + /// /// Upsert record OrderRow ///