From c865420e951e8692939b4be660aeb9af39b8ea5d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 24 Apr 2026 17:42:49 +0200 Subject: [PATCH] Aggiunti repository + servizi x reports in LUX UI --- EgwCoreLib.Lux.Data/DataLayerContext.cs | 4 +- EgwCoreLib.Lux.Data/GlobalUsings.cs | 1 + EgwCoreLib.Lux.Data/ReportContext.cs | 80 +++++++++++++++++++ .../Repository/Report/BaseRepRepository.cs | 31 +++++++ .../Repository/Report/IBaseRepRepository.cs | 10 +++ .../Repository/Report/IReportRepository.cs | 32 ++++++++ .../Repository/Report/ReportRepository.cs | 64 +++++++++++++++ .../Services/Report/IReportService.cs | 24 ++++++ .../Services/Report/ReportService.cs | 74 +++++++++++++++++ Lux.API/Lux.API.csproj | 2 +- ...BaseRepository.cs => BaseRepRepository.cs} | 4 +- ...aseRepository.cs => IBaseRepRepository.cs} | 2 +- .../Repository/ReportRepository.cs | 2 +- Lux.Report.Manager/Lux.Report.Manager.csproj | 2 +- Lux.Report.Server/Lux.Report.Server.csproj | 2 +- Lux.UI/Lux.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 19 files changed, 328 insertions(+), 14 deletions(-) create mode 100644 EgwCoreLib.Lux.Data/ReportContext.cs create mode 100644 EgwCoreLib.Lux.Data/Repository/Report/BaseRepRepository.cs create mode 100644 EgwCoreLib.Lux.Data/Repository/Report/IBaseRepRepository.cs create mode 100644 EgwCoreLib.Lux.Data/Repository/Report/IReportRepository.cs create mode 100644 EgwCoreLib.Lux.Data/Repository/Report/ReportRepository.cs create mode 100644 EgwCoreLib.Lux.Data/Services/Report/IReportService.cs create mode 100644 EgwCoreLib.Lux.Data/Services/Report/ReportService.cs rename Lux.Report.Data/Repository/{BaseRepository.cs => BaseRepRepository.cs} (82%) rename Lux.Report.Data/Repository/{IBaseRepository.cs => IBaseRepRepository.cs} (81%) diff --git a/EgwCoreLib.Lux.Data/DataLayerContext.cs b/EgwCoreLib.Lux.Data/DataLayerContext.cs index 8f09ae6..b003879 100644 --- a/EgwCoreLib.Lux.Data/DataLayerContext.cs +++ b/EgwCoreLib.Lux.Data/DataLayerContext.cs @@ -1,6 +1,4 @@ -using EgwCoreLib.Lux.Data.DbModel.Warehouse; - -namespace EgwCoreLib.Lux.Data +namespace EgwCoreLib.Lux.Data { public partial class DataLayerContext : DbContext { diff --git a/EgwCoreLib.Lux.Data/GlobalUsings.cs b/EgwCoreLib.Lux.Data/GlobalUsings.cs index d596109..d59b12e 100644 --- a/EgwCoreLib.Lux.Data/GlobalUsings.cs +++ b/EgwCoreLib.Lux.Data/GlobalUsings.cs @@ -7,6 +7,7 @@ global using EgwCoreLib.Lux.Data.DbModel.Cost; global using EgwCoreLib.Lux.Data.DbModel.Items; global using EgwCoreLib.Lux.Data.DbModel.Job; global using EgwCoreLib.Lux.Data.DbModel.Production; +global using EgwCoreLib.Lux.Data.DbModel.Report; global using EgwCoreLib.Lux.Data.DbModel.Sales; global using EgwCoreLib.Lux.Data.DbModel.Stats; global using EgwCoreLib.Lux.Data.DbModel.Stock; diff --git a/EgwCoreLib.Lux.Data/ReportContext.cs b/EgwCoreLib.Lux.Data/ReportContext.cs new file mode 100644 index 0000000..7f6acd1 --- /dev/null +++ b/EgwCoreLib.Lux.Data/ReportContext.cs @@ -0,0 +1,80 @@ +namespace EgwCoreLib.Lux.Data +{ + public partial class ReportContext : DbContext + { + private static Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfiguration _configuration; + + public ReportContext() + { + } + +#if false + public ReportContext(IConfiguration configuration) + { + _configuration = configuration; + } +#endif + public ReportContext(DbContextOptions options) : base(options) + { + try + { + // se non ci fosse... crea o migra! + Database.Migrate(); + } + catch (Exception exc) + { + Log.Error(exc, "Exception during context initialization 02"); + } + } + + public virtual DbSet DbSetReports { get; set; } + + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + // default + string connString = DbConfig.CONNECTION_STRING; + if (string.IsNullOrEmpty(connString)) + { +#if DEBUG + connString = "Server=mdb.ufficio;port=3306;database=Lux_000;uid=lux_user;pwd=Egal_pwd!;sslmode=None;"; + //connString = "Server=mdb.ufficio;port=3306;database=Lux_000_dev;uid=lux_user;pwd=Egal_pwd!;sslmode=None;"; +#else + connString = "Server=mdb.ufficio;port=3306;database=Lux_000;uid=lux_user;pwd=Egal_pwd!;sslmode=None;"; +#endif + } + if (!optionsBuilder.IsConfigured) + { + var serverVersion = ServerVersion.AutoDetect(connString); + + // 2026.01.09 aggiornata init componente POMELO +#if false + optionsBuilder.UseMySql(connString, serverVersion); +#endif + optionsBuilder.UseMySql(connString, serverVersion, options => + { + // Questo abilita il supporto JSON specifico per MySQL + options.EnableStringComparisonTranslations(); + }); + // verificare setup componente +#if false + optionsBuilder + .UseMySql(connString, serverVersion) + .UseSnakeCaseNamingConvention(); // via EFCore.NamingConventions +#endif + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys())) + { + relationship.DeleteBehavior = DeleteBehavior.Restrict; + } + } + } +} diff --git a/EgwCoreLib.Lux.Data/Repository/Report/BaseRepRepository.cs b/EgwCoreLib.Lux.Data/Repository/Report/BaseRepRepository.cs new file mode 100644 index 0000000..4d13b22 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Report/BaseRepRepository.cs @@ -0,0 +1,31 @@ + + +namespace EgwCoreLib.Lux.Data.Repository.Report +{ + public abstract class BaseRepRepository : IBaseRepRepository + { + #region Protected Fields + + protected readonly IDbContextFactory _ctxFactory; + + #endregion Protected Fields + + #region Protected Constructors + + protected BaseRepRepository(IDbContextFactory ctxFactory) + => _ctxFactory = ctxFactory; + + #endregion Protected Constructors + + #region Protected Methods + + /// + /// Creazione dbcontext per singola transazione + /// + /// + protected async Task CreateContextAsync() + => await _ctxFactory.CreateDbContextAsync(); + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Repository/Report/IBaseRepRepository.cs b/EgwCoreLib.Lux.Data/Repository/Report/IBaseRepRepository.cs new file mode 100644 index 0000000..13a3d71 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Report/IBaseRepRepository.cs @@ -0,0 +1,10 @@ + + +namespace EgwCoreLib.Lux.Data.Repository.Report +{ + public interface IBaseRepRepository + { + //Task CreateContextAsync(); + //Task SaveChangesAsync(DataLayerContext ctx); + } +} diff --git a/EgwCoreLib.Lux.Data/Repository/Report/IReportRepository.cs b/EgwCoreLib.Lux.Data/Repository/Report/IReportRepository.cs new file mode 100644 index 0000000..5573721 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Report/IReportRepository.cs @@ -0,0 +1,32 @@ +namespace EgwCoreLib.Lux.Data.Repository.Report +{ + public interface IReportRepository + { + #region Public Methods + + /// + /// Inserisce un nuovo record Report nel database. + /// + /// Record da inserire + Task AddAsync(ReportModel entity); + + /// + /// Recupera l'elenco completo dei Report + /// + Task> GetAllAsync(); + + /// + /// Recupera un Report specifico per ID. + /// + /// ID da recuperare + Task GetByIdAsync(int currID); + + /// + /// Aggiorna un record Report esistente nel database. + /// + /// Record aggiornato + Task UpdateAsync(ReportModel entity); + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Repository/Report/ReportRepository.cs b/EgwCoreLib.Lux.Data/Repository/Report/ReportRepository.cs new file mode 100644 index 0000000..29403a8 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Repository/Report/ReportRepository.cs @@ -0,0 +1,64 @@ +namespace EgwCoreLib.Lux.Data.Repository.Report +{ + public class ReportRepository : BaseRepRepository, IReportRepository + { + #region Public Constructors + + public ReportRepository(IDbContextFactory ctxFactory) : base(ctxFactory) + { + } + + #endregion Public Constructors + + #region Public Methods + + /// + public async Task AddAsync(ReportModel entity) + { + await using var dbCtx = await CreateContextAsync(); + // per ora disabilito salvataggio effettivo in prod +#if DEBUG + await dbCtx.DbSetReports.AddAsync(entity); +#endif + return await dbCtx.SaveChangesAsync() > 0; + } + + /// + public async Task> GetAllAsync() + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetReports + .AsNoTracking() + .ToListAsync(); + } + + /// + public async Task GetByIdAsync(int currID) + { + await using var dbCtx = await CreateContextAsync(); + return await dbCtx.DbSetReports.FirstOrDefaultAsync(x => x.ReportID == currID); + } + + + /// + public async Task UpdateAsync(ReportModel entity) + { + await using var dbCtx = await CreateContextAsync(); + // Recuperiamo l'entità tracciata dal context + var trackedEntity = await dbCtx.DbSetReports.FirstOrDefaultAsync(x => x.ReportID == entity.ReportID); + + if (trackedEntity != null) + { + // Aggiorna i valori dell'entità tracciata con quelli della nuova + dbCtx.Entry(trackedEntity).CurrentValues.SetValues(entity); + } + else + { + dbCtx.DbSetReports.Update(entity); + } + return await dbCtx.SaveChangesAsync() > 0; + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Services/Report/IReportService.cs b/EgwCoreLib.Lux.Data/Services/Report/IReportService.cs new file mode 100644 index 0000000..430c60a --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Report/IReportService.cs @@ -0,0 +1,24 @@ +namespace EgwCoreLib.Lux.Data.Services.Report +{ + public interface IReportService + { + #region Public Methods + + + /// + /// Elenco completo Report da DB + /// + /// + Task> GetAllAsync(); + + + /// + /// Upsert record Report + /// + /// + /// + Task UpsertAsync(ReportModel upsRec); + + #endregion Public Methods + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Report/ReportService.cs b/EgwCoreLib.Lux.Data/Services/Report/ReportService.cs new file mode 100644 index 0000000..a65a607 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Report/ReportService.cs @@ -0,0 +1,74 @@ +using EgwCoreLib.Lux.Data.Repository.Report; + +namespace EgwCoreLib.Lux.Data.Services.Report +{ + public class ReportService : BaseServ, IReportService + { + #region Public Constructors + + public ReportService( + IConfiguration config, + IConnectionMultiplexer redis, + IReportRepository repo) : base(config, redis) + { + _className = "Report"; + _repo = repo; + } + + #endregion Public Constructors + + #region Public Methods + + /// + public async Task> GetAllAsync() + { + // Uso helper TraceAsync che gestisce automaticamente StartActivity, Log e Exception tracking + return await TraceAsync($"{_className}.GetAll", async (activity) => + { + return await GetOrSetCacheAsync( + $"{_redisBaseKey}:{_className}:ALL", + async () => await _repo.GetAllAsync() + ); + }); + } + + /// + public async Task UpsertAsync(ReportModel upsRec) + { + return await TraceAsync($"{_className}.Upsert", async (activity) => + { + var currRec = await _repo.GetByIdAsync(upsRec.ReportID); + + 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 + + #region Private Fields + + private readonly string _className; + private readonly IReportRepository _repo; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/Lux.API/Lux.API.csproj b/Lux.API/Lux.API.csproj index 3281cef..388af9c 100644 --- a/Lux.API/Lux.API.csproj +++ b/Lux.API/Lux.API.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 1.1.2604.2416 + 1.1.2604.2417 diff --git a/Lux.Report.Data/Repository/BaseRepository.cs b/Lux.Report.Data/Repository/BaseRepRepository.cs similarity index 82% rename from Lux.Report.Data/Repository/BaseRepository.cs rename to Lux.Report.Data/Repository/BaseRepRepository.cs index d23c464..7906e4a 100644 --- a/Lux.Report.Data/Repository/BaseRepository.cs +++ b/Lux.Report.Data/Repository/BaseRepRepository.cs @@ -2,7 +2,7 @@ namespace Lux.Report.Data.Repository { - public abstract class BaseRepository : IBaseRepository + public abstract class BaseRepRepository : IBaseRepRepository { #region Protected Fields @@ -12,7 +12,7 @@ namespace Lux.Report.Data.Repository #region Protected Constructors - protected BaseRepository(IDbContextFactory ctxFactory) + protected BaseRepRepository(IDbContextFactory ctxFactory) => _ctxFactory = ctxFactory; #endregion Protected Constructors diff --git a/Lux.Report.Data/Repository/IBaseRepository.cs b/Lux.Report.Data/Repository/IBaseRepRepository.cs similarity index 81% rename from Lux.Report.Data/Repository/IBaseRepository.cs rename to Lux.Report.Data/Repository/IBaseRepRepository.cs index da9c9b1..295d461 100644 --- a/Lux.Report.Data/Repository/IBaseRepository.cs +++ b/Lux.Report.Data/Repository/IBaseRepRepository.cs @@ -2,7 +2,7 @@ namespace Lux.Report.Data.Repository { - public interface IBaseRepository + public interface IBaseRepRepository { //Task CreateContextAsync(); //Task SaveChangesAsync(DataLayerContext ctx); diff --git a/Lux.Report.Data/Repository/ReportRepository.cs b/Lux.Report.Data/Repository/ReportRepository.cs index fd95814..3a5ea4d 100644 --- a/Lux.Report.Data/Repository/ReportRepository.cs +++ b/Lux.Report.Data/Repository/ReportRepository.cs @@ -2,7 +2,7 @@ namespace Lux.Report.Data.Repository { - public class ReportRepository : BaseRepository, IReportRepository + public class ReportRepository : BaseRepRepository, IReportRepository { #region Public Constructors diff --git a/Lux.Report.Manager/Lux.Report.Manager.csproj b/Lux.Report.Manager/Lux.Report.Manager.csproj index 4ebccc1..05755db 100644 --- a/Lux.Report.Manager/Lux.Report.Manager.csproj +++ b/Lux.Report.Manager/Lux.Report.Manager.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 1.1.2604.2416 + 1.1.2604.2417 diff --git a/Lux.Report.Server/Lux.Report.Server.csproj b/Lux.Report.Server/Lux.Report.Server.csproj index 1ad8dd9..010813d 100644 --- a/Lux.Report.Server/Lux.Report.Server.csproj +++ b/Lux.Report.Server/Lux.Report.Server.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 1.1.2604.2416 + 1.1.2604.2417 diff --git a/Lux.UI/Lux.UI.csproj b/Lux.UI/Lux.UI.csproj index 8455d78..b012201 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.2604.2416 + 1.1.2604.2417 diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 26e5d94..81f2d48 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ LUX - Web Windows MES -

Versione: 1.1.2604.2416

+

Versione: 1.1.2604.2417


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 879569a..89a2656 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2604.2416 +1.1.2604.2417 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index ce5734e..88ff86d 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2604.2416 + 1.1.2604.2417 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false