diff --git a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs index 89e9b17c..68df2636 100644 --- a/EgwCoreLib.Lux.Data/Controllers/LuxController.cs +++ b/EgwCoreLib.Lux.Data/Controllers/LuxController.cs @@ -294,6 +294,43 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } + internal async Task OffersCheckExpired() + { + bool answ = false; + //using (DataLayerContext dbCtx = new DataLayerContext(_config)) + using (DataLayerContext dbCtx = new DataLayerContext()) + { + try + { + DateTime adesso = DateTime.Now; + // recupero offerta... + var listExpired = dbCtx + .DbSetOffer + .Where(x => x.ValidUntil < adesso && x.OffertState == OfferStates.Open) + .ToList(); + + // se trovo le aggiorno come stato + if (listExpired != null) + { + foreach (var item in listExpired) + { + item.OffertState = OfferStates.Expired; + dbCtx.Entry(item).State = EntityState.Modified; + } + // salvo TUTTI i cambiamenti... + var result = await dbCtx.SaveChangesAsync(); + answ = result > 0; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione durante OffersCheckExpired{Environment.NewLine}{exc}"); + } + } + return answ; + } + +#if true /// /// Recupera da DB riga offerta dato Primary ID /// @@ -367,41 +404,6 @@ namespace EgwCoreLib.Lux.Data.Controllers return dbResult; } - internal async Task OffersCheckExpired() - { - bool answ = false; - //using (DataLayerContext dbCtx = new DataLayerContext(_config)) - using (DataLayerContext dbCtx = new DataLayerContext()) - { - try - { - DateTime adesso = DateTime.Now; - // recupero offerta... - var listExpired = dbCtx - .DbSetOffer - .Where(x => x.ValidUntil < adesso && x.OffertState == OfferStates.Open) - .ToList(); - - // se trovo le aggiorno come stato - if (listExpired != null) - { - foreach (var item in listExpired) - { - item.OffertState = OfferStates.Expired; - dbCtx.Entry(item).State = EntityState.Modified; - } - // salvo TUTTI i cambiamenti... - var result = await dbCtx.SaveChangesAsync(); - answ = result > 0; - } - } - catch (Exception exc) - { - Log.Error($"Eccezione durante OffersCheckExpired{Environment.NewLine}{exc}"); - } - } - return answ; - } /// Elimina riga e sposta eventuali righe successive... /// @@ -765,6 +767,7 @@ namespace EgwCoreLib.Lux.Data.Controllers } return answ; } +#endif /// /// Esegue upsert del record offerta data la BOM ricevuta diff --git a/EgwCoreLib.Lux.Data/Domains/BomCalculator.cs b/EgwCoreLib.Lux.Data/Domains/BomCalculator.cs index 94da6569..d3682315 100644 --- a/EgwCoreLib.Lux.Data/Domains/BomCalculator.cs +++ b/EgwCoreLib.Lux.Data/Domains/BomCalculator.cs @@ -1,5 +1,6 @@ using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Items; +using Newtonsoft.Json; namespace EgwCoreLib.Lux.Data.Domains { @@ -7,6 +8,20 @@ namespace EgwCoreLib.Lux.Data.Domains { #region Public Methods + public static List GetBomList(string itemBOM) + { + List answ = new List(); + if (!string.IsNullOrEmpty(itemBOM) && itemBOM.Length > 2) + { + var bomList = JsonConvert.DeserializeObject>(itemBOM); + if (bomList != null) + { + answ = bomList; + } + } + return answ; + } + /// /// Esegue completamento e la validazione dei dati BOM da lista articoli + gruppi, /// validando i dati stessi diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/IOfferRowRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/IOfferRowRepository.cs new file mode 100644 index 00000000..c33c1c7e --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Sales/IOfferRowRepository.cs @@ -0,0 +1,26 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; + +namespace EgwCoreLib.Lux.Data.Repository.Sales +{ + public interface IOfferRowRepository : IBaseRepository + { + #region Public Methods + + Task AddAsync(OfferRowModel entity); + + Task DeleteAsync(OfferRowModel entity); + + Task GetByUidAsync(string offerRowUid); + + Task GetByIdAsync(int offerRowId); + + Task> GetByParentAsync(int offerId); + + Task SaveRowsAsync(List rows); + + Task UpdateAsync(OfferRowModel entity); + + + #endregion Public Methods + } +} diff --git a/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs b/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs new file mode 100644 index 00000000..421f2cd6 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Sales/OfferRowRepository.cs @@ -0,0 +1,89 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; +using Microsoft.EntityFrameworkCore; + +namespace EgwCoreLib.Lux.Data.Repository.Sales +{ + public class OfferRowRepository : BaseRepository, IOfferRowRepository + { + #region Public Constructors + + public OfferRowRepository(IDbContextFactory ctxFactory) : base(ctxFactory) + { + } + + #endregion Public Constructors + + #region Public Methods + + public async Task AddAsync(OfferRowModel entity) + { + await using var dbCtx = await CreateContextAsync(); + await dbCtx.DbSetOfferRow.AddAsync(entity); + return await dbCtx.SaveChangesAsync() > 0; + } + + + public async Task DeleteAsync(OfferRowModel entity) + { + await using var dbCtx = await CreateContextAsync(); + dbCtx.DbSetOfferRow.Remove(entity); + return await dbCtx.SaveChangesAsync() > 0; + } + + + public async Task GetByUidAsync(string offerRowUid) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetOfferRow + .Include(r => r.SellingItemNav) + .FirstOrDefaultAsync(x => x.OfferRowUID == offerRowUid); + } + + public async Task GetByIdAsync(int offerRowId) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetOfferRow + .Include(r => r.SellingItemNav) + .FirstOrDefaultAsync(x => x.OfferRowID == offerRowId); + } + + + public async Task> GetByParentAsync(int offerId) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetOfferRow + .Where(x => x.OfferID == offerId) + .Include(r => r.SellingItemNav) + .ToListAsync(); + } + + public async Task SaveRowsAsync(List rows) + { + await using var dbCtx = await CreateContextAsync(); + foreach (var row in rows) + dbCtx.Entry(row).State = EntityState.Modified; + + return await dbCtx.SaveChangesAsync() > 0; + } + + public async Task UpdateAsync(OfferRowModel entity) + { + await using var dbCtx = await CreateContextAsync(); + // Recuperiamo l'entità tracciata dal context + var trackedEntity = dbCtx.DbSetOfferRow.Local.FirstOrDefault(x => x.OfferRowID == entity.OfferRowID); + + if (trackedEntity != null) + { + // Aggiorna i valori dell'entità tracciata con quelli della nuova + dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity); + } + else + { + dbCtx.DbSetOfferRow.Update(entity); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + #endregion Public Methods + } +} diff --git a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs index eaff53e1..f8446c08 100644 --- a/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs +++ b/EgwCoreLib.Lux.Data/Services/DataLayerServices.cs @@ -316,6 +316,23 @@ namespace EgwCoreLib.Lux.Data.Services return result; } +#if true + ///// + ///// Converte il campo raw della BOM in lista oggetti da gestire + ///// + ///// + ///// + //public List OffertGetBomList(OfferRowModel currRec) + //{ + // List answ = new List(); + // var bomList = JsonConvert.DeserializeObject>(currRec.ItemBOM); + // if (bomList != null) + // { + // answ = bomList; + // } + // return answ; + //} + /// /// Elenco righe offerta specificata /// @@ -382,39 +399,6 @@ namespace EgwCoreLib.Lux.Data.Services return result; } - /// - /// Verifica offerte scadute, con update sul DB - /// - public async Task OffersCheckExpired() - { - using var activity = StartActivity(); - string source = "DB+REDIS"; - // calcolo - bool fatto = await dbController.OffersCheckExpired(); - // svuoto cache... - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*"); - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*"); - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return fatto; - } - - /// - /// Converte il campo raw della BOM in lista oggetti da gestire - /// - /// - /// - public List OffertGetBomList(OfferRowModel currRec) - { - List answ = new List(); - var bomList = JsonConvert.DeserializeObject>(currRec.ItemBOM); - if (bomList != null) - { - answ = bomList; - } - return answ; - } - /// /// Effettua eliminazione della Riga Offerta /// @@ -434,41 +418,6 @@ namespace EgwCoreLib.Lux.Data.Services return fatto; } - /// - /// Effettua fix UID righe child dell'offerta indicata e restituisce elenco UID da chiamare x refresh - /// - /// Key - /// - public async Task> OffertRowFixUid(int OffertID) - { - using var activity = StartActivity(); - string source = "DB+REDIS"; - List answ = new List(); - try - { - // calcolo - answ = await dbController.OffertRowFixUidAsync(OffertID); - // svuoto cache... - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*"); - await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*"); - } - catch (Exception exc) - { - string exMsg = $"Eccezione durante OffertRowFixUidAsync"; - LogTrace($"{exMsg}{Environment.NewLine}{exc}", LogLevel.Error); - // traccio errore - activity?.SetStatus(ActivityStatusCode.Error, exc.Message); - activity?.AddEvent(new ActivityEvent("exception", tags: new ActivityTagsCollection { - { "exception.type", exc.GetType().Name }, - { "exception.message", exc.Message }, - { "exception.stacktrace", exc.StackTrace } - })); - } - activity?.SetTag("data.source", source); - LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); - return answ; - } - /// /// Aggiornamento valore UID non calcolato + ritorno elenco UID da aggiornare /// @@ -504,6 +453,40 @@ namespace EgwCoreLib.Lux.Data.Services return answ; } + /// + /// Effettua fix UID righe child dell'offerta indicata e restituisce elenco UID da chiamare x refresh + /// + /// Key + /// + public async Task> OffertRowFixUid(int OffertID) + { + using var activity = StartActivity(); + string source = "DB+REDIS"; + List answ = new List(); + try + { + // calcolo + answ = await dbController.OffertRowFixUidAsync(OffertID); + // svuoto cache... + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*"); + } + catch (Exception exc) + { + string exMsg = $"Eccezione durante OffertRowFixUidAsync"; + LogTrace($"{exMsg}{Environment.NewLine}{exc}", LogLevel.Error); + // traccio errore + activity?.SetStatus(ActivityStatusCode.Error, exc.Message); + activity?.AddEvent(new ActivityEvent("exception", tags: new ActivityTagsCollection { + { "exception.type", exc.GetType().Name }, + { "exception.message", exc.Message }, + { "exception.stacktrace", exc.StackTrace } + })); + } + activity?.SetTag("data.source", source); + LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); + return answ; + } /// /// Effettua update stato await BOM/PRICE per l'offerta indicata @@ -650,6 +633,25 @@ namespace EgwCoreLib.Lux.Data.Services return dbResult; } +#endif + + /// + /// Verifica offerte scadute, con update sul DB + /// + public async Task OffersCheckExpired() + { + using var activity = StartActivity(); + string source = "DB+REDIS"; + // calcolo + bool fatto = await dbController.OffersCheckExpired(); + // svuoto cache... + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:Offers:*"); + await ExecFlushRedisPatternAsync((RedisValue)$"{redisBaseKey}:OfferRows:*"); + activity?.SetTag("data.source", source); + LogTrace($"{source} | trace: {activity?.TraceId} | {activity?.Duration.TotalMilliseconds}ms"); + return fatto; + } + /// /// Converte il campo raw della BOM in lista oggetti da gestire /// @@ -970,7 +972,6 @@ namespace EgwCoreLib.Lux.Data.Services return fatto; } - /// /// Elenco completo Fasi /// @@ -1649,20 +1650,6 @@ namespace EgwCoreLib.Lux.Data.Services activity?.SetTag("host.name", Environment.MachineName); return activity; } - /// - /// Helper trace messaggio log (SE abilitato) - /// - /// - protected new void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null, [CallerMemberName] string? methodName = null) - { - if (!_traceEnabled) - return; - - reqLevel ??= NLog.LogLevel.Debug; - - // Loggo! - Log.Log(reqLevel, $"{methodName} | {traceMsg}"); - } /// /// Esegue flush memoria redis dato pat2Flush @@ -1824,6 +1811,21 @@ namespace EgwCoreLib.Lux.Data.Services return answ; } + /// + /// Helper trace messaggio log (SE abilitato) + /// + /// + protected new void LogTrace(string traceMsg, NLog.LogLevel? reqLevel = null, [CallerMemberName] string? methodName = null) + { + if (!_traceEnabled) + return; + + reqLevel ??= NLog.LogLevel.Debug; + + // Loggo! + Log.Log(reqLevel, $"{methodName} | {traceMsg}"); + } + #endregion Protected Methods #region Private Fields diff --git a/EgwCoreLib.Lux.Data/Services/Sales/IOfferRowService.cs b/EgwCoreLib.Lux.Data/Services/Sales/IOfferRowService.cs new file mode 100644 index 00000000..8806562e --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Sales/IOfferRowService.cs @@ -0,0 +1,29 @@ +using EgwCoreLib.Lux.Data.DbModel.Sales; + +namespace EgwCoreLib.Lux.Data.Services.Sales +{ + public interface IOfferRowService + { + #region Public Methods + + Task CloneAsync(OfferRowModel rec2clone); + + Task DeleteAsync(OfferRowModel model); + + Task> FixRowUidAsync(int OfferId); + + Task> GetAllAsync(); + + Task> GetByParentAsync(int OfferId); + + Task UpdateAwaitStateAsync(int OfferRowId, bool? awaitBom, bool? awaitPrice, bool flushCache = false); + + Task UpdateFileDataAsync(OfferRowModel updRec); + + Task UpdateSerStructAsync(int OfferRowID, string serStruct); + + Task UpsertAsync(OfferRowModel upsRec); + + #endregion Public Methods + } +} diff --git a/Lux.API/Lux.API.csproj b/Lux.API/Lux.API.csproj index 073371b6..2e7592c9 100644 --- a/Lux.API/Lux.API.csproj +++ b/Lux.API/Lux.API.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 1.1.2603.1717 + 1.1.2603.1718 diff --git a/Lux.UI/Components/Compo/OfferRowMan.razor.cs b/Lux.UI/Components/Compo/OfferRowMan.razor.cs index 3a99ae39..90937140 100644 --- a/Lux.UI/Components/Compo/OfferRowMan.razor.cs +++ b/Lux.UI/Components/Compo/OfferRowMan.razor.cs @@ -5,6 +5,7 @@ using EgwCoreLib.Lux.Data.DbModel.Catalog; using EgwCoreLib.Lux.Data.DbModel.Config; using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.DbModel.Utils; +using EgwCoreLib.Lux.Data.Domains; using EgwCoreLib.Lux.Data.Services; using EgwCoreLib.Lux.Data.Services.Config; using EgwCoreLib.Lux.Data.Services.Sales; @@ -1634,7 +1635,8 @@ namespace Lux.UI.Components.Compo private void selectBom(OfferRowModel currRow) { EditRecord = currRow; - CurrBomList = DLService.OffertGetBomList(EditRecord); + //CurrBomList = DLService.OffertGetBomList(EditRecord); + CurrBomList = BomCalculator.GetBomList(EditRecord.ItemBOM); if (CurrBomList.Any(x => x.ItemID == 0)) { CurrBomList = DLService.BomFixItemId(CurrBomList); diff --git a/Lux.UI/Lux.UI.csproj b/Lux.UI/Lux.UI.csproj index f53bfc4b..b86bd3d8 100644 --- a/Lux.UI/Lux.UI.csproj +++ b/Lux.UI/Lux.UI.csproj @@ -5,7 +5,7 @@ enable enable aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50 - 1.1.2603.1717 + 1.1.2603.1718 diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 7e9e8827..11569c64 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ LUX - Web Windows MES -

Versione: 1.1.2603.1717

+

Versione: 1.1.2603.1718


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 14d1dedc..a47d7f58 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2603.1717 +1.1.2603.1718 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 5d818c6e..0bfae75b 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2603.1717 + 1.1.2603.1718 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false