Gestiti salvataggi rest

This commit is contained in:
2026-03-02 10:50:34 +01:00
parent e027d8e5cf
commit ab9578a45f
58 changed files with 1235 additions and 305 deletions

View File

@@ -1,5 +1,8 @@
@using CommunityToolkit.Mvvm.Messaging
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.System.Network
@using SteUp.Shared.Core.Messages.Ispezione
@using SteUp.Shared.Core.Messages.Scheda
@inject INetworkService NetworkService
@inject IDialogService Dialog
@@ -31,17 +34,24 @@
@if (PlusVisible)
{
<MudFabMenu ButtonClass="custom-plus-button" MenuClass="custom-menu-fab" OnClick="@OnOpenMenu" StartIcon="@Icons.Material.Filled.Add"
IconColor="Color.Primary" Color="Color.Surface" AlignItems="AlignItems.End"
<MudFabMenu ButtonClass="custom-plus-button" MenuClass="custom-menu-fab" OnClick="@OnOpenMenu"
StartIcon="@Icons.Material.Filled.Add"
IconColor="Color.Primary" Color="Color.Surface" AlignItems="AlignItems.End"
Size="Size.Medium" IconSize="Size.Medium">
@if (SchedaVisible)
{
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewScheda"
if (ShowCompleteInspection)
{
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@CompleteInspection"
Label="Concludi ispezione" Color="Color.Surface"/>
}
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewScheda"
Label="Nuova scheda" Color="Color.Surface"/>
}
else
{
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewActivity"
<MudFabMenuItem Disabled="!NetworkService.IsNetworkAvailable()" OnClick="@NewActivity"
Label="Nuova ispezione" Color="Color.Surface"/>
}
</MudFabMenu>
@@ -53,6 +63,7 @@
{
private bool IsVisible { get; set; } = true;
private bool PlusVisible { get; set; } = true;
private bool ShowCompleteInspection { get; set; }
private bool SchedaVisible { get; set; }
protected override Task OnInitializedAsync()
@@ -81,6 +92,9 @@
_ = ModalHelper.OpenSelectShop(Dialog);
}
private void CompleteInspection() =>
Messenger.Send(new CompleteInspectionMessage());
private async Task NewScheda()
{
var ispezione = SteupDataService.InspectionPageState.Ispezione;
@@ -95,6 +109,7 @@
var location = NavigationManager.Uri.Remove(0, NavigationManager.BaseUri.Length);
SchedaVisible = new List<string> { "ispezione" }.Contains(location);
ShowCompleteInspection = !SteupDataService.InspectionPageState.Ispezione.ActivityId.IsNullOrEmpty();
StateHasChanged();
}
}

View File

