b1afa82a91
- GpwDataSrvice - MessageService - ogni dipendenza (aggiunti using, in _import non basta...)
223 lines
7.2 KiB
C#
223 lines
7.2 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.DTO;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.WRKLOG.Components.Pages
|
|
{
|
|
public partial class Presenze : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
UITimer?.Dispose();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected DateTime lastRefresh = DateTime.Now;
|
|
|
|
/// <summary>
|
|
/// Timer per refresh dati
|
|
///
|
|
/// https://stackoverflow.com/questions/63060065/blazor-timer-call-async-api-task-to-update-ui https://www.janduniec.blog/index.php/100/timers-in-blazor/
|
|
/// </summary>
|
|
protected System.Timers.Timer UITimer = new System.Timers.Timer();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Fields
|
|
|
|
private int _endHour = 18;
|
|
|
|
private int _startHour = 8;
|
|
|
|
private DateTime DtSelected = DateTime.Today;
|
|
|
|
private int IdxDipendente = 0;
|
|
|
|
private List<AnagFasiModel> ListFasi = new List<AnagFasiModel>();
|
|
|
|
private List<DailyDataDTO>? ListRecords = null;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int endHour
|
|
{
|
|
get => _endHour;
|
|
set
|
|
{
|
|
// fix --> max 24...
|
|
_endHour = value < 25 ? value : 24;
|
|
}
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int startHour
|
|
{
|
|
get => _startHour;
|
|
set
|
|
{
|
|
// fix --> MIN 0...
|
|
_startHour = value > 0 ? value : 0;
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void checkHourRange()
|
|
{
|
|
int minHour = 12;
|
|
int maxHour = 14;
|
|
int currStart = 12;
|
|
int currEnd = 12;
|
|
int roundMin = 30;
|
|
//int extraEnd = 30;
|
|
if (ListRecords != null)
|
|
{
|
|
// per ogni giornata
|
|
foreach (var giornata in ListRecords)
|
|
{
|
|
if (giornata.ListTimbr != null)
|
|
{
|
|
var minRecTimb = giornata.ListTimbr
|
|
.Where(x => x.Entrata == true)
|
|
.OrderBy(x => x.DataOra)
|
|
.FirstOrDefault();
|
|
if (minRecTimb != null)
|
|
{
|
|
if (minHour > minRecTimb.DataOra.AddMinutes(roundMin / 3).Hour)
|
|
{
|
|
minHour = minRecTimb.DataOra.AddMinutes(roundMin / 3).Hour;
|
|
}
|
|
}
|
|
var maxRecTimb = giornata.ListTimbr
|
|
.Where(x => x.Entrata == false)
|
|
.OrderByDescending(x => x.DataOra)
|
|
.FirstOrDefault();
|
|
if (maxRecTimb != null)
|
|
{
|
|
if (maxHour < maxRecTimb.DataOra.AddMinutes(-roundMin / 3).Hour)
|
|
{
|
|
maxHour = maxRecTimb.DataOra.AddMinutes(-roundMin / 3).Hour + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (giornata.ListRA != null)
|
|
{
|
|
var minRecRa = giornata.ListRA
|
|
.OrderBy(x => x.Inizio)
|
|
.FirstOrDefault();
|
|
if (minRecRa != null)
|
|
{
|
|
// verifico se cambia giorno inizio/fine --> seleziono la mezzanotte
|
|
currStart = minRecRa.Inizio.AddMinutes(-roundMin).Date.Equals(minRecRa.Fine.Date) ? minRecRa.Inizio.AddMinutes(-roundMin).Hour : 0;
|
|
if (minHour > currStart)
|
|
{
|
|
minHour = currStart;
|
|
}
|
|
}
|
|
var maxRecRa = giornata.ListRA
|
|
.OrderByDescending(x => x.Fine)
|
|
.FirstOrDefault();
|
|
if (maxRecRa != null)
|
|
{
|
|
// verifico se cambia giorno inizio/fine --> seleziono la mezzanotte
|
|
currEnd = maxRecRa.Inizio.Date.Equals(maxRecRa.Fine.AddMinutes(roundMin).Date) ? maxRecRa.Fine.AddMinutes(roundMin).Hour + 1 : 24;
|
|
if (maxHour < currEnd)
|
|
{
|
|
maxHour = currEnd;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
startHour = minHour;// - 1;
|
|
checkOrarioDip();
|
|
// minimo 6 h... x cui "allungo" verso fine
|
|
if (maxHour - minHour < AppMServ.orarioDip)
|
|
{
|
|
minHour--;
|
|
maxHour = minHour + AppMServ.orarioDip;
|
|
}
|
|
endHour = maxHour;// + 1;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
ListRecords = null;
|
|
await InvokeAsync(StateHasChanged);
|
|
await Task.Delay(1);
|
|
|
|
await TryReload();
|
|
// avvio un timer infinito x refresh pagina COMUNQUE ogni 60 sec anche non succedesse nulla...
|
|
UITimer = new System.Timers.Timer
|
|
{
|
|
Interval = 1000 * 60,
|
|
AutoReset = true,
|
|
Enabled = true
|
|
};
|
|
UITimer.Elapsed += async (s, ea) => await TryReload();
|
|
}
|
|
|
|
protected async Task TryReload()
|
|
{
|
|
// effettuo reload SOLO SE no ho editing in corso...
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private void checkOrarioDip()
|
|
{
|
|
// calcolo minimo da cod orario dipendente
|
|
if (AppMServ.orarioDip == 0)
|
|
{
|
|
AnagOrariModel? schemaOrario = null;
|
|
// recupero da DB schema settimanale...
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
schemaOrario = await GDataServ.AnagOrarioByDip(AppMServ.IdxDipendente);
|
|
});
|
|
pUpd.Wait();
|
|
if (schemaOrario != null)
|
|
{
|
|
AppMServ.orarioDip = (int)(Math.Ceiling(schemaOrario.oreOrdSett / 5));
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
UITimer.Stop();
|
|
ListRecords = await GDataServ.DailyDetailAllDip(DtSelected);
|
|
await Task.Delay(1);
|
|
checkHourRange();
|
|
await Task.Delay(1);
|
|
lastRefresh = DateTime.Now;
|
|
UITimer.Start();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |