From 34471c607324bd7dfce54a7eb9df035c3c85cc25 Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Tue, 10 Jan 2023 17:46:57 +0100 Subject: [PATCH] Bozza lettura dati --- GPW.CORE.Comp/CalendarMonth.razor | 4 +- GPW.CORE.Comp/CalendarMonth.razor.cs | 22 + GPW.CORE.Comp/GPW.CORE.Comp.csproj | 4 + GPW.CORE.SMART/Components/Calendario.razor | 10 +- GPW.CORE.SMART/Components/Calendario.razor.cs | 20 + GPW.CORE.SMART/Data/CoreSmartDataService.cs | 394 +++++++++--------- 6 files changed, 244 insertions(+), 210 deletions(-) diff --git a/GPW.CORE.Comp/CalendarMonth.razor b/GPW.CORE.Comp/CalendarMonth.razor index 4904dc5..b7e954c 100644 --- a/GPW.CORE.Comp/CalendarMonth.razor +++ b/GPW.CORE.Comp/CalendarMonth.razor @@ -114,10 +114,10 @@ else
- +
- +
diff --git a/GPW.CORE.Comp/CalendarMonth.razor.cs b/GPW.CORE.Comp/CalendarMonth.razor.cs index f4d3647..64f8d3a 100644 --- a/GPW.CORE.Comp/CalendarMonth.razor.cs +++ b/GPW.CORE.Comp/CalendarMonth.razor.cs @@ -80,6 +80,28 @@ namespace GPW.CORE.Comp [Parameter] public string WeekEndCss { get; set; } = "bg-secondary text-light bg-opacity-75"; + /// + /// titolo che verrà inserito in gauge + /// + [Parameter] + public string RightGaugeTitle { get; set; } = "--:--"; + /// + /// testo che verrà inserito in gauge + /// + [Parameter] + public string RightGaugeText { get; set; } = "-----"; + + /// + /// titolo che verrà inserito in gauge + /// + [Parameter] + public string LeftGaugeTitle { get; set; } = "--:--"; + /// + /// testo che verrà inserito in gauge + /// + [Parameter] + public string LeftGaugeText { get; set; } = "-----"; + #endregion Public Properties #region Protected Methods diff --git a/GPW.CORE.Comp/GPW.CORE.Comp.csproj b/GPW.CORE.Comp/GPW.CORE.Comp.csproj index 55f72a9..b7c5e76 100644 --- a/GPW.CORE.Comp/GPW.CORE.Comp.csproj +++ b/GPW.CORE.Comp/GPW.CORE.Comp.csproj @@ -41,4 +41,8 @@ + + + + diff --git a/GPW.CORE.SMART/Components/Calendario.razor b/GPW.CORE.SMART/Components/Calendario.razor index ef89396..02e5478 100644 --- a/GPW.CORE.SMART/Components/Calendario.razor +++ b/GPW.CORE.SMART/Components/Calendario.razor @@ -1,5 +1,9 @@ -
- -
+@if (timbratureOggi != null) +{ +
+ +
+ +} diff --git a/GPW.CORE.SMART/Components/Calendario.razor.cs b/GPW.CORE.SMART/Components/Calendario.razor.cs index af97abb..b052039 100644 --- a/GPW.CORE.SMART/Components/Calendario.razor.cs +++ b/GPW.CORE.SMART/Components/Calendario.razor.cs @@ -12,19 +12,33 @@ using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web.Virtualization; using Microsoft.JSInterop; using GPW.CORE.Smart; +using GPW.CORE.Data; using GPW.CORE.Smart.Shared; using GPW.CORE.Comp; +using GPW.CORE.Data.DTO; +using GPW.CORE.Data.Controllers; namespace GPW.CORE.Smart.Components { public partial class Calendario { + [Inject] + protected GPWController GPWContr { get; set; } = null!; + #region Protected Methods protected override async Task OnInitializedAsync() { dtCurr = DateTime.Today; await Task.Delay(1); + + listRecords = GPWContr.DailyDetails(56, DateTime.Now.AddDays(-3), DateTime.Now); + + timbratureOggi = listRecords.Where(x=> x.DtInizio == DateTime.Now.Date).FirstOrDefault(); + + oreCaricate = timbratureOggi.OreComm.ToString(); + oreLavorate = timbratureOggi.OreLav.ToString(); + DateCheck = new Dictionary(); Random rnd = new Random(); // random colorate... @@ -42,6 +56,12 @@ namespace GPW.CORE.Smart.Components } } + protected string oreCaricate = ""; + protected string oreLavorate = ""; + + protected List? listRecords = null; + protected DailyDataDTO? timbratureOggi = null; + #endregion Protected Methods #region Private Fields diff --git a/GPW.CORE.SMART/Data/CoreSmartDataService.cs b/GPW.CORE.SMART/Data/CoreSmartDataService.cs index 093a62b..0613e6e 100644 --- a/GPW.CORE.SMART/Data/CoreSmartDataService.cs +++ b/GPW.CORE.SMART/Data/CoreSmartDataService.cs @@ -1,11 +1,15 @@ -using GPW.CORE.Data.DTO; +using GPW.CORE.Data.DbModels; +using GPW.CORE.Data.DTO; using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; +using Microsoft.VisualBasic; using Newtonsoft.Json; using NLog; using StackExchange.Redis; using System.Diagnostics; +using System.Reflection.PortableExecutable; +using System.Text; namespace GPW.CORE.Smart.Data { @@ -61,6 +65,54 @@ namespace GPW.CORE.Smart.Data #region Public Methods + + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + } + private readonly IDistributedCache distributedCache; + + + /// + /// Recupera l'elenco dei dettagli giornalieri attività di un dipendente, dato periodo riferimento + /// + /// Dipendente interessato + /// Data di riferimento (ultima/corrente) + /// NUm settimane precedenti da recuperare + /// + public async Task> DailyDetails(int idxDipendente, DateTime dtInizio, DateTime dtFine) + { + List? dbResult = new List(); + string currKey = $"{rKeyDailyData}:{idxDipendente}:{dtInizio.ToString("yyyy-MM-dd")}:{dtFine.ToString("yyyy-MM-dd")}"; + trackCache(currKey); + 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.DailyDetails(idxDipendente, dtInizio, dtFine); + 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 DailyDetails: {ts.TotalMilliseconds} ms"); + } + if (dbResult == null) + { + dbResult = new List(); + } + return await Task.FromResult(dbResult); + } + +#if false /// /// Recupera l'elenco dei dettagli giornalieri attività di un dipendente, dato periodo riferimento /// @@ -103,208 +155,6 @@ namespace GPW.CORE.Smart.Data return dbResult; } - public void Dispose() - { - // Clear database controller - dbController.Dispose(); - } - - public async Task FlushRedisCache() - { - await Task.Delay(1); - RedisValue pattern = new RedisValue($"{redisBaseAddr}:*"); - bool answ = await ExecFlushRedisPattern(pattern); - return answ; - } - - public void rollBackEdit(object item) - { - dbController.rollBackEntity(item); - } - - #endregion Public Methods - - #region Protected Fields - - protected const string redisBaseAddr = "GPW:Smart"; - - protected const string rKeyAKV = $"{redisBaseAddr}:Cache:AKV"; - - protected const string rKeyAnOrDip = $"{redisBaseAddr}:Cache:AnOrariDip"; - - protected const string rKeyCalcOreFase = $"{redisBaseAddr}:Cache:CalcOreFase"; - - protected const string rKeyCalcOreProj = $"{redisBaseAddr}:Cache:CalcOreProj"; - - protected const string rKeyCalendari = $"{redisBaseAddr}:Cache:Calendari"; - - protected const string rKeyCliAll = $"{redisBaseAddr}:Cache:CliAll"; - - protected const string rKeyConfig = $"{redisBaseAddr}:Cache:Config"; - - protected const string rKeyDailyData = $"{redisBaseAddr}:Cache:DailyData"; - - protected const string rKeyDipendenti = $"{redisBaseAddr}:Cache:Dipendenti"; - - protected const string rKeyFasiAll = $"{redisBaseAddr}:Cache:FasiAll"; - - protected const string rKeyFasiByProj = $"{redisBaseAddr}:Cache:FasiByProj"; - - protected const string rKeyFasiSearch = $"{redisBaseAddr}:Cache:FasiSearch"; - - protected const string rKeyGiust = $"{redisBaseAddr}:Cache:Giustif"; - - protected const string rKeyGrpAll = $"{redisBaseAddr}:Cache:GrpAll"; - - protected const string rKeyGrpUser = $"{redisBaseAddr}:Cache:GrpUser"; - - protected const string rKeyParetoRegAtt = $"{redisBaseAddr}:Cache:ParetoRegAtt"; - - protected const string rKeyProjAll = $"{redisBaseAddr}:Cache:ProjAll"; - - protected const string rKeyRilTemp = $"{redisBaseAddr}:Cache:RilTemp"; - - protected const string rKeyVC19 = $"{redisBaseAddr}:Cache:VC19"; - - protected const string rKeyVetoIns = $"{redisBaseAddr}:Cache:VetoInsert"; - - protected const string rKeyWeekStats = $"{redisBaseAddr}:Cache:WeekStats"; - - protected static string connStringBBM = ""; - - #endregion Protected Fields - - #region Protected Methods - - /// - /// Invio email tramite libreria - /// - /// - /// - /// - /// - protected async Task sendEmail(string destList, string subject, string message) - { - List emailDestList = destList.Split(",").ToList(); - foreach (var dest in emailDestList) - { - try - { - await _emailSender.SendEmailAsync(dest, subject, message); - } - catch (Exception exc) - { - Log.Error($"Eccezione durante invio email:{Environment.NewLine}dest: {dest} | subject {subject}{Environment.NewLine}{exc}"); - } - } - } - - /// - /// Registra in cache chiave se non fosse già in elenco - /// - /// - protected void trackCache(string newKey) - { - if (!cachedDataList.Contains(newKey)) - { - cachedDataList.Add(newKey); - } - } - - #endregion Protected Methods - - #region Private Fields - - private static IConfiguration _configuration = null!; - - private static ILogger _logger = null!; - - private static JsonSerializerSettings? JSSettings; - - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - - private readonly IEmailSender _emailSender; - - private readonly IMemoryCache memoryCache; - - private List cachedDataList = new List(); - - /// - /// Durata assoluta massima della cache IN SECONDI - /// - private int chAbsExp = 60 * 5; - - /// - /// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire - /// rimossa NON estende oltre il tempo massimo di validità della cache (chAbsExp) - /// - private int chSliExp = 60 * 1; - - /// - /// Oggetto per connessione a REDIS - /// - private IConnectionMultiplexer redisConn; - - //ISubscriber sub = redis.GetSubscriber(); - /// - /// Oggetto DB redis da impiegare x chiamate R/W - /// - private IDatabase redisDb = null!; - - #endregion Private Fields - - #region Private Methods - - //private readonly IEmailSender _emailSender; - //private readonly UserManager _userManager; - //private ConnectionMultiplexer redisConnMult = null!; - private DistributedCacheEntryOptions cacheOpt(bool fastCache) - { - var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10; - var numSecSliExp = fastCache ? chSliExp : chSliExp * 10; - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); - } - - private DistributedCacheEntryOptions cacheOpt(int multFact) - { - var numSecAbsExp = chAbsExp * multFact; - var numSecSliExp = chSliExp * multFact; - return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); - } - - /// - /// Esegue flush memoria redis dato pattern - /// - /// - /// - private async Task ExecFlushRedisPattern(RedisValue pattern) - { - bool answ = false; - var listEndpoints = redisConn.GetEndPoints(); - foreach (var endPoint in listEndpoints) - { - //var server = redisConnAdmin.GetServer(listEndpoints[0]); - var server = redisConn.GetServer(endPoint); - if (server != null) - { - var keyList = server.Keys(redisDb.Database, pattern); - foreach (var item in keyList) - { - await redisDb.KeyDeleteAsync(item); - } - // brutalmente rimuovo intero contenuto DB... DANGER - //await server.FlushDatabaseAsync(); - answ = true; - } - } - - return answ; - } - - #endregion Private Methods - -#if false - /// /// Elenco AKV /// @@ -853,6 +703,7 @@ namespace GPW.CORE.Smart.Data return await Task.FromResult(keyResult); } + public async Task> DipendentiGetAll() { List? dbResult = new List(); @@ -882,6 +733,7 @@ namespace GPW.CORE.Smart.Data return await Task.FromResult(dbResult); } + /// /// invalida tutta la cache in caso di update /// @@ -1369,8 +1221,14 @@ namespace GPW.CORE.Smart.Data catch { } return answ; - } + } #endif + + public void rollBackEdit(object item) + { + dbController.rollBackEntity(item); + } + #if false /// /// Elenco timbrature di un giorno @@ -1418,7 +1276,133 @@ namespace GPW.CORE.Smart.Data catch { } return answ; - } + } #endif + + #endregion Public Methods + + #region Protected Fields + + protected const string rKeyAKV = "Cache:AKV"; + protected const string rKeyAnOrDip = "Cache:AnOrariDip"; + protected const string rKeyCalcOreFase = "Cache:CalcOreFase"; + protected const string rKeyCalcOreProj = "Cache:CalcOreProj"; + protected const string rKeyCalendari = "Cache:Calendari"; + protected const string rKeyCliAll = "Cache:CliAll"; + protected const string rKeyConfig = "Cache:Config"; + protected const string rKeyDailyData = "Cache:DailyData"; + protected const string rKeyDipendenti = "Cache:Dipendenti"; + protected const string rKeyFasiAll = "Cache:FasiAll"; + protected const string rKeyFasiByProj = "Cache:FasiByProj"; + protected const string rKeyFasiSearch = "Cache:FasiSearch"; + protected const string rKeyGiust = "Cache:Giustif"; + 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"; + protected const string rKeyVC19 = "Cache:VC19"; + protected const string rKeyVetoIns = "Cache:VetoInsert"; + protected const string rKeyWeekStats = "Cache:WeekStats"; + protected static string connStringBBM = ""; + + #endregion Protected Fields + + #region Protected Methods + + /// + /// Invio email tramite libreria + /// + /// + /// + /// + /// + protected async Task sendEmail(string destList, string subject, string message) + { + List emailDestList = destList.Split(",").ToList(); + foreach (var dest in emailDestList) + { + try + { + await _emailSender.SendEmailAsync(dest, subject, message); + } + catch (Exception exc) + { + Log.Error($"Eccezione durante invio email:{Environment.NewLine}dest: {dest} | subject {subject}{Environment.NewLine}{exc}"); + } + } + } + + /// + /// Registra in cache chiave se non fosse già in elenco + /// + /// + protected void trackCache(string newKey) + { + if (!cachedDataList.Contains(newKey)) + { + cachedDataList.Add(newKey); + } + } + + #endregion Protected Methods + + #region Private Fields + + private static IConfiguration _configuration = null!; + private static ILogger _logger = null!; + private static JsonSerializerSettings? JSSettings; + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private readonly IEmailSender _emailSender; + + //private readonly IEmailSender _emailSender; + //private readonly UserManager _userManager; + + + /// + /// Oggetto per connessione a REDIS + /// + private IConnectionMultiplexer redisConn; + //private ConnectionMultiplexer redisConnMult = null!; + + //ISubscriber sub = redis.GetSubscriber(); + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + private IDatabase redisDb = null!; + + private readonly IMemoryCache memoryCache; + private List cachedDataList = new List(); + + /// + /// Durata assoluta massima della cache IN SECONDI + /// + private int chAbsExp = 60 * 5; + + /// + /// Durata della cache IN SECONDI in modalità inattiva (non acceduta) prima di venire + /// rimossa NON estende oltre il tempo massimo di validità della cache (chAbsExp) + /// + private int chSliExp = 60 * 1; + + #endregion Private Fields + + #region Private Methods + + private DistributedCacheEntryOptions cacheOpt(bool fastCache) + { + var numSecAbsExp = fastCache ? chAbsExp : chAbsExp * 10; + var numSecSliExp = fastCache ? chSliExp : chSliExp * 10; + return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); + } + + private DistributedCacheEntryOptions cacheOpt(int multFact) + { + var numSecAbsExp = chAbsExp * multFact; + var numSecSliExp = chSliExp * multFact; + return new DistributedCacheEntryOptions().SetAbsoluteExpiration(DateTime.Now.AddSeconds(numSecAbsExp)).SetSlidingExpiration(TimeSpan.FromSeconds(numSecSliExp)); + } + + #endregion Private Methods } } \ No newline at end of file