@@ -1,13 +1,19 @@
@page "/ispezione"
@using SteUp.Shared.Components.Layout
@using SteUp.Shared.Components.Layout.Overlay
@using SteUp.Shared.Components.SingleElements.Card
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Enum
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.LocalDb
@using SteUp.Shared.Core.Messages.Ispezione
@using SteUp.Shared.Core.Messages.Scheda
@inject NewSchedaService NewScheda
@inject CompleteInspectionService CompleteInspection
@inject IIspezioniService IspezioniService
@inject IDialogService Dialog
@inject IIntegrySteupService IntegrySteupService
@implements IDisposable
<HeaderLayout Title="Ispezione" BackTo="Indietro" Back="true"/>
@@ -30,9 +36,23 @@
</MudChip>
</div>
<div class="action-scheda-group">
<MudIconButton Variant="Variant.Filled" Icon="@Icons.Material.Rounded.Add"
Color="Color.Warning" Size="Size.Medium"
OnClick="@(() => CreateNewScheda(group.Key))"/>
@if (NetworkService.IsNetworkAvailable())
{
<MudFab StartIcon="@Icons.Material.Rounded.Add"
Color="Color.Warning" Size="Size.Small"
OnClick="@(() => CreateNewScheda(group.Key))"/>
<MudFab StartIcon="@Icons.Material.Rounded.CloudSync" Label="Esporta reparto"
Color="Color.Success" Size="Size.Small"
OnClick="@(() => ExportReparto(group.Key))"/>
}
else
{
<MudFab StartIcon="@Icons.Material.Rounded.Add"
Label="@($"Nuova scheda su {group.Key.Descrizione}")"
Color="Color.Warning" Size="Size.Medium"
OnClick="@(() => CreateNewScheda(group.Key))"/>
}
</div>
</div>
</TitleContent>
@@ -51,13 +71,18 @@
}
</div>
<SpinnerOverlay VisibleOverlay="VisibleOverlay"/>
@code {
private List<Scheda> SchedeList { get; set; } = [];
private Dictionary<JtbFasiDto, List<Scheda>> SchedeGrouped { get; set; } = [];
private bool VisibleOverlay { get; set; }
protected override void OnInitialized()
{
NewScheda.OnNewScheda += LoadSchede;
CompleteInspection.OnComplete += HandleCompleteInspection;
LoadSchede();
}
@@ -77,6 +102,48 @@
});
}
private async void HandleCompleteInspection()
{
try
{
await InvokeAsync(() =>
{
VisibleOverlay = true;
StateHasChanged();
});
var ispezione = SteupDataService.InspectionPageState.Ispezione;
SteupDataService.InspectionPageState.Ispezione.Stato = StatusEnum.Completata;
await IntegrySteupService.CompleteInspection(ispezione.ActivityId!);
await IspezioniService.UpdateStatoIspezioneAsync(
ispezione.CodMdep,
ispezione.Data,
ispezione.Rilevatore,
StatusEnum.Completata
);
await InvokeAsync(() =>
{
VisibleOverlay = false;
StateHasChanged();
});
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await InvokeAsync(() =>
{
VisibleOverlay = false;
StateHasChanged();
});
OnError(e.Message);
}
}
private void GroupSchede()
{
SchedeGrouped = SchedeList
@@ -114,12 +181,76 @@
new Scheda { Reparto = jtbFasi }
);
if (modal is {Canceled: false}) LoadSchede();
if (modal is { Canceled: false }) LoadSchede();
}
private async Task ExportReparto(JtbFasiDto jtbFasi)
{
VisibleOverlay = true;
StateHasChanged();
var ispezione = SteupDataService.InspectionPageState.Ispezione;
var saveRequest = SchedeGrouped[jtbFasi].ConvertAll(x =>
{
return new SaveRequestDto
{
LocalIdScheda = x.Id,
ActivityTypeId = x.ActivityTypeId,
CodJfas = x.CodJfas,
CodMdep = ispezione.CodMdep,
DataCreazione = ispezione.Data,
Note = x.Note,
PersonaRif = x.Responsabile,
Barcodes = x.Articoli.ConvertAll(y => y.Barcode),
Scandeza = (ScadenzaEnum)x.Scadenza,
ParentActivityId = x.Ispezione?.ActivityId
};
});
var apiResponse = await IntegrySteupService.SaveMultipleSchede(saveRequest);
if (apiResponse != null)
{
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
await IspezioniService.UpdateActivityIdIspezioneAsync(ispezione.CodMdep, ispezione.Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
if (apiResponse.ActivityIdSchedaList.IsNullOrEmpty()) return;
foreach (var scheda in SchedeGrouped[jtbFasi])
{
scheda.ActivityId = apiResponse.ActivityIdScheda;
await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId);
var activityId = apiResponse.ActivityIdSchedaList!.Find(x =>
x.LocalId != null && x.LocalId == scheda.Id
)?.ActivityId;
if (activityId == null) return;
scheda.ActivityId = activityId;
await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId);
}
}
VisibleOverlay = false;
StateHasChanged();
}
private void OnError(string? errorMessage)
{
if (errorMessage == null) return;
_ = ModalHelper.ShowError(Dialog, errorMessage);
}
void IDisposable.Dispose()
{
NewScheda.OnNewScheda -= LoadSchede;
CompleteInspection.OnComplete -= HandleCompleteInspection;
}
}

View File

@@ -2,4 +2,10 @@
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.action-scheda-group {
display: flex;
align-items: center;
justify-content: space-around;
}

View File

@@ -100,6 +100,8 @@ else
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Spinner = false;
StateHasChanged();

View File

@@ -0,0 +1,2 @@
@using SteUp.Shared.Components.Layout.Spinner
<SpinnerLayout FullScreen="true"/>

View File

@@ -1,3 +1,4 @@
@using SteUp.Shared.Components.Pages.Utility
@using SteUp.Shared.Components.SingleElements.Modal.ExceptionModal
@using SteUp.Shared.Core.BarcodeReader.Contracts
@inject NavigationManager NavigationManager
@@ -8,21 +9,29 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Routes).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
<Authorizing>
<p>Authorizing page</p>
</Authorizing>
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
NavigationManager.NavigateTo("/login");
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
@if (!LoadData)
{
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
<Authorizing>
<AuthorizingPage/>
</Authorizing>
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
NavigationManager.NavigateTo("/login");
}
else
{
<p role="alert">You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
}
else
{
<AuthorizingPage/>
}
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found>
</Router>
@@ -38,13 +47,21 @@
</ErrorBoundary>
@code {
private bool LoadData { get; set; }
private ErrorBoundary? ErrorBoundary { get; set; }
private ExceptionModal ExceptionModal { get; set; } = null!;
protected override async Task OnInitializedAsync()
{
LoadData = true;
StateHasChanged();
await SteupDataService.Init();
BarcodeManager.Init();
LoadData = false;
StateHasChanged();
}
}

View File

@@ -1,8 +1,12 @@
@using SteUp.Shared.Components.Layout.Overlay
@using SteUp.Shared.Components.SingleElements.MessageBox
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Enum
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.LocalDb
@inject IIspezioniService IspezioniService
@inject IIntegrySteupService IntegrySteupService
@inject IDialogService Dialog
<div class="scheda-card">
@@ -14,36 +18,48 @@
<div class="sub-info-section">
<MudChip T="string" Icon="@Icons.Material.Rounded.PhotoCamera" Size="Size.Small" Color="Color.Default">
0
@Scheda.ImageNames.Count()
</MudChip>
<MudChip T="string" Icon="@Icons.Material.Rounded.QrCode2" Size="Size.Small" Color="Color.Default">
0
@Scheda.Articoli.Count
</MudChip>
</div>
</div>
<div class="scheda-card-action">
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Rounded.Edit"
Color="Color.Info" Size="Size.Small" OnClick="@UpdateScheda">
Modifica
</MudButton>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Rounded.Delete"
Color="Color.Error" Size="Size.Small" OnClick="@DeleteScheda">
Cancella
</MudButton>
@if (NetworkService.IsNetworkAvailable())
{
<MudFab Color="Color.Info" Size="Size.Small" StartIcon="@Icons.Material.Rounded.Edit" OnClick="@UpdateScheda"/>
<MudFab Color="Color.Error" Size="Size.Small" StartIcon="@Icons.Material.Rounded.Delete" OnClick="@DeleteScheda"/>
<MudFab Color="Color.Success" Size="Size.Small" StartIcon="@Icons.Material.Rounded.CloudSync" OnClick="@ExportScheda"/>
}
else
{
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Rounded.Edit"
Color="Color.Info" Size="Size.Small" OnClick="@UpdateScheda">
Modifica
</MudButton>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Rounded.Delete"
Color="Color.Error" Size="Size.Small" OnClick="@DeleteScheda">
Cancella
</MudButton>
}
</div>
</div>
</div>
<SpinnerOverlay VisibleOverlay="VisibleOverlay"/>
<ConfirmDeleteMessageBox @ref="_deleteMessageBox" Message="Confermi la cancellazione della scheda corrente?"/>
@code{
[Parameter] public string CodMdep { get; set; } = string.Empty;
[Parameter] public DateOnly Data { get; set; }
[Parameter] public DateTime Data { get; set; }
[Parameter] public required Scheda Scheda { get; set; }
[Parameter] public EventCallback<Scheda> OnSchedaModified { get; set; }
[Parameter] public EventCallback<Scheda> OnSchedaDeleted { get; set; }
private bool VisibleOverlay { get; set; }
private ConfirmDeleteMessageBox _deleteMessageBox = null!;
private async Task UpdateScheda()
@@ -63,4 +79,40 @@
}
}
private async Task ExportScheda()
{
VisibleOverlay = true;
StateHasChanged();
var apiResponse = await IntegrySteupService.SaveScheda(
new SaveRequestDto
{
LocalIdScheda = Scheda.Id,
ActivityTypeId = Scheda.ActivityTypeId,
CodJfas = Scheda.CodJfas,
CodMdep = CodMdep,
DataCreazione = Data,
Note = Scheda.Note,
PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza,
ParentActivityId = Scheda.Ispezione?.ActivityId
}
);
if (apiResponse != null)
{
Scheda.ActivityId = apiResponse.ActivityIdScheda;
SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione;
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId);
}
VisibleOverlay = false;
StateHasChanged();
}
}

View File

@@ -47,7 +47,7 @@
SteupDataService.InspectionPageState.Ispezione = await IspezioniService.GetOrCreateIspezioneAsync(
PuntoVendita.CodMdep!,
DateOnly.FromDateTime(DateTime.Today),
DateTime.Now,
UserSession.User.Username
);

View File

@@ -5,10 +5,10 @@
@using SteUp.Shared.Components.SingleElements.MessageBox
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Entities
@using SteUp.Shared.Core.Enum
@using SteUp.Shared.Core.Interface.IntegryApi
@using SteUp.Shared.Core.Interface.LocalDb
@using SteUp.Shared.Core.Interface.System
@using SteUp.Shared.Core.Interface.System.Network
@using SteUp.Shared.Core.Messages.Scanner
@inject INetworkService NetworkService
@inject IDialogService Dialog
@@ -27,7 +27,7 @@
<div class="content">
<CardFormModal Title="Reparto" Loading="SteupDataService.Reparti.IsNullOrEmpty()">
<MudSelectExtended ReadOnly="IsView" T="JtbFasiDto?" Variant="Variant.Text"
<MudSelectExtended T="JtbFasiDto?" Variant="Variant.Text"
@bind-Value="Scheda.Reparto" ToStringFunc="@(x => x?.Descrizione)"
@bind-Value:after="OnAfterChangeReparto" Required="true"
RequiredError="Reparto obbligatorio">
@@ -41,7 +41,7 @@
</CardFormModal>
<CardFormModal Title="Motivo" Loading="SteupDataService.TipiAttività.IsNullOrEmpty()">
<MudSelectExtended ReadOnly="@(IsView || Scheda.CodJfas.IsNullOrEmpty())" T="string?"
<MudSelectExtended ReadOnly="@Scheda.CodJfas.IsNullOrEmpty()" T="string?"
Variant="Variant.Text"
@bind-Value="Scheda.ActivityTypeId" @bind-Value:after="OnAfterChangeValue"
Required="true" RequiredError="Motivo obbligatorio">
@@ -75,10 +75,13 @@
}
<MudCardContent Class="image_card">
<MudText Typo="Typo.subtitle1"><b>@item.p.Name</b></MudText>
<MudIconButton Variant="Variant.Outlined"
Icon="@Icons.Material.Rounded.Close"
Size="Size.Small" Color="Color.Error"
OnClick="@(() => OnRemoveAttached(item.index))"/>
@if (IsNew)
{
<MudIconButton Variant="Variant.Outlined"
Icon="@Icons.Material.Rounded.Close"
Size="Size.Small" Color="Color.Error"
OnClick="@(() => OnRemoveAttached(item.index))"/>
}
</MudCardContent>
</MudCard>
}
@@ -87,19 +90,16 @@
</CardFormModal>
}
@if (!IsView)
{
<div class="container-button ripple-container">
<MudButton Class="button-settings green-icon"
FullWidth="true"
StartIcon="@Icons.Material.Rounded.AttachFile"
Size="Size.Medium"
OnClick="@OpenAddAttached"
Variant="Variant.Outlined">
Aggiungi foto
</MudButton>
</div>
}
<div class="container-button ripple-container">
<MudButton Class="button-settings green-icon"
FullWidth="true"
StartIcon="@Icons.Material.Rounded.AttachFile"
Size="Size.Medium"
OnClick="@OpenAddAttached"
Variant="Variant.Outlined">
Aggiungi foto
</MudButton>
</div>
<CardFormModal Title="Articoli">
<div class="input-manual-barcode">
@@ -113,7 +113,8 @@
<div class="art-list">
@foreach (var articolo in Scheda.Articoli)
{
<MudChip T="string" OnClose="@(() => RemoveArt(articolo.Barcode))" style="height: auto;">
<MudChip T="string" OnClose="@(() => RemoveArt(articolo.Barcode))"
style="height: auto;">
<MudStack Direction="Column" Spacing="0" class="py-1">
<MudText Typo="Typo.subtitle2" Style="line-height: 1.1; font-weight: 700;">
@articolo.Descrizione
@@ -143,23 +144,23 @@
}
<CardFormModal Title="Scadenza">
<MudSelectExtended FullWidth="true" ReadOnly="@IsView" T="int" Variant="Variant.Text"
<MudSelectExtended FullWidth="true" T="int" Variant="Variant.Text"
@bind-Value="@Scheda.Scadenza" @bind-Value:after="OnAfterChangeValue">
<MudSelectItemExtended Class="custom-item-select" Text="24H" Value="24"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Settimana" Value="168"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Mese" Value="730"/>
<MudSelectItemExtended Class="custom-item-select" Text="2 Mesi" Value="1460"/>
<MudSelectItemExtended Class="custom-item-select" Text="24H" Value="3"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Settimana" Value="2"/>
<MudSelectItemExtended Class="custom-item-select" Text="1 Mese" Value="1"/>
<MudSelectItemExtended Class="custom-item-select" Text="2 Mesi" Value="0"/>
</MudSelectExtended>
</CardFormModal>
<CardFormModal Title="Responsabile">
<MudTextField FullWidth="true" ReadOnly="IsView" T="string?" Variant="Variant.Text"
<MudTextField FullWidth="true" T="string?" Variant="Variant.Text"
@bind-Value="Scheda.Responsabile" @bind-Value:after="OnAfterChangeValue"
DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
</CardFormModal>
<CardFormModal Title="Note">
<MudTextField ReadOnly="IsView" T="string?" Variant="Variant.Text" Lines="3"
<MudTextField T="string?" Variant="Variant.Text" Lines="3"
@bind-Value="Scheda.Note" @bind-Value:after="OnAfterChangeValue"
DebounceInterval="500" OnDebounceIntervalElapsed="OnAfterChangeValue"/>
</CardFormModal>
@@ -187,7 +188,7 @@
@code {
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter] public required string CodMdep { get; set; }
[Parameter] public required DateOnly Data { get; set; }
[Parameter] public required DateTime Data { get; set; }
[Parameter] public bool IsNew { get; set; }
[Parameter] public Scheda Scheda { get; set; } = new();
@@ -214,7 +215,7 @@
protected override void OnInitialized()
{
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
OnScannerService.OnNewScanSuccessful += HandleNewScanSuccessful;
OnScannerService.OnErrorScan += OnErrorScan;
@@ -226,6 +227,8 @@
private void LoadAttached()
{
if (Scheda.ImageNames == null) return;
FileLoading = true;
StateHasChanged();
@@ -237,7 +240,8 @@
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
}
},
Scheda.ImageNames
);
await InvokeAsync(() =>
@@ -254,9 +258,40 @@
{
VisibleOverlay = true;
StateHasChanged();
SaveSchedaResponseDto? apiResponse = null;
try
{
if (!IsView)
{
apiResponse = await IntegrySteupService.SaveScheda(
new SaveRequestDto
{
LocalIdScheda = Scheda.Id,
ActivityTypeId = Scheda.ActivityTypeId,
CodJfas = Scheda.CodJfas,
CodMdep = CodMdep,
DataCreazione = Data,
Note = Scheda.Note,
PersonaRif = Scheda.Responsabile,
Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode),
Scandeza = (ScadenzaEnum)Scheda.Scadenza,
ParentActivityId = IsNew ? null : Scheda.Ispezione?.ActivityId
}
);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await ModalHelper.ShowError(Dialog, e.Message);
}
if (IsNew) await NewSave();
else await Update();
if (IsNew) await NewSave(apiResponse);
else await Update(apiResponse);
if (Scheda.ActivityId.IsValorized()) await UploadFile(Scheda.ActivityId!);
await AttachedService.CleanTempStorageAsync();
@@ -268,7 +303,7 @@
MudDialog.Close(Scheda);
}
private async Task NewSave()
private async Task NewSave(SaveSchedaResponseDto? apiResponse)
{
if (!AttachedList.IsNullOrEmpty())
{
@@ -291,10 +326,18 @@
}
}
if (apiResponse != null)
{
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
Scheda.ActivityId = apiResponse.ActivityIdScheda;
}
await IspezioniService.AddSchedaAsync(CodMdep, Data, UserSession.User.Username, Scheda);
}
private async Task Update()
private async Task Update(SaveSchedaResponseDto? apiResponse)
{
if (!AttachedList.IsNullOrEmpty())
{
@@ -324,7 +367,33 @@
}
}
Scheda.ActivityId = apiResponse?.ActivityIdScheda;
await IspezioniService.UpdateSchedaAsync(Scheda);
if (apiResponse != null)
await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data,
UserSession.User.Username, apiResponse.ActivityIdIspezione
);
}
private async Task UploadFile(string activityId)
{
if (AttachedList.IsNullOrEmpty()) return;
var ispezione = new Ispezione
{
CodMdep = CodMdep,
Data = Data,
Rilevatore = UserSession.User.Username
};
foreach (var file in AttachedList!.Where(x => x.ToUpload))
{
if (file.FileBytes == null || file.Name == null) continue;
await IntegrySteupService.UploadFile(activityId, file.FileBytes, file.Name);
await AttachedService.MoveInspectionFileFromToUploadToFinal(ispezione, file.Name);
}
}
private async Task Cancel()
@@ -436,6 +505,7 @@
var target = AttachedList![AttachedList.Count - attachedList.Count + i];
target.TempPath = origUrl;
target.ThumbPath = thumbUrl;
target.ToUpload = true;
StateHasChanged();
});
}
@@ -456,7 +526,7 @@
Snackbar.Add("Selezionare prima il reparto", Severity.Error);
return;
}
OnLoading = true;
TextLoading = "Download articoli in griglia";
StateHasChanged();
@@ -477,25 +547,27 @@
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await InvokeAsync(() =>
{
OnLoading = false;
TextLoading = null;
StateHasChanged();
OnError(e.Message);
});
return;
}
var modal = await ModalHelper.OpenSelectArt(Dialog, articoli);
await InvokeAsync(() =>
{
OnLoading = false;
TextLoading = null;
StateHasChanged();
});
@@ -581,17 +653,17 @@
{
OnLoading = false;
StateHasChanged();
if (art != null)
{
RecalcDirty(true);
Scheda.Articoli.Add(new SchedaArticolo
{
Barcode = art.Barcode,
Descrizione = art.Descrizione
});
StateHasChanged();
}
else
@@ -602,12 +674,14 @@
}
catch (Exception e)
{
Console.WriteLine(e.Message);
await InvokeAsync(() =>
{
OnLoading = false;
StateHasChanged();
});
OnError(e.Message);
}
}
@@ -627,7 +701,7 @@
{
var index = Scheda.Articoli.FindIndex(x => x.Barcode.Equals(barcode));
if (index < 0) return;
RecalcDirty(true);
Scheda.Articoli.RemoveAt(index);
StateHasChanged();

View File

@@ -1,12 +1,13 @@
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account;
using IntegryApiClient.Core.Domain.Abstraction.Contracts.Device;
using SteUp.Shared.Core.BarcodeReader.Contracts;
using SteUp.Shared.Core.Data.Contracts;
using SteUp.Shared.Core.Dto;
using SteUp.Shared.Core.Dto.PageState;
using SteUp.Shared.Core.Helpers;
using SteUp.Shared.Core.Interface.IntegryApi;
using SteUp.Shared.Core.Interface.LocalDb;
using SteUp.Shared.Core.Interface.System;
using SteUp.Shared.Core.Interface.System.Network;
namespace SteUp.Shared.Core.Data;
@@ -15,12 +16,14 @@ public class SteupDataService(
IUserSession userSession,
IDeviceService deviceService,
IGenericSystemService genericSystemService,
IIspezioniService ispezioniService,
IDbInitializer dbInitializer) : ISteupDataService
{
public async Task Init()
{
await dbInitializer.InitializeAsync();
await LoadDataAsync();
await CheckAndUpdateStatus();
RegisterAppVersion();
}
@@ -31,6 +34,48 @@ public class SteupDataService(
);
}
private async Task CheckAndUpdateStatus()
{
var ispezioni = await ispezioniService.GetAllIspezioniWithSchedeAsync();
var listActivityId = ispezioni
.Where(x => x.ActivityId != null)
.Select(x => x.ActivityId!)
.ToList();
if (!listActivityId.IsNullOrEmpty())
{
var stati = await integrySteupService.RetrieveStatoIspezioni(
new RetrieveStatoIspezioniRequestDto
{
ActivityIdList = listActivityId
}
);
if (stati != null)
{
foreach (var stato in stati)
{
var ispezione = ispezioni.Find(x =>
x.ActivityId != null &&
x.ActivityId.EqualsIgnoreCase(stato.ActivityId)
);
var newStatus = StatusEnumHelper.ConvertToStatusEnum(stato.ActivityResultId);
if (ispezione != null && ispezione.Stato != newStatus)
{
await ispezioniService.UpdateStatoIspezioneAsync(
ispezione.CodMdep,
ispezione.Data,
ispezione.Rilevatore,
newStatus
);
}
}
}
}
}
private async Task LoadDataAsync()
{
if (!await userSession.IsLoggedIn()) return;

View File

@@ -16,6 +16,7 @@ public class AttachedDto
public bool SavedOnAppData { get; set; }
public bool ToRemove { get; set; }
public bool ToUpload { get; set; }
public Stream? FileContent =>
FileBytes is null ? null : new MemoryStream(FileBytes);

View File

@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace SteUp.Shared.Core.Dto;
public class RetrieveStatoIspezioniRequestDto
{
[JsonPropertyName("activityIdList")]
public required List<string> ActivityIdList { get; set; }
}

View File

@@ -0,0 +1,37 @@
using System.Text.Json.Serialization;
using SteUp.Shared.Core.Enum;
namespace SteUp.Shared.Core.Dto;
public class SaveRequestDto
{
[JsonPropertyName("localIdScheda")]
public int? LocalIdScheda { get; set; }
[JsonPropertyName("codMdep")]
public string? CodMdep { get; set; }
[JsonPropertyName("note")]
public string? Note { get; set; }
[JsonPropertyName("parentActivityId")]
public string? ParentActivityId { get; set; }
[JsonPropertyName("activityTypeId")]
public string? ActivityTypeId { get; set; }
[JsonPropertyName("codJfas")]
public string? CodJfas { get; set; }
[JsonPropertyName("personaRif")]
public string? PersonaRif { get; set; }
[JsonPropertyName("scandeza")]
public ScadenzaEnum Scandeza { get; set; }
[JsonPropertyName("dataCreazione")]
public DateTime? DataCreazione { get; set; }
[JsonPropertyName("barcodes")]
public List<string>? Barcodes { get; set; }
}

View File

@@ -0,0 +1,24 @@
using System.Text.Json.Serialization;
namespace SteUp.Shared.Core.Dto;
public class SaveSchedaResponseDto
{
[JsonPropertyName("activityIdIspezione")]
public string? ActivityIdIspezione { get; set; }
[JsonPropertyName("activityIdScheda")]
public string? ActivityIdScheda { get; set; }
[JsonPropertyName("activityIdSchedaList")]
public List<SchedaActivityId>? ActivityIdSchedaList { get; set; }
public class SchedaActivityId
{
[JsonPropertyName("localId")]
public int? LocalId { get; set; }
[JsonPropertyName("activityId")]
public string? ActivityId { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace SteUp.Shared.Core.Dto;
public class StbActivityDto
{
[JsonPropertyName("activityId")]
public string ActivityId { get; set; } = string.Empty;
[JsonPropertyName("activityResultId")]
public string ActivityResultId { get; set; } = string.Empty;
}

View File

@@ -7,10 +7,12 @@ public class Ispezione : EntityBase<Ispezione>
{
[Required]
public string CodMdep { get; set; } = string.Empty;
public DateOnly Data { get; set; }
public DateTime Data { get; set; }
[Required]
public string Rilevatore { get; set; } = string.Empty;
public string? ActivityId { get; set; }
public StatusEnum Stato { get; set; } = StatusEnum.InCorso;
public List<Scheda> Schede { get; set; } = [];

View File

@@ -8,11 +8,12 @@ public class Scheda : EntityBase<Scheda>
{
[Key]
public int Id { get; set; }
public string? ActivityId { get; set; }
public string? CodJfas { get; set; }
[Required]
public string CodMdep { get; set; } = string.Empty;
public DateOnly Data { get; set; }
public DateTime Data { get; set; }
[Required]
public string Rilevatore { get; set; } = string.Empty;
public Ispezione? Ispezione { get; set; }
@@ -24,7 +25,7 @@ public class Scheda : EntityBase<Scheda>
public string? ActivityTypeId { get; set; }
public string? Note { get; set; }
public string? Responsabile { get; set; }
public int Scadenza { get; set; } = 1460;
public int Scadenza { get; set; }
[NotMapped]
public JtbFasiDto? Reparto

View File

@@ -0,0 +1,9 @@
namespace SteUp.Shared.Core.Enum;
public enum ScadenzaEnum
{
Bassa2Mesi = 0,
Media1Mese = 1,
Alta1Settimana = 2,
Altissima24Ore = 3
}

View File

@@ -4,5 +4,6 @@ public enum StatusEnum
{
InCorso = 0,
Completata = 1,
Esporta = 2
Verifica = 2,
Annullata = 3
}

View File

@@ -25,7 +25,7 @@ public abstract class ModalHelper
return await modal.Result;
}
public static async Task<DialogResult?> OpenFormScheda(IDialogService dialog, string codMdep, DateOnly data,
public static async Task<DialogResult?> OpenFormScheda(IDialogService dialog, string codMdep, DateTime data,
bool isNew = false, Scheda? scheda = null)
{
scheda = isNew && scheda == null ? new Scheda() : scheda;

View File

@@ -10,9 +10,13 @@ public static class ObjectExtensions
public static bool IsNullOrEmpty(this string? obj) =>
string.IsNullOrEmpty(obj);
public static bool IsValorized(this string? obj) => !obj.IsNullOrEmpty();
public static bool EqualsIgnoreCase(this string obj, string other) =>
string.Equals(obj, other, StringComparison.InvariantCultureIgnoreCase);
public static bool ContainsIgnoreCase(this string obj, string other) =>
obj.Contains(other, StringComparison.InvariantCultureIgnoreCase);
public static int Count<T>(this List<T>? obj) => obj?.Count ?? 0;
}

View File

@@ -11,18 +11,30 @@ public static class StatusEnumHelper
{
StatusEnum.InCorso => "IN CORSO",
StatusEnum.Completata => "COMPLETATA",
StatusEnum.Esporta => "ESPORTATA",
StatusEnum.Verifica => "VERIFICA",
StatusEnum.Annullata => "ANNULLATA",
_ => throw new ArgumentOutOfRangeException(nameof(enumValue), enumValue, null)
};
}
public static StatusEnum ConvertToStatusEnum(string stringValue)
{
return stringValue switch
{
"COMPLETATA" => StatusEnum.Completata,
"ANNULLATA" => StatusEnum.Annullata,
"VERIFICA" => StatusEnum.Verifica,
_ => StatusEnum.InCorso
};
}
public static Color GetColor(this StatusEnum enumValue)
{
return enumValue switch
{
StatusEnum.InCorso => Color.Warning,
StatusEnum.Completata or
StatusEnum.Esporta => Color.Success,
StatusEnum.InCorso or StatusEnum.Verifica => Color.Warning,
StatusEnum.Completata => Color.Success,
StatusEnum.Annullata => Color.Error,
_ => Color.Default
};
}

View File

@@ -10,4 +10,11 @@ public interface IIntegrySteupService
Task<List<ActivityTypeDto>> RetrieveActivityType();
Task<List<ArticoliInGrigliaDto>?> RetrieveGrigliaPlu(RetrieveGrigliaPluRequestDto request);
Task<ArticoliInGrigliaDto?> RetrieveArtFromBarcode(string barcode);
Task<List<StbActivityDto>?> RetrieveStatoIspezioni(RetrieveStatoIspezioniRequestDto request);
//Save
Task<SaveSchedaResponseDto?> SaveScheda(SaveRequestDto request);
Task<SaveSchedaResponseDto?> SaveMultipleSchede(List<SaveRequestDto> request);
Task CompleteInspection(string activityId);
Task UploadFile(string activityId, byte[] file, string fileName);
}

View File

@@ -1,23 +1,27 @@
using SteUp.Shared.Core.Entities;
using SteUp.Shared.Core.Enum;
namespace SteUp.Shared.Core.Interface.LocalDb;
public interface IIspezioniService
{
// ISPEZIONI
Task<Ispezione?> GetIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task<Ispezione?> GetIspezioneAsync(string codMdep, DateTime data, string rilevatore);
Task<List<Ispezione>> GetAllIspezioniWithSchedeAsync();
Task AddIspezioneAsync(Ispezione ispezione);
Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task<Ispezione> GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore);
Task<bool> UpdateIspezioneAsync(Ispezione ispezione);
Task<bool> DeleteIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task<bool> UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, StatusEnum stato);
Task<bool> UpdateActivityIdIspezioneAsync(string codMdep, DateTime data, string rilevatore, string? activityId);
Task<bool> DeleteIspezioneAsync(string codMdep, DateTime data, string rilevatore);
// SCHEDE
Task AddSchedaAsync(string codMdep, DateOnly data, string rilevatore, Scheda scheda);
Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task AddSchedaAsync(string codMdep, DateTime data, string rilevatore, Scheda scheda);
Task<List<Scheda>> GetAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore);
Task<Scheda?> GetSchedaAsync(int schedaId);
Task<Scheda?> GetSchedaWithIspezioneAsync(int schedaId);
Task<bool> UpdateSchedaAsync(Scheda scheda);
Task<bool> UpdateActivityIdSchedaAsync(int schedaId, string? activityId);
Task<bool> DeleteSchedaAsync(int schedaId);
Task<int> DeleteAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore);
Task<int> DeleteAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore);
}

