From d7e95de3cefca9d3788c561b3a4cccf3a7e445d2 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 28 Jan 2022 07:56:14 +0100 Subject: [PATCH] Filtro elenco gruppi dato utente (LIMITE selezione) --- GPW.CORE.Data/Controllers/GPWController.cs | 31 +++++++++++++-- GPW.CORE.Data/DbModels/AnagGruppiModel.cs | 10 ++--- .../DbModels/Dipendenti2GruppiModel.cs | 27 +++++++++++++ GPW.CORE.Data/GPWContext.cs | 13 +++++++ .../Components/FasiSearch.razor.cs | 2 +- .../Components/RegAttEditor.razor.cs | 2 +- GPW.CORE.WRKLOG/Data/GpwDataService.cs | 39 +++++++++++++++++++ 7 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 GPW.CORE.Data/DbModels/Dipendenti2GruppiModel.cs diff --git a/GPW.CORE.Data/Controllers/GPWController.cs b/GPW.CORE.Data/Controllers/GPWController.cs index 953eb50..3065d2c 100644 --- a/GPW.CORE.Data/Controllers/GPWController.cs +++ b/GPW.CORE.Data/Controllers/GPWController.cs @@ -97,10 +97,10 @@ namespace GPW.CORE.Data.Controllers try { // recupero intero set... - var dbResult = localDbCtx - .DbSetAnagFasi - .Where(x => x.IdxFase==idxFase) - .FirstOrDefault(); + var dbResult = localDbCtx + .DbSetAnagFasi + .Where(x => x.IdxFase == idxFase) + .FirstOrDefault(); if (dbResult != null) { dbResult.Attivo = isActive; @@ -139,6 +139,29 @@ namespace GPW.CORE.Data.Controllers return dbResult; } + public List AnagGruppiUser(int idxDipendente) + { + // init dati necessari + List dbResult = new List(); + // cerco su DB recuperando set di dati.... + using (GPWContext localDbCtx = new GPWContext(_configuration)) + { + try + { + // recupero intero set... + dbResult = localDbCtx + .DbSetAnagGruppi + .Where(x => x.Dipendenti2GruppiNav.Contains(new Dipendenti2GruppiModel() { IdxDipendente = idxDipendente, Gruppo = x.Gruppo })) + .ToList(); + } + catch (Exception exc) + { + Log.Error($"Errore in AnagGruppiUser:{Environment.NewLine}{exc}"); + } + } + return dbResult; + } + public List AnagProjAll(bool onlyActive) { // init dati necessari diff --git a/GPW.CORE.Data/DbModels/AnagGruppiModel.cs b/GPW.CORE.Data/DbModels/AnagGruppiModel.cs index 1d24595..f0d1d96 100644 --- a/GPW.CORE.Data/DbModels/AnagGruppiModel.cs +++ b/GPW.CORE.Data/DbModels/AnagGruppiModel.cs @@ -10,10 +10,10 @@ namespace GPW.CORE.Data.DbModels [Table("AnagGruppi")] public partial class AnagGruppiModel { - //public AnagGruppiModel() - //{ - // DipendentiNav = new HashSet(); - //} + public AnagGruppiModel() + { + Dipendenti2GruppiNav = new HashSet(); + } public string Gruppo { get; set; } = null!; public string? DescrGruppo { get; set; } public string? CodExt { get; set; } @@ -22,6 +22,6 @@ namespace GPW.CORE.Data.DbModels /// public bool? ExportEnab { get; set; } - //public virtual ICollection DipendentiNav { get; set; } + public virtual ICollection Dipendenti2GruppiNav { get; set; } } } diff --git a/GPW.CORE.Data/DbModels/Dipendenti2GruppiModel.cs b/GPW.CORE.Data/DbModels/Dipendenti2GruppiModel.cs new file mode 100644 index 0000000..ba5627c --- /dev/null +++ b/GPW.CORE.Data/DbModels/Dipendenti2GruppiModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; + +namespace GPW.CORE.Data.DbModels +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + [Table(" Dipendenti2Gruppi")] + public partial class Dipendenti2GruppiModel + { + public int IdxDipendente { get; set; } + public string Gruppo { get; set; } = null!; + + /// + /// Navigation property to Dipendente + /// + [ForeignKey("Gruppo")] + public virtual AnagGruppiModel GruppiNav { get; set; } = null!; + /// + /// Navigation property to Dipendente + /// + [ForeignKey("IdxDipendente")] + public virtual DipendentiModel DipNav { get; set; } = null!; + } +} diff --git a/GPW.CORE.Data/GPWContext.cs b/GPW.CORE.Data/GPWContext.cs index bb0fd07..603ff24 100644 --- a/GPW.CORE.Data/GPWContext.cs +++ b/GPW.CORE.Data/GPWContext.cs @@ -53,6 +53,7 @@ namespace GPW.CORE.Data public virtual DbSet DbSetCalcOreFasi { get; set; } = null!; public virtual DbSet DbSetAnagKeyValue { get; set; } = null!; public virtual DbSet DbSetAnagTipoTimb { get; set; } = null!; + public virtual DbSet DbSetDipendenti2Gruppi { get; set; } = null!; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { @@ -735,6 +736,18 @@ namespace GPW.CORE.Data .HasDefaultValueSql("('')"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.IdxDipendente, e.Gruppo }); + + entity.ToTable("Dipendenti2Gruppi"); + + entity.Property(e => e.IdxDipendente).HasColumnName("idxDipendente"); + + entity.Property(e => e.Gruppo) + .HasMaxLength(50) + .HasColumnName("gruppo"); + }); OnModelCreatingPartial(modelBuilder); } diff --git a/GPW.CORE.WRKLOG/Components/FasiSearch.razor.cs b/GPW.CORE.WRKLOG/Components/FasiSearch.razor.cs index ef5bb88..0d41cfd 100644 --- a/GPW.CORE.WRKLOG/Components/FasiSearch.razor.cs +++ b/GPW.CORE.WRKLOG/Components/FasiSearch.razor.cs @@ -98,7 +98,7 @@ namespace GPW.CORE.WRKLOG.Components protected async Task ReloadData() { - gruppiList = await GDataServ.AnagGruppiAll(); + gruppiList = await GDataServ.AnagGruppiUser(AppMServ.IdxDipendente); var allProj = await GDataServ.AnagProjAll(); projList = allProj.Where(x => x.Attivo == true && x.Gruppo == gruppoSel).OrderBy(x => x.ClienteNav.RagSociale).ThenBy(x => x.NomeProj).ToList(); var allFasi = await GDataServ.AnagFasiAll(); diff --git a/GPW.CORE.WRKLOG/Components/RegAttEditor.razor.cs b/GPW.CORE.WRKLOG/Components/RegAttEditor.razor.cs index dda5bd5..6689ea2 100644 --- a/GPW.CORE.WRKLOG/Components/RegAttEditor.razor.cs +++ b/GPW.CORE.WRKLOG/Components/RegAttEditor.razor.cs @@ -193,7 +193,7 @@ namespace GPW.CORE.WRKLOG.Components protected async Task ReloadData() { - gruppiList = await GDataServ.AnagGruppiAll(); + gruppiList = await GDataServ.AnagGruppiUser(AppMServ.IdxDipendente); var allProj = await GDataServ.AnagProjAll(); projList = allProj .Where(x => x.Attivo == true && x.Gruppo == gruppoSel) diff --git a/GPW.CORE.WRKLOG/Data/GpwDataService.cs b/GPW.CORE.WRKLOG/Data/GpwDataService.cs index 558a87f..1bac34c 100644 --- a/GPW.CORE.WRKLOG/Data/GpwDataService.cs +++ b/GPW.CORE.WRKLOG/Data/GpwDataService.cs @@ -48,6 +48,7 @@ namespace GPW.CORE.WRKLOG.Data protected const string rKeyDipendenti = "Cache:Dipendenti"; protected const string rKeyFasiAll = "Cache:FasiAll"; protected const string rKeyGrpAll = "Cache:GrpAll"; + protected const string rKeyGrpUser = "Cache:GrpUser"; protected const string rKeyParetoRegAtt = "Cache:ParetoRegAtt"; protected const string rKeyProjAll = "Cache:ProjAll"; protected const string rKeyRilTemp = "Cache:RilTemp"; @@ -264,6 +265,7 @@ namespace GPW.CORE.WRKLOG.Data return await Task.FromResult(dbResult); } +#if false /// /// Recupera l'elenco gruppi (tutti) /// @@ -297,6 +299,43 @@ namespace GPW.CORE.WRKLOG.Data dbResult = new List(); } return await Task.FromResult(dbResult); + } +#endif + + /// + /// Recupera l'elenco gruppi abilitati x il dipendente + /// + /// + /// + public async Task> AnagGruppiUser(int idxDipendente) + { + List? dbResult = new List(); + string currKey = $"{rKeyGrpUser}:{idxDipendente}"; + + string rawData; + var redisDataList = await distributedCache.GetAsync(currKey); + if (redisDataList != null) + { + rawData = Encoding.UTF8.GetString(redisDataList); + dbResult = JsonConvert.DeserializeObject>(rawData); + } + else + { + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.AnagGruppiUser(idxDipendente); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + redisDataList = Encoding.UTF8.GetBytes(rawData); + await distributedCache.SetAsync(currKey, redisDataList, cacheOpt(true)); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per AnagGruppiUser: {ts.TotalMilliseconds} ms"); + } + if (dbResult == null) + { + dbResult = new List(); + } + return await Task.FromResult(dbResult); } ///