diff --git a/MP.Data/Controllers/MpTabController.cs b/MP.Data/Controllers/MpTabController.cs index df67fb6b..51f78bb2 100644 --- a/MP.Data/Controllers/MpTabController.cs +++ b/MP.Data/Controllers/MpTabController.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using MP.Data.DatabaseModels; using NLog; @@ -15,7 +16,7 @@ namespace MP.Data.Controllers public MpTabController(IConfiguration configuration) { _configuration = configuration; - Log.Info("Avviata classe MpTabController"); + Log.Info("Avviato MpTabController"); } #endregion Public Constructors @@ -62,6 +63,56 @@ namespace MP.Data.Controllers _configuration = null; } + /// + /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL + /// + /// + /// + /// + public List STAR_byGrpOdl(string codGruppo, int idxODL) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var CodGruppo = new SqlParameter("@CodGruppo", codGruppo); + var IdxODL = new SqlParameter("@IdxODL", idxODL); + + dbResult = dbCtx + .DbSetStActRow + .FromSqlRaw("exec dbo.stp_ST_AR_getByGrpOdl @CodGruppo, @IdxODL", CodGruppo, IdxODL) + .AsNoTracking() + .AsEnumerable() + .ToList(); + } + return dbResult; + } + + /// + /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL + label + /// + /// + /// + /// + /// + public List STAR_byGrpOdlLbl(string codGruppo, string label, int idxODL) + { + List dbResult = new List(); + using (var dbCtx = new MoonProContext(_configuration)) + { + var CodGruppo = new SqlParameter("@CodGruppo", codGruppo); + var Label = new SqlParameter("@Label", label); + var IdxODL = new SqlParameter("@IdxODL", idxODL); + + dbResult = dbCtx + .DbSetStActRow + .FromSqlRaw("exec dbo.stp_ST_AR_getGrpOdlLabel @CodGruppo, @Label, @IdxODL", CodGruppo, Label, IdxODL) + .AsNoTracking() + .AsEnumerable() + .ToList(); + } + return dbResult; + } + #endregion Public Methods #region Private Fields diff --git a/MP.Data/DatabaseModels/ST_Act.cs b/MP.Data/DatabaseModels/ST_Act.cs new file mode 100644 index 00000000..97f1e16c --- /dev/null +++ b/MP.Data/DatabaseModels/ST_Act.cs @@ -0,0 +1,27 @@ +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("ST_Actual")] + public partial class ST_Act + { + + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int IdxST { get; set; } + public string CodTempl { get; set; } = ""; + public string CodArticolo { get; set; } = ""; + public int MatrOpr { get; set; } = 0; + public DateTime DtMod { get; set; } = DateTime.Now; + public string UserLogin { get; set; } = ""; + public bool IsValidated { get; set; } = false; + + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/ST_ActRow.cs b/MP.Data/DatabaseModels/ST_ActRow.cs new file mode 100644 index 00000000..7248effa --- /dev/null +++ b/MP.Data/DatabaseModels/ST_ActRow.cs @@ -0,0 +1,31 @@ +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("ST_ActualRows")] + public partial class ST_ActRow + { + + public int IdxST { get; set; } + public string Label { get; set; } = ""; + public int Oggetto { get; set; } = 0; + public int Num { get; set; } = 0; + public string CodGruppo { get; set; } = ""; + public string CodTipo { get; set; } = ""; + public string Value { get; set; } = ""; + public string CheckType { get; set; } = ""; + public bool Required { get; set; } = false; + public string ExtCode { get; set; } = ""; + public string ValueRead { get; set; } = ""; + public string Note { get; set; } = ""; + + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/ST_AnagGruppi.cs b/MP.Data/DatabaseModels/ST_AnagGruppi.cs new file mode 100644 index 00000000..af723ef5 --- /dev/null +++ b/MP.Data/DatabaseModels/ST_AnagGruppi.cs @@ -0,0 +1,24 @@ +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("ST_AnagGruppi")] + public partial class ST_AnagGruppi + { + + [Key] + public string CodGruppo { get; set; } = ""; + public string DescGruppo { get; set; } = ""; + public int OrdVisual { get; set; } = 0; + public string CssClass { get; set; } = ""; + + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/ST_AnagTipi.cs b/MP.Data/DatabaseModels/ST_AnagTipi.cs new file mode 100644 index 00000000..153e0ad3 --- /dev/null +++ b/MP.Data/DatabaseModels/ST_AnagTipi.cs @@ -0,0 +1,22 @@ +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("ST_AnagTipi")] + public partial class ST_AnagTipi + { + + [Key] + public string CodTipo { get; set; } = ""; + public string DescTipo { get; set; } = ""; + + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/ST_Check.cs b/MP.Data/DatabaseModels/ST_Check.cs new file mode 100644 index 00000000..23d58db2 --- /dev/null +++ b/MP.Data/DatabaseModels/ST_Check.cs @@ -0,0 +1,30 @@ +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("ST_Check")] + public partial class ST_Check + { + + public DateTime DtEvent { get; set; } = DateTime.Now; + public int IdxODL { get; set; } = 0; + public int IdxST { get; set; } = 0; + public int Oggetto { get; set; } = 0; + public int Num { get; set; } = 0; + public string ValueRead { get; set; } = ""; + public string ExtCode { get; set; } = ""; + public bool CheckOk { get; set; } = false; + public DateTime DtMod { get; set; } = DateTime.Now; + public string UserMod { get; set; } = ""; + public bool Forced { get; set; } = false; + + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/ST_Template.cs b/MP.Data/DatabaseModels/ST_Template.cs new file mode 100644 index 00000000..da7eca57 --- /dev/null +++ b/MP.Data/DatabaseModels/ST_Template.cs @@ -0,0 +1,22 @@ +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("ST_Template")] + public partial class ST_Template + { + + [Key] + public string CodTempl { get; set; } = ""; + public string DescTempl { get; set; } = ""; + + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/ST_TemplateRows.cs b/MP.Data/DatabaseModels/ST_TemplateRows.cs new file mode 100644 index 00000000..0e5d4df0 --- /dev/null +++ b/MP.Data/DatabaseModels/ST_TemplateRows.cs @@ -0,0 +1,28 @@ +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("ST_TemplateRows")] + public partial class ST_TemplateRows + { + + public string CodTempl { get; set; } = ""; + public int Num { get; set; } = 0; + public string CodGruppo { get; set; } = ""; + public string CodTipo { get; set; } = ""; + public string Label { get; set; } = ""; + public string Value { get; set; } = ""; + public string CheckType { get; set; } = ""; + public bool Required { get; set; } = false; + public string Note { get; set; } = ""; + + } +} \ No newline at end of file diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index 893ebeb4..d1eae27d 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -64,6 +64,14 @@ namespace MP.Data public virtual DbSet DbSetSMI { get; set; } public virtual DbSet DbSetKeepAlive { get; set; } + public virtual DbSet DbSetStAct { get; set; } + public virtual DbSet DbSetStActRow { get; set; } + public virtual DbSet DbSetStAnagGruppi { get; set; } + public virtual DbSet DbSetStAnagTipi { get; set; } + public virtual DbSet DbSetStCheck { get; set; } + public virtual DbSet DbSetStTemplate { get; set; } + public virtual DbSet DbSetStTemplateRows { get; set; } + #endregion Public Properties #region Private Methods @@ -330,7 +338,7 @@ namespace MP.Data }); modelBuilder.Entity(entity => { - entity.HasKey(e => new { e.CodGruppo, e.MatrOpr}); + entity.HasKey(e => new { e.CodGruppo, e.MatrOpr }); }); @@ -474,6 +482,23 @@ namespace MP.Data entity.Property(e => e.DataOraStart).HasColumnType("datetime"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.IdxST, e.Label, e.Oggetto }); + + }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.DtEvent, e.IdxODL, e.IdxST, e.Oggetto, e.Num }); + + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.CodTempl, e.Num }); + + }); + OnModelCreatingPartial(modelBuilder); } diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index 7dc7c77c..a7040975 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -101,6 +101,19 @@ namespace MP.Data.Services } } + public string UserAuthKey + { + get + { + string answ = ""; + if (_rigaOper != null) + { + answ = _rigaOper.authKey; + } + return answ; + } + } + public AnagOperatoriModel? RigaOper { get => _rigaOper; diff --git a/MP.Data/Services/SharedMemService.cs b/MP.Data/Services/SharedMemService.cs index e98ea243..75a69513 100644 --- a/MP.Data/Services/SharedMemService.cs +++ b/MP.Data/Services/SharedMemService.cs @@ -1,19 +1,25 @@ -using Microsoft.Extensions.Configuration; -using MP.Data.DatabaseModels; -using NLog.Fluent; +using MP.Data.DatabaseModels; +using NLog; using StackExchange.Redis; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace MP.Data.Services { - public class SharedMemService + public class SharedMemService : BaseServ { - #region Public Properties + /// + /// List configurazione attiva da tab DB + /// + public List DbConfig { get; set; } = new List(); + + /// + /// Dizionario configurazione attiva da tab DB + /// + public Dictionary DictConfig { get; set; } = new Dictionary(); + /// /// Dizionario macchine (shared) /// @@ -24,54 +30,15 @@ namespace MP.Data.Services /// public Dictionary> DictMenu { get; set; } = new Dictionary>(); - /// - /// List configurazione attiva da tab DB - /// - public List DbConfig { get; set; } = new List(); - - #endregion Public Properties - public bool MenuOk { get => AllMenuData.Count > 0; } - private List AllMenuData { get; set; } = new List(); + #endregion Public Properties #region Public Methods - /// - /// Effettua setup memorie menu recuperando dati dal DB + popolando dizionario x livelli - /// - public void SetupMenu(List AllData) - { - // svuoto i valori in essere - DictMenu.Clear(); - // salvo nuovo set - AllMenuData = AllData; - // ciclo x recuperare i distinti TIPI di menu... - var tList = AllMenuData - .Select(x => x.TipoLink) - .Distinct() - .ToList(); - // per ogni tipo --> ciclo! - foreach (var item in tList) - { - var currMenu = AllMenuData - .Where(x => x.TipoLink == item) - .ToList(); - if (!DictMenu.ContainsKey(item)) - { - DictMenu.Add(item, currMenu); - } - } - } - - public void SetConfig(List? newConfList) - { - DbConfig = newConfList ?? new List(); - } - /// /// Restituisce il livello pagina dato URL /// - se contiene ?IdxMacc --> T2D (detail) @@ -101,12 +68,75 @@ namespace MP.Data.Services /// /// Reset cache memory /// - public void ResetCache() + public void ClearCache() { DictMacchine = new Dictionary(); DictMenu = new Dictionary>(); + DbConfig = new List(); + DictConfig = new Dictionary(); + Log.Info("SharedMemService | Cache resetted!"); } + public void SetConfig(List? newConfList) + { + DbConfig = newConfList ?? new List(); + // salvo dizionario + DictConfig = DbConfig.ToDictionary(x => x.Chiave, x => x.Valore); + Log.Info("SharedMemService | SetConfig executed!"); + } + + /// + /// Effettua setup memorie menu recuperando dati dal DB + popolando dizionario x livelli + /// + public void SetupMenu(List AllData) + { + // svuoto i valori in essere + DictMenu.Clear(); + // salvo nuovo set + AllMenuData = AllData; + // ciclo x recuperare i distinti TIPI di menu... + var tList = AllMenuData + .Select(x => x.TipoLink) + .Distinct() + .ToList(); + // per ogni tipo --> ciclo! + foreach (var item in tList) + { + var currMenu = AllMenuData + .Where(x => x.TipoLink == item) + .ToList(); + if (!DictMenu.ContainsKey(item)) + { + DictMenu.Add(item, currMenu); + } + } + Log.Info("SharedMemService | SetupMenu executed!"); + } + + public string GetConf(string chiave) + { + string answ = ""; + if (DictConfig.ContainsKey(chiave)) + { + answ = DictConfig[chiave]; + } + return answ; + } + + + #endregion Public Methods + + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Private Properties + + private List AllMenuData { get; set; } = new List(); + + #endregion Private Properties } } \ No newline at end of file diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 2de020f9..233c01b0 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -121,12 +121,84 @@ namespace MP.Data.Services dbController.Dispose(); } + /// + /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL + /// + /// + /// + /// + public async Task> STAR_byGrpOdl(string codGruppo, int idxODL) + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:START:{codGruppo}:{idxODL}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.STAR_byGrpOdl(codGruppo, idxODL); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"STAR_byGrpOdl | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// + /// Recupero Righe (Actual) della scheda tecnica da GRUPPO + ODL + /// + /// + /// + /// + /// + public async Task> STAR_byGrpOdlLbl(string codGruppo, string label, int idxODL) + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:START:{codGruppo}:{label}:{idxODL}"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty($"{rawData}")) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.STAR_byGrpOdlLbl(codGruppo, label, idxODL); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"STAR_byGrpOdlLbl | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + #endregion Public Methods #region Protected Fields - protected static IConfiguration _configuration = null!; - /// /// Oggetto per connessione a REDIS ///