From 896d2fbb1222fd1ea7f4eed22fe89c55388d2ac6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 12 Jan 2023 16:59:45 +0100 Subject: [PATCH] Spostato grafici in area componenti condivisi --- GPW.CORE.Comp/Chart.razor | 64 + GPW.CORE.Comp/ChartHist.razor | 84 ++ GPW.CORE.Comp/ChartTS.razor | 92 ++ GPW.CORE.Comp/chartJsData.cs | 16 + GPW.CORE.SMART/Data/CoreSmartDataService.cs | 1203 ++--------------- .../Components/DayCheckEditor.razor.cs | 1 + GPW.CORE.WRKLOG/Components/TimbList.razor | 22 +- GPW.CORE.WRKLOG/Components/TimbrEditor.razor | 2 +- GPW.CORE.WRKLOG/GPW.CORE.WRKLOG.csproj | 7 + GPW.CORE.WRKLOG/Pages/Test.razor.cs | 1 + 10 files changed, 399 insertions(+), 1093 deletions(-) create mode 100644 GPW.CORE.Comp/Chart.razor create mode 100644 GPW.CORE.Comp/ChartHist.razor create mode 100644 GPW.CORE.Comp/ChartTS.razor create mode 100644 GPW.CORE.Comp/chartJsData.cs diff --git a/GPW.CORE.Comp/Chart.razor b/GPW.CORE.Comp/Chart.razor new file mode 100644 index 0000000..0f5780c --- /dev/null +++ b/GPW.CORE.Comp/Chart.razor @@ -0,0 +1,64 @@ +@using Microsoft.JSInterop +@inject IJSRuntime JSRuntime + + + +@code { + public enum ChartType + { + Pie, + Bar + } + + [Parameter] + public string Id { get; set; } = "MyChart"; + + [Parameter] + public ChartType Type { get; set; } + + [Parameter] + public string[]? Data { get; set; } + + [Parameter] + public string[]? BackgroundColor { get; set; } + + [Parameter] + public string[]? Labels { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await InitDefault(); + } + + protected async Task InitDefault() + { + // Here we create an anonymous type with all the options + // that need to be sent to Chart.js + var config = new + { + type = Type.ToString().ToLower(), + options = new + { + responsive = true, + scales = new + { + yAxes = new + { + suggestedMin = 0 + } + }, + Animation = false + }, + data = new + { + datasets = new[] + { + new { data = Data, backgroundColor = BackgroundColor} + }, + labels = Labels + } + }; + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } + +} \ No newline at end of file diff --git a/GPW.CORE.Comp/ChartHist.razor b/GPW.CORE.Comp/ChartHist.razor new file mode 100644 index 0000000..1b395d0 --- /dev/null +++ b/GPW.CORE.Comp/ChartHist.razor @@ -0,0 +1,84 @@ +@using Microsoft.JSInterop +@inject IJSRuntime JSRuntime + + + +@code { + + [Parameter] + public string Id { get; set; } = "MyHist"; + + [Parameter] + public string[]? Data { get; set; } + [Parameter] + public string[]? Labels { get; set; } + + [Parameter] + public string lineColor { get; set; } = ""; + [Parameter] + public string backColor { get; set; } = ""; + + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + //if (!firstRender) + //{ + await renderChart(); + //} + } + + + /// + /// Inizializzazione rendering componente + /// + /// partendo da qui: + /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ + /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ + /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type + /// + /// + /// + protected async Task renderChart() + { + // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js + var config = new + { + type = "bar", + options = new + { + responsive = true, + scales = new + { + yAxes = new + { + suggestedMin = 0, + display = true, + ticks = new + { + beginAtZero = true, + maxTicksLimit = 10 + } + } + }, + Animation = false + }, + data = new + { + datasets = new[] + { + new + { + data = Data, + borderColor = lineColor, + backgroundColor = backColor, + borderWidth = 1, + label= "Freq. Osservate" + } + }, + labels = Labels + } + }; + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } + +} \ No newline at end of file diff --git a/GPW.CORE.Comp/ChartTS.razor b/GPW.CORE.Comp/ChartTS.razor new file mode 100644 index 0000000..99300a6 --- /dev/null +++ b/GPW.CORE.Comp/ChartTS.razor @@ -0,0 +1,92 @@ +@using Microsoft.JSInterop +@inject IJSRuntime JSRuntime + + + +@code { + + [Parameter] + public string Id { get; set; } = "MyTs"; + + [Parameter] + public List DataTS { get; set; } = null!; + + [Parameter] + public string lineColor { get; set; } = ""; + [Parameter] + public string backColor { get; set; } = ""; + + /// + /// Inizializzazione rendering componente + /// + /// partendo da qui: + /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ + /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ + /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type + /// + /// + /// + protected override async Task OnAfterRenderAsync(bool firstRender) + { + //if (!firstRender) + //{ + await renderChart(); + //} + } + + /// + /// Inizializzazione rendering componente + /// + /// partendo da qui: + /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ + /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ + /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type + /// + /// + /// + protected async Task renderChart() + { + // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js + var config = new + { + type = "line", + options = new + { + responsive = true, + scales = new + { + yAxes = new + { + display = true, + ticks = new + { + maxTicksLimit = 10 + } + }, + xAxes = new + { + type = "timeseries", + distribution = "linear", + } + }, + Animation = false + }, + data = new + { + datasets = new[] + { + new + { + data = DataTS, + borderColor= lineColor, + backgroundColor= backColor, + lineTension= 0, + stepped= true, + label= "Temperatura Rilevata" + } + } + } + }; + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } +} \ No newline at end of file diff --git a/GPW.CORE.Comp/chartJsData.cs b/GPW.CORE.Comp/chartJsData.cs new file mode 100644 index 0000000..f849e01 --- /dev/null +++ b/GPW.CORE.Comp/chartJsData.cs @@ -0,0 +1,16 @@ +namespace GPW.CORE.Comp +{ + public class chartJsData + { + public class chartJsTSerie + { + public DateTime x { get; set; } + public decimal y { get; set; } + } + public class chartJsXY + { + public decimal x { get; set; } + public decimal y { get; set; } + } + } +} diff --git a/GPW.CORE.SMART/Data/CoreSmartDataService.cs b/GPW.CORE.SMART/Data/CoreSmartDataService.cs index 90fef40..d6bc5b1 100644 --- a/GPW.CORE.SMART/Data/CoreSmartDataService.cs +++ b/GPW.CORE.SMART/Data/CoreSmartDataService.cs @@ -194,6 +194,120 @@ namespace GPW.CORE.Smart.Data return answ; } + /// + /// Recupera l'elenco dei Rilievi temperatura nel periodo indicato x dipendente + /// + /// Dipendente interessato + /// Data di riferimento (ultima/corrente) + /// NUm settimane precedenti da recuperare + /// + public async Task> RilTempList(int idxDipendente, DateTime dtInizio, DateTime dtFine) + { + string source = "DB"; + List? dbResult = new List(); + string currKey = $"{rKeyRilTemp}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.RilTempList(idxDipendente, dtInizio, dtFine); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"RilTempList | {source} in: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + /// + /// Registra update valore temp rilevata + /// + /// + /// + public async Task RilTempUpdate(RilievoTempModel currItem) + { + bool answ = false; + try + { + dbController.RilTempUpdate(currItem); + // invalido la cache... + await ExecFlushRedisPattern($"{rKeyRilTemp}:*"); + await ExecFlushRedisPattern($"{rKeyDailyData}:*"); + answ = true; + } + catch + { } + return answ; + } + + /// + /// Elenco timbrature di un giorno + /// + /// + /// + /// + public async Task> TimbratureDay(DateTime dateRif, int IdxDip) + { + await Task.Delay(1); + List? dbResult = new List(); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + dbResult = dbController.TimbratureDay(dateRif, IdxDip); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"Effettuata lettura da DB + caching per TimbratureDay: {ts.TotalMilliseconds} ms"); + return dbResult; + } + + public async Task TimbratureDelete(TimbratureModel currItem) + { + bool answ = false; + try + { + dbController.TimbratureDelete(currItem); + // invalido la cache... + await FlushRedisCache(); + answ = true; + } + catch + { } + return answ; + } + + public async Task TimbratureUpdate(TimbratureModel currItem) + { + bool answ = false; + try + { + dbController.TimbratureUpdate(currItem); + // invalido la cache... + await FlushRedisCache(); + answ = true; + } + catch + { } + return answ; + } + public void rollBackEdit(object item) { dbController.rollBackEntity(item); @@ -377,1094 +491,5 @@ namespace GPW.CORE.Smart.Data } #endregion Private Methods - -#if false - - /// - /// Elenco AKV - /// - public async Task?> AKVList() - { - List? dbResult = new List(); - // cerco da cache - string currKey = rKeyAKV; - 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.AnagKeyValGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - redisDataList = Encoding.UTF8.GetBytes(rawData); - await distributedCache.SetAsync(currKey, redisDataList, cacheOpt(500)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Effettuata lettura da DB + caching per AKVList: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Recupera l'elenco fasi (tutte) - /// - /// - public async Task> AnagClientiAll() - { - List? dbResult = new List(); - string currKey = $"{rKeyCliAll}"; - - 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.AnagClientiAll(); - 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 AnagClientiAll: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Recupera l'elenco fasi (tutte) - /// - /// - public async Task> AnagFasiAll() - { - List? dbResult = new List(); - string currKey = $"{rKeyFasiAll}"; - - 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.AnagFasiAll(false); - 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 AnagFasiAll: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Recupera info x una specifica FASE - /// - /// - public async Task AnagFasiByKey(int idxFase) - { - AnagFasiModel? dbResult = new AnagFasiModel(); - // cerco "secca "in redis... - string currKey = $"{rKeyFasiSearch}:{idxFase}"; - 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.AnagFasiByKey(idxFase); - // salvo in cache - 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 AnagFasiSearch: {ts.TotalMilliseconds} ms"); - } - return dbResult; - } - - /// - /// Elenco fasi dato progetto - /// - /// - /// - public async Task?> AnagFasiByProj(int idxProj) - { - List? dbResult = new List(); - // cerco "secca "in redis... - string currKey = $"{rKeyFasiByProj}:{idxProj}"; - 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.AnagFasiByProj(idxProj); - // salvo in cache - 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 AnagFasiByProj: {ts.TotalMilliseconds} ms"); - } - return dbResult; - } - /// - /// Elenco Giustificativi - /// - /// - public async Task?> AnagGiust() - { - List? dbResult = new List(); - // cerco "secca "in redis... - string currKey = $"{rKeyGiust}"; - 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.AnagGiust(); - // salvo in cache - 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 AnagGiust: {ts.TotalMilliseconds} ms"); - } - return dbResult; - } - /// - /// 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 dbResult; - } - - /// - /// Dati orario del dipendente indicato - /// - /// - /// - public async Task AnagOrarioByDip(int idxDip) - { - AnagOrariModel? dbResult = new AnagOrariModel(); - string currKey = $"{rKeyAnOrDip}:{idxDip}"; - - 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.AnagOrarioByDip(idxDip); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - redisDataList = Encoding.UTF8.GetBytes(rawData); - await distributedCache.SetAsync(currKey, redisDataList, cacheOpt(false)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Effettuata lettura da DB + caching per AnagOrarioByDip: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new AnagOrariModel(); - } - return dbResult; - } - - /// - /// Recupera l'elenco progetti (tutti) - /// - /// - public async Task> AnagProjAll() - { - List? dbResult = new List(); - string currKey = $"{rKeyProjAll}"; - - 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.AnagProjAll(false); - 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 AnagProjAll: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Recupera info x uno specifico PROJ - /// - /// - public async Task AnagProjSearch(int idxProj) - { - AnagProgettiModel dbResult = new AnagProgettiModel(); - var rawData = await AnagProjAll(); - if (rawData != null) - { - var foundData = rawData.Where(x => x.IdxProgetto == idxProj).FirstOrDefault(); - if (foundData != null) - { - dbResult = foundData; - } - } - - return dbResult; - } - - /// - /// Vista dati per FASE (tipicamente master...) con totalizzaizone ore budget/real e stato fase - /// - /// - /// - public async Task CalcOreFase(int idxFase) - { - CalcOreFasiModel? dbResult = new CalcOreFasiModel(); - string currKey = $"{rKeyCalcOreFase}:{idxFase}"; - 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.CalcOreFase(idxFase); - 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 CalcOreFase: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new CalcOreFasiModel(); - } - return dbResult; - } - - /// - /// Vista dati per progetto con totalizzaizone ore budget/real - /// - /// - /// - public async Task CalcOreProj(int idxProj) - { - CalcOreProgettiModel? dbResult = new CalcOreProgettiModel(); - string currKey = $"{rKeyCalcOreProj}:{idxProj}"; - 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.CalcOreProj(idxProj); - 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 CalcOreProj: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new CalcOreProgettiModel(); - } - return dbResult; - } - - /// - /// Lista chiusure aziendali dato periodo - /// - /// - /// - /// - public async Task> CalFestFeriePeriodo(DateTime dtStart, DateTime dtEnd) - { - List? dbResult = new List(); - string currKey = $"{rKeyCalendari}:ClaFestFer:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}"; - 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.CalFestFeriePeriodo(dtStart, dtEnd); - 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 CalFestFeriePeriodo: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Recupera l'elenco dei controlli VC19 nel periodo indicato x dipendente - /// - /// Dipendente interessato - /// Data di riferimento (ultima/corrente) - /// NUm settimane precedenti da recuperare - /// - public async Task> CheckVC19List(int idxDipendente, DateTime dtInizio, DateTime dtFine) - { - List? dbResult = new List(); - string currKey = $"{rKeyVC19}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; - 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.CheckVC19List(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 CheckVC19List: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Lista configurazione - /// - /// - /// - /// - public async Task> ConfigGetAll() - { - List? dbResult = new List(); - string currKey = $"{rKeyConfig}:Table"; - 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.ConfigGetAll(); - rawData = JsonConvert.SerializeObject(dbResult, JSSettings); - redisDataList = Encoding.UTF8.GetBytes(rawData); - await distributedCache.SetAsync(currKey, redisDataList, cacheOpt(false)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Effettuata lettura da DB + caching per ConfigGetAll: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Recupera una singola chaive di config da cache/DB - /// - /// - /// - public async Task ConfigGetKey(string chiave) - { - // cerco in cache direttamente la chiave... altrimenti da redis/db - ConfigModel? keyResult = null; - string currKey = $"{rKeyConfig}:Dict:{chiave}"; - trackCache(currKey); - string rawData; - var redisDataList = await distributedCache.GetAsync(currKey); - if (redisDataList != null) - { - rawData = Encoding.UTF8.GetString(redisDataList); - keyResult = JsonConvert.DeserializeObject(rawData); - } - else - { - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - var listConfig = await ConfigGetAll(); - keyResult = listConfig.FirstOrDefault(x => x.chiave == chiave); - rawData = JsonConvert.SerializeObject(keyResult, JSSettings); - redisDataList = Encoding.UTF8.GetBytes(rawData); - await distributedCache.SetAsync(currKey, redisDataList, cacheOpt(false)); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Effettuata lettura da DB + caching per ConfigGetKey | chiave {chiave} | {ts.TotalMilliseconds} ms"); - } - return await Task.FromResult(keyResult); - } - - /// - /// invalida tutta la cache in caso di update - /// - /// - public async Task InvalidateAllCache() - { - await distributedCache.RemoveAsync(rKeyDipendenti); - await distributedCache.RemoveAsync(rKeyFasiAll); - foreach (var item in cachedDataList) - { - await distributedCache.RemoveAsync(item); - } - cachedDataList = new List(); - } - - /// - /// Invalida la cache corrispondente al apttern fornito - /// - /// - public async Task InvalidateCache(string cachePattern) - { - foreach (var item in cachedDataList) - { - if (item.Contains(cachePattern)) - { - await distributedCache.RemoveAsync(item); - } - } - } - - /// - /// Statistiche ultime settimane - /// - /// - /// - /// - /// - public async Task> LastWeeks(int idxDipendente, DateTime dtRif, int numWeek) - { - List? dbResult = new List(); - string currKey = $"{rKeyWeekStats}:{idxDipendente}:{dtRif.ToString("yyyy-MM-dd")}:{numWeek}"; - 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.WeekOverview(idxDipendente, dtRif, numWeek); - 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 LastWeeks: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Elenco pareto progetti ordinati da filtro - /// - /// - /// - /// - /// - public async Task> ParetoRegAtt(int idxDip, int numDayPrev, int maxResult) - { - List? dbResult = new List(); - string currKey = $"{rKeyParetoRegAtt}:{idxDip}:{numDayPrev}:{maxResult}"; - - DateTime dataFine = DateTime.Today.AddDays(1); - DateTime dataInizio = dataFine.AddDays(-numDayPrev); - - 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.ParetoRegAtt(idxDip, dataInizio, dataFine, maxResult); - 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 ParetoRegAtt: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - public async Task RegAttDelete(RegAttivitaModel currItem) - { - bool answ = false; - try - { - dbController.RegAttDelete(currItem); - // invalido la cache... - await InvalidateAllCache(); - answ = true; - } - catch - { } - return answ; - } - - /// - /// Recupera ultima attività dipendente - /// - /// - /// cerca ultima solo tra attive (=true) o tutte (=false) - /// - public async Task RegAttLastByDip(int IdxDipendente, bool onlyActive) - { - RegAttivitaModel dbResult = dbController.RegAttLastByDip(IdxDipendente, onlyActive); - return dbResult; - } - - public async Task RegAttUpdate(RegAttivitaModel currItem) - { - bool answ = false; - try - { - dbController.RegAttUpdate(currItem); - // invalido la cache... - await InvalidateAllCache(); - answ = true; - } - catch - { } - return answ; - } - - /// - /// Effettua eliminazione record registro malattie (SE non confermato) - /// - /// - /// - public async Task RegMalattieDelete(RegMalattieModel currItem) - { - bool answ = false; - try - { - answ = dbController.RegMalattieDelete(currItem); - if (answ) - { - // gestisco email notifica... - string emailDest = _configuration["MailDest:InfoMal"]; - string urlRedir = _configuration["AdmApp:LinkMal"]; - StringBuilder sbMain = new StringBuilder(); - DateTime adesso = DateTime.Now; - sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato rimosso un record di registrazione malattia"); - sbMain.AppendLine(""); - sbMain.Append("
"); - sbMain.Append($"{currItem.DipNav.Cognome} {currItem.DipNav.Nome} ({currItem.DipNav.Matricola})"); - //sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - sbMain.Append("
"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Data Inizio: {currItem.DtInizio}"); - sbMain.AppendLine($"Numero Giorni: {currItem.NumGG}"); - sbMain.AppendLine($"Certificato: {currItem.CodCert}"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - string msgBody = sbMain.ToString(); - await sendEmail(emailDest, "Eliminazione record Malattia Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); - } - // invalido la cache... - await InvalidateAllCache(); - } - catch - { } - return answ; - } - - /// - /// Restituisce elenco malattie dipendente - /// - /// Dipendente interessato - /// max record da recuperare - /// - public async Task> RegMalattieGetByDip(int idxDipendente, int maxRecord) - { - List? dbResult = new List(); - string currKey = $"{rKeyDipendenti}:{idxDipendente}:RegMal:{maxRecord}"; - 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.RegMalattieGetByDip(idxDipendente, maxRecord); - 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 GetRegMalattieDip: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - /// - /// Restituisce elenco malattie globali - /// - /// max record da recuperare - /// - public async Task> RegMalattieGetAll(int maxRecord) - { - List? dbResult = new List(); - string currKey = $"{rKeyDipendenti}:ALL:RegMal:{maxRecord}"; - 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.RegMalattieGetAll(maxRecord); - 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 RegMalattieGetAll: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Registra o aggiorna record registro malattie - /// - /// - /// - public async Task RegMalattieUpsert(RegMalattieModel currItem) - { - bool answ = false; - try - { - // scrivo su DB - answ = dbController.RegMalattieUpsert(currItem); - if (answ) - { - // recupero info dipendente - var listDip = await DipendentiGetAll(); - var currDip = listDip.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente); - // gestisco email notifica... - string emailDest = _configuration["MailDest:InfoMal"]; - string urlRedir = _configuration["AdmApp:LinkMal"]; - StringBuilder sbMain = new StringBuilder(); - DateTime adesso = DateTime.Now; - sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato inserito un nuovo record di registrazione malattia"); - sbMain.AppendLine(""); - sbMain.Append("
"); - sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - sbMain.Append("
"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Data Inizio: {currItem.DtInizio}"); - sbMain.AppendLine($"Numero Giorni: {currItem.NumGG}"); - sbMain.AppendLine($"Certificato: {currItem.CodCert}"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - - string msgBody = sbMain.ToString(); - await sendEmail(emailDest, "Nuovo record Malattia Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); - } - // invalido la cache... - await InvalidateAllCache(); - } - catch - { } - return answ; - } - - /// - /// Effettua eliminazione record registro richieste dipendente (SE non confermato) - /// - /// - /// - public async Task RegRichiesteDelete(RegRichiesteModel currItem) - { - bool answ = false; - try - { - answ = dbController.RegRichiesteDelete(currItem); - if (answ) - { - // gestisco email notifica... - string emailDest = _configuration["MailDest:InfoRich"]; - string urlRedir = _configuration["AdmApp:LinkRich"]; - StringBuilder sbMain = new StringBuilder(); - DateTime adesso = DateTime.Now; - sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato rimosso un record di registrazione richiesta utente"); - sbMain.AppendLine(""); - sbMain.Append("
"); - sbMain.Append($"{currItem.DipNav.Cognome} {currItem.DipNav.Nome} ({currItem.DipNav.Matricola})"); - //sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - sbMain.Append("
"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Richiesta: {currItem.CodGiust}"); - sbMain.AppendLine($"Periodo: {currItem.DtStart} --> {currItem.DtEnd}"); - sbMain.AppendLine($"Note: {currItem.Note}"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - string msgBody = sbMain.ToString(); - await sendEmail(emailDest, $"Eliminazione Richiesta Dipendente | {currItem.CodGiust}", msgBody.Replace($"{Environment.NewLine}", "
")); - } - // invalido la cache... - await InvalidateAllCache(); - } - catch - { } - return answ; - } - - /// - /// Restituisce elenco richieste dipendente - /// - /// Dipendente interessato - /// Inizio periodo richiesto - /// Fine periodo richiesto - /// - public async Task> RegRichiesteGetByDip(int idxDipendente, DateTime dtFrom, DateTime dtTo) - { - List? dbResult = new List(); - string currKey = $"{rKeyDipendenti}:{idxDipendente}:RegRichieste:{dtFrom:yyyyMMdd}:{dtTo:yyyyMMdd}"; - 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.RegRichiesteGetByDip(idxDipendente, dtFrom, dtTo); - 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 RegRichiesteGetByDip: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - /// - /// Registra o aggiorna record registro richieste - /// - /// - /// - public async Task RegRichiesteUpsert(RegRichiesteModel currItem) - { - bool answ = false; - try - { - // scrivo su DB - answ = dbController.RegRichiesteUpsert(currItem); - if (answ) - { - // recupero info dipendente - var listDip = await DipendentiGetAll(); - var currDip = listDip.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente); - // gestisco email notifica... - string emailDest = _configuration["MailDest:InfoRich"]; - string urlRedir = _configuration["AdmApp:LinkRich"]; - StringBuilder sbMain = new StringBuilder(); - DateTime adesso = DateTime.Now; - sbMain.AppendLine($"Il giorno {adesso:yyyy.MM.dd} alle ore {adesso:HH:mm:ss} è stato inserito una nuova richiesta dipendente"); - sbMain.AppendLine(""); - sbMain.Append("
"); - sbMain.Append($"{currDip.Cognome} {currDip.Nome} ({currDip.Matricola})"); - sbMain.Append("
"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Richiesta: {currItem.CodGiust}"); - sbMain.AppendLine($"Periodo: {currItem.DtStart} --> {currItem.DtEnd}"); - sbMain.AppendLine($"Note: {currItem.Note}"); - sbMain.AppendLine("
"); - sbMain.AppendLine($"Cliccare sul seguente link per accedere alla pagina di gestione"); - - string msgBody = sbMain.ToString(); - await sendEmail(emailDest, $"Nuovo record Richiesta {currItem.CodGiust} Dipendente", msgBody.Replace($"{Environment.NewLine}", "
")); - } - // invalido la cache... - await InvalidateAllCache(); - } - catch - { } - return answ; - } - - /// - /// Recupera l'elenco dei Rilievi temperatura nel periodo indicato x dipendente - /// - /// Dipendente interessato - /// Data di riferimento (ultima/corrente) - /// NUm settimane precedenti da recuperare - /// - public async Task> RilTempList(int idxDipendente, DateTime dtInizio, DateTime dtFine) - { - List? dbResult = new List(); - string currKey = $"{rKeyRilTemp}:{dtInizio:yyyyMMdd}:{dtFine:yyyMMdd}"; - 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.RilTempList(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 RilTempList: {ts.TotalMilliseconds} ms"); - } - if (dbResult == null) - { - dbResult = new List(); - } - return dbResult; - } - - public async Task RilTempUpdate(RilievoTempModel currItem) - { - bool answ = false; - try - { - dbController.RilTempUpdate(currItem); - // invalido la cache... - await InvalidateCache(rKeyRilTemp); - //await InvalidateCache($"{rKeyWeekStats}:{currItem.IdxDipendente}"); - await InvalidateCache($"{rKeyDailyData}:{currItem.IdxDipendente}"); - answ = true; - } - catch - { } - return answ; - } -#endif -#if false - /// - /// Elenco timbrature di un giorno - /// - /// - /// - /// - public async Task> TimbratureDay(DateTime dateRif, int IdxDip) - { - List? dbResult = new List(); - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - dbResult = dbController.TimbratureDay(dateRif, IdxDip); - stopWatch.Stop(); - TimeSpan ts = stopWatch.Elapsed; - Log.Trace($"Effettuata lettura da DB + caching per TimbratureDay: {ts.TotalMilliseconds} ms"); - return dbResult; - } - - public async Task TimbratureDelete(TimbratureModel currItem) - { - bool answ = false; - try - { - dbController.TimbratureDelete(currItem); - // invalido la cache... - await InvalidateAllCache(); - answ = true; - } - catch - { } - return answ; - } - - public async Task TimbratureUpdate(TimbratureModel currItem) - { - bool answ = false; - try - { - dbController.TimbratureUpdate(currItem); - // invalido la cache... - await InvalidateAllCache(); - answ = true; - } - catch - { } - return answ; - } -#endif } } \ No newline at end of file diff --git a/GPW.CORE.WRKLOG/Components/DayCheckEditor.razor.cs b/GPW.CORE.WRKLOG/Components/DayCheckEditor.razor.cs index 3588a20..9fc08c4 100644 --- a/GPW.CORE.WRKLOG/Components/DayCheckEditor.razor.cs +++ b/GPW.CORE.WRKLOG/Components/DayCheckEditor.razor.cs @@ -1,3 +1,4 @@ +using GPW.CORE.Comp; using GPW.CORE.Data.DbModels; using Microsoft.AspNetCore.Components; diff --git a/GPW.CORE.WRKLOG/Components/TimbList.razor b/GPW.CORE.WRKLOG/Components/TimbList.razor index 157b607..764c5b6 100644 --- a/GPW.CORE.WRKLOG/Components/TimbList.razor +++ b/GPW.CORE.WRKLOG/Components/TimbList.razor @@ -27,7 +27,14 @@ } - + @if (EnableEdit) + { + + } + else + { + + } @if (@item.Entrata == false) @@ -36,9 +43,15 @@ } - + @if (EnableEdit) + { + + } + else + { + + } - } @@ -65,6 +78,9 @@ } } + [Parameter] + public bool EnableEdit { get; set; } = false; + [Parameter] public EventCallback ReqDelete { get; set; } diff --git a/GPW.CORE.WRKLOG/Components/TimbrEditor.razor b/GPW.CORE.WRKLOG/Components/TimbrEditor.razor index f7a7542..4e17062 100644 --- a/GPW.CORE.WRKLOG/Components/TimbrEditor.razor +++ b/GPW.CORE.WRKLOG/Components/TimbrEditor.razor @@ -75,7 +75,7 @@
@if (ListTimbRich != null) { - + } else { diff --git a/GPW.CORE.WRKLOG/GPW.CORE.WRKLOG.csproj b/GPW.CORE.WRKLOG/GPW.CORE.WRKLOG.csproj index aafb9ff..9c1fe2e 100644 --- a/GPW.CORE.WRKLOG/GPW.CORE.WRKLOG.csproj +++ b/GPW.CORE.WRKLOG/GPW.CORE.WRKLOG.csproj @@ -7,8 +7,15 @@ enable + + + + + + + diff --git a/GPW.CORE.WRKLOG/Pages/Test.razor.cs b/GPW.CORE.WRKLOG/Pages/Test.razor.cs index e8e7e3c..008d7de 100644 --- a/GPW.CORE.WRKLOG/Pages/Test.razor.cs +++ b/GPW.CORE.WRKLOG/Pages/Test.razor.cs @@ -16,6 +16,7 @@ using GPW.CORE.WRKLOG.Shared; using GPW.CORE.WRKLOG.Components; using GPW.CORE.Data.DbModels; using GPW.CORE.WRKLOG.Data; +using GPW.CORE.Comp; namespace GPW.CORE.WRKLOG.Pages {