View File

@@ -8,13 +8,21 @@ public interface IAttachedService
Task<AttachedDto?> SelectImageFromCamera();
Task<List<AttachedDto>?> SelectImageFromGallery();
Task<List<AttachedDto>?> GetInspectionFiles(Ispezione ispezione);
Task<List<AttachedDto>?> GetInspectionFiles(Ispezione ispezione, List<string> fileNameFilter,
bool includeToUpload = true, CancellationToken ct = default);
Task<string?> SaveInspectionFile(Ispezione ispezione, byte[] file, string fileName, CancellationToken ct = default);
bool RemoveInspectionFile(Ispezione ispezione, string fileName);
bool RemoveInspectionFile(Ispezione ispezione, string fileName, bool removeAlsoFromFinal = true,
bool removeAlsoFromToUpload = true);
Task<bool> MoveInspectionFileFromToUploadToFinal(Ispezione ispezione, string fileName, bool overwrite = true,
CancellationToken ct = default);
Task<string> SaveToTempStorage(Stream file, string fileName, CancellationToken ct = default);
Task CleanTempStorageAsync(CancellationToken ct = default);
Task OpenFile(string fileName, string filePath);
Task<(string originalUrl, string thumbUrl)> SaveAndCreateThumbAsync(byte[] bytes, string fileName, CancellationToken ct = default);
Task<(string originalUrl, string thumbUrl)> SaveAndCreateThumbAsync(byte[] bytes, string fileName,
CancellationToken ct = default);
}

