b1afa82a91
- GpwDataSrvice - MessageService - ogni dipendenza (aggiunti using, in _import non basta...)
150 lines
4.3 KiB
C#
150 lines
4.3 KiB
C#
using EgwCoreLib.Razor.Data;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace GPW.CORE.WRKLOG.Components.Compo
|
|
{
|
|
public partial class DayCheckEditor
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> CloseReq { get; set; }
|
|
|
|
[Parameter]
|
|
public bool IsPortrait { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public DateTime TargetDate
|
|
{
|
|
get => _targetDate;
|
|
set => _targetDate = value;
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected int _numDays = 30;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected DateTime _targetDate { get; set; } = DateTime.Today;
|
|
|
|
protected RilievoTempModel? currRecord { get; set; } = null;
|
|
|
|
protected string[]? histData { get; set; } = null;
|
|
|
|
protected string[]? histLabel { get; set; } = null;
|
|
|
|
protected List<chartJsData.chartJsTSerie>? listRilTemp { get; set; } = null;
|
|
|
|
protected List<CheckVc19Model>? listVC19 { get; set; } = null;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void DoClose()
|
|
{
|
|
await CloseReq.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio misurazione temperatura
|
|
/// </summary>
|
|
protected async void DoSave()
|
|
{
|
|
// chiamo classe gestione che salva e resetta cache dati...
|
|
if (currRecord != null)
|
|
{
|
|
await GDataServ.RilTempUpdate(currRecord);
|
|
}
|
|
|
|
// chiamo chiusura!
|
|
await CloseReq.InvokeAsync(true);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task ReloadData()
|
|
{
|
|
DateTime inizio = TargetDate.AddDays(1 - numDays);
|
|
DateTime fine = TargetDate.AddDays(1);
|
|
// recupero dati completi...
|
|
var rawVC19 = await GDataServ.CheckVC19List(AppMServ.IdxDipendente, fine.AddDays(-15), fine);
|
|
var rawData = await GDataServ.RilTempList(AppMServ.IdxDipendente, inizio, fine);
|
|
|
|
// calcolo dati derivati
|
|
listVC19 = rawVC19.OrderByDescending(x => x.DtCheck).ToList();
|
|
listRilTemp = rawData.Select(r => new chartJsData.chartJsTSerie()
|
|
{ x = r.DtRilievo, y = r.TempRil }).ToList();
|
|
|
|
// calcolo hist frequenza con EFCore: https://entityframeworkcore.com/knowledge-base/60871048/group-by-and-to-dictionary-in-ef-core-3-1
|
|
var histDict = rawData.GroupBy(r => r.TempRil.ToString("N1")).Select(g => new
|
|
{
|
|
g.Key,
|
|
Count = g.Count()
|
|
}).OrderBy(d => d.Key).ToDictionary(x => x.Key, x => x.Count.ToString());
|
|
histData = histDict.Values.ToArray();
|
|
histLabel = histDict.Keys.ToArray();
|
|
// cerco se c'� dato odierno della temperatura...
|
|
currRecord = rawData.Where(x => x.DtRilievo == TargetDate).FirstOrDefault();
|
|
if (currRecord == null)
|
|
{
|
|
currRecord = new RilievoTempModel()
|
|
{ IdxDipendente = AppMServ.IdxDipendente, DtRilievo = TargetDate, TempRil = 0 };
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private MessageService AppMServ { get; set; } = null!;
|
|
|
|
private string cssCheck
|
|
{
|
|
get => IsPortrait ? "col-12" : "col-4";
|
|
}
|
|
|
|
private string cssTemp
|
|
{
|
|
get => IsPortrait ? "col-6" : "col-4";
|
|
}
|
|
|
|
[Inject]
|
|
private GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
private int numDays
|
|
{
|
|
get
|
|
{
|
|
return _numDays;
|
|
}
|
|
|
|
set
|
|
{
|
|
_numDays = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |