diff --git a/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor b/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor index 0dc01b01..66f83cbd 100644 --- a/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor +++ b/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor @@ -1,5 +1,4 @@ -@inject MenuData MDataService - +@inject OprFiltData MDataService @*
*@
@@ -61,12 +60,10 @@
@code{ - /// /// Elenco items da menù per pagina corrente... /// protected List CurrMenuItems { get; set; } = new List(); - /// /// Livello corrente del menu /// diff --git a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor index 9b24eba5..48cb2086 100644 --- a/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor +++ b/MP-TAB/MP-TAB/Components/Pages/TCHistory.razor @@ -1,4 +1,5 @@ @page "/tc-history" +@inject OprFiltData MDataService
@@ -11,10 +12,18 @@
@@ -23,22 +32,82 @@ +
- griglia risultati + @if (ListArticoli != null) + { + griglia risultati + @*
+ + +

@context.CodArticolo | @context.DescArticolo

+
+ +

Loading...

+
+ +

+ There are no strings to display. +

+
+
+
*@ + }
@code { + /// + /// Matricola operatore corrente (da rendere parametrico con gest operatore) + /// + protected int MatrOpr { get; set; } = 102; + protected int NumRec { get; set; } = 100000; + protected string azienda { get; set; } = "*"; + protected string searchVal { get; set; } = ""; + + protected int num2Displ { get; set; } = 10; + + protected List? ListMacchine { get; set; } = null; + protected List? SearchArticoli { get; set; } = null; + protected List? ListArticoli { get; set; } = null; + + protected async override Task OnInitializedAsync() + { + SearchArticoli = await MDataService.ArticoliGetSearch(NumRec, azienda, searchVal); + TotalCount = SearchArticoli.Count; + ListArticoli = SearchArticoli.Take(num2Displ).ToList(); + ListMacchine = await MDataService.MacchineByMatrOper(MatrOpr); + } + + protected int TotalCount { get; set; } = 0; + + protected void LoadMore() + { + ListArticoli = null; + // await Task.Delay(1); + num2Displ += 10; + num2Displ = num2Displ < TotalCount ? num2Displ : TotalCount; + ListArticoli = SearchArticoli?.Take(num2Displ).ToList(); + } } diff --git a/MP-TAB/MP-TAB/Program.cs b/MP-TAB/MP-TAB/Program.cs index 5009a01f..3a4abb8b 100644 --- a/MP-TAB/MP-TAB/Program.cs +++ b/MP-TAB/MP-TAB/Program.cs @@ -14,7 +14,7 @@ var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); // Add services x accesso dati builder.Services.AddSingleton(redisMultiplexer); builder.Services.AddSingleton(); -builder.Services.AddSingleton(); +builder.Services.AddSingleton(); // nuova versione contenuti... builder.Services.AddRazorComponents() diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index c0bcee56..85163492 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -185,7 +185,8 @@ namespace MP.Data.Controllers dbResult = dbCtx .DbSetArticoli .AsNoTracking() - .Where(x => (x.Azienda == azienda || azienda == "*") && (x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal))) + .Where(x => (azienda == "*" || x.Azienda == azienda ) && (string.IsNullOrEmpty(searchVal) || x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) )) + //.AsNoTracking() .OrderBy(x => x.CodArticolo) .Take(numRecord) .ToList(); @@ -713,24 +714,74 @@ namespace MP.Data.Controllers if (codGruppo == "*") { dbResult = dbCtx - .DbSetMacchine - .AsNoTracking() - .OrderBy(x => x.IdxMacchina) - .ToList(); + .DbSetMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); } else { dbResult = dbCtx - .DbSetGrp2Macc - .Where(g => g.CodGruppo == codGruppo) - .Join(dbCtx.DbSetMacchine, - g => g.IdxMacchina, - m => m.IdxMacchina, - (g, m) => m - ) - .AsNoTracking() - .OrderBy(x => x.IdxMacchina) - .ToList(); + .DbSetGrp2Macc + .Where(g => g.CodGruppo == codGruppo) + .Join(dbCtx.DbSetMacchine, + g => g.IdxMacchina, + m => m.IdxMacchina, + (g, m) => m + ) + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in MacchineGetFilt{Environment.NewLine}{exc}"); + } + return dbResult; + } + + /// + /// Elenco Macchine dato operatore secondo gruppi (macchine/operatore) + /// + /// + /// + public List MacchineByMatrOper(int MatrOpr) + { + List dbResult = new List(); + try + { + using (var dbCtx = new MoonProContext(_configuration)) + { + if (MatrOpr == 0) + { + dbResult = dbCtx + .DbSetMacchine + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); + } + else + { + dbResult = dbCtx + .DbSetGrp2Oper + .Where(g => g.MatrOpr == MatrOpr) + .Join(dbCtx.DbSetGrp2Macc, + g => g.CodGruppo, + m => m.CodGruppo, + (g, m) => m + ) + .Distinct() + .Join(dbCtx.DbSetMacchine, + g => g.IdxMacchina, + m => m.IdxMacchina, + (g, m) => m + ) + .Distinct() + .AsNoTracking() + .OrderBy(x => x.IdxMacchina) + .ToList(); } } } diff --git a/MP.Data/DatabaseModels/Gruppi2OperModel.cs b/MP.Data/DatabaseModels/Gruppi2OperModel.cs new file mode 100644 index 00000000..78ffa5a1 --- /dev/null +++ b/MP.Data/DatabaseModels/Gruppi2OperModel.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +#nullable disable +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DatabaseModels +{ + [Table("Gruppi2Operatori")] + public partial class Gruppi2OperModel + { + #region Public Properties + public int MatrOpr { get; set; } = 0; + + public string CodGruppo { get; set; } = ""; + + /// + /// Navigazione oggetto Operatori + /// + [ForeignKey("MatrOpr")] + public virtual AnagOperatoriModel OperNav { get; set; } = null!; + + /// + /// Navigazione oggetto Machine + /// + [ForeignKey("CodGruppo")] + public virtual AnagGruppi GruppiNav { get; set; } = null!; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index d25b9ddf..6dd285ab 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -55,6 +55,7 @@ namespace MP.Data public virtual DbSet DbSetEvList { get; set; } public virtual DbSet DbSetVocabolario { get; set; } public virtual DbSet DbOperatori { get; set; } + public virtual DbSet DbSetGrp2Oper { get; set; } public virtual DbSet DbSetGrp2Macc { get; set; } public virtual DbSet DbSetDatiMacchine { get; set; } public virtual DbSet DbSetMSFD { get; set; } @@ -323,7 +324,12 @@ namespace MP.Data }); modelBuilder.Entity(entity => { - entity.HasKey(e => new { e.CodGruppo, e.IdxMacchina}); + entity.HasKey(e => new { e.CodGruppo, e.IdxMacchina }); + + }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CodGruppo, e.MatrOpr}); }); diff --git a/MP.Data/Services/BaseServ.cs b/MP.Data/Services/BaseServ.cs index 4faf5346..78f4f222 100644 --- a/MP.Data/Services/BaseServ.cs +++ b/MP.Data/Services/BaseServ.cs @@ -30,7 +30,7 @@ namespace MP.Data.Services } /// - /// Durata cache molto breve (10 sec circa + perturbazione percentuale +/-10%) + /// Durata cache MOLTO breve (10 sec circa + perturbazione percentuale +/-10%) /// protected TimeSpan UltraFastCache { @@ -38,7 +38,7 @@ namespace MP.Data.Services } /// - /// Durata cache lunga (+ perturbazione percentuale +/-10%) + /// Durata cache MOLTO lunga (+ perturbazione percentuale +/-10%) /// protected TimeSpan UltraLongCache { diff --git a/MP.Data/Services/MenuData.cs b/MP.Data/Services/OprFiltData.cs similarity index 51% rename from MP.Data/Services/MenuData.cs rename to MP.Data/Services/OprFiltData.cs index 66e1c6fe..5a06dd15 100644 --- a/MP.Data/Services/MenuData.cs +++ b/MP.Data/Services/OprFiltData.cs @@ -15,11 +15,14 @@ using System.Threading.Tasks; namespace MP.Data.Services { - public class MenuData : BaseServ, IDisposable + /// + /// Classe accesso dati filtrati per operatore + /// + public class OprFiltData : BaseServ, IDisposable { #region Public Constructors - public MenuData(IConfiguration configuration) + public OprFiltData(IConfiguration configuration) { _configuration = configuration; @@ -75,7 +78,7 @@ namespace MP.Data.Services sw.Start(); List? result = new List(); // cerco in redis... - string currKey = $"{redisMenuDataKey}:{tipoLink}"; + string currKey = $"{redisBaseKey}:Menu:{tipoLink}"; RedisValue rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty($"{rawData}")) { @@ -98,6 +101,81 @@ namespace MP.Data.Services return result; } + + /// + /// Elenco Macchine dato operatore secondo gruppi (macchine/operatore) + /// + /// + /// + public async Task> MacchineByMatrOper(int MatrOpr) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Macc:{MatrOpr}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = await Task.FromResult(dbController.MacchineByMatrOper(MatrOpr)); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"MacchineGetFilt | MatrOpr: {MatrOpr} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + + + /// + /// Elenco tabella Articoli da filtro + /// + /// Numero record max da recuperare + /// cod azienda, * = tutte + /// Ricerca testuale + /// + public async Task> ArticoliGetSearch(int numRecord, string azienda, string searchVal) + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Art:{azienda}:{searchVal}:{numRecord}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = await Task.FromResult(dbController.ArticoliGetSearch(numRecord, azienda, searchVal)); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ArticoliGetSearch | azienda: {azienda} | searchVal: {searchVal} | numRecord: {numRecord} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + #endregion Public Methods #region Protected Fields @@ -119,7 +197,7 @@ namespace MP.Data.Services private static IConfiguration _configuration = null!; private static Logger Log = LogManager.GetCurrentClassLogger(); - private string redisMenuDataKey = "MP:ALL:Cache:Menu"; + private string redisBaseKey = "MP:ALL:Cache"; #endregion Private Fields }