View File

@@ -0,0 +1,5 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
namespace SteUp.Shared.Core.Messages.Ispezione;
public class CompleteInspectionMessage(object? value = null) : ValueChangedMessage<object?>(value);

View File

@@ -0,0 +1,13 @@
using CommunityToolkit.Mvvm.Messaging;
namespace SteUp.Shared.Core.Messages.Ispezione;
public class CompleteInspectionService
{
public event Action? OnComplete;
public CompleteInspectionService(IMessenger messenger)
{
messenger.Register<CompleteInspectionMessage>(this, (_, _) => { OnComplete?.Invoke(); });
}
}

View File

@@ -19,6 +19,7 @@ public class IntegryApiService(
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}

View File

@@ -1,4 +1,5 @@
using IntegryApiClient.Core.Domain.RestClient.Contacts;
using System.Net.Http.Headers;
using IntegryApiClient.Core.Domain.RestClient.Contacts;
using SteUp.Shared.Core.Dto;
using SteUp.Shared.Core.Interface.IntegryApi;
@@ -31,5 +32,39 @@ public class IntegrySteupService(IIntegryApiRestClient integryApiRestClient) : I
}
);
public Task<List<StbActivityDto>?> RetrieveStatoIspezioni(RetrieveStatoIspezioniRequestDto request) =>
integryApiRestClient.AuthorizedPost<List<StbActivityDto>?>($"{BaseRequest}/retrieveStatoIspezioni", request);
#endregion
#region Save
public Task<SaveSchedaResponseDto?> SaveScheda(SaveRequestDto request) =>
integryApiRestClient.AuthorizedPost<SaveSchedaResponseDto?>($"{BaseRequest}/saveScheda", request);
public Task<SaveSchedaResponseDto?> SaveMultipleSchede(List<SaveRequestDto> request) =>
integryApiRestClient.AuthorizedPost<SaveSchedaResponseDto?>($"{BaseRequest}/saveMultipleSchede", request);
public Task CompleteInspection(string activityId) =>
integryApiRestClient.AuthorizedPost<object>(
$"{BaseRequest}/complete",
new Dictionary<string, object>
{
{ "activityId", activityId }
}
);
#endregion
public Task UploadFile(string activityId, byte[] file, string fileName)
{
var queryParams = new Dictionary<string, object> { { "activityId", activityId } };
using var content = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(file);
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
content.Add(fileContent, "file", fileName);
return integryApiRestClient.Post<object>($"{BaseRequest}/uploadAttachment", content, queryParams!);
}
}

View File

@@ -14,10 +14,12 @@
@using MudExtensions
@using SteUp.Shared.Core.Data.Contracts
@using SteUp.Shared.Core.Helpers
@using SteUp.Shared.Core.Interface.System.Network
@using static InteractiveRenderSettings
@inject NavigationManager NavigationManager
@inject IUserSession UserSession
@inject ILocalStorage LocalStorage
@inject ISnackbar Snackbar
@inject ISteupDataService SteupDataService
@inject ISteupDataService SteupDataService
@inject INetworkService NetworkService