Gestiti salvataggi rest
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
37
SteUp.Shared/Core/Dto/SaveRequestDto.cs
Normal file
37
SteUp.Shared/Core/Dto/SaveRequestDto.cs
Normal 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; }
|
||||
}
|
||||
24
SteUp.Shared/Core/Dto/SaveSchedaResponseDto.cs
Normal file
24
SteUp.Shared/Core/Dto/SaveSchedaResponseDto.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
12
SteUp.Shared/Core/Dto/StbActivityDto.cs
Normal file
12
SteUp.Shared/Core/Dto/StbActivityDto.cs
Normal 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;
|
||||
}
|
||||
@@ -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; } = [];
|
||||
|
||||
@@ -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
|
||||
|
||||
9
SteUp.Shared/Core/Enum/ScadenzaEnum.cs
Normal file
9
SteUp.Shared/Core/Enum/ScadenzaEnum.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace SteUp.Shared.Core.Enum;
|
||||
|
||||
public enum ScadenzaEnum
|
||||
{
|
||||
Bassa2Mesi = 0,
|
||||
Media1Mese = 1,
|
||||
Alta1Settimana = 2,
|
||||
Altissima24Ore = 3
|
||||
}
|
||||
@@ -4,5 +4,6 @@ public enum StatusEnum
|
||||
{
|
||||
InCorso = 0,
|
||||
Completata = 1,
|
||||
Esporta = 2
|
||||
Verifica = 2,
|
||||
Annullata = 3
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||||
|
||||
namespace SteUp.Shared.Core.Messages.Ispezione;
|
||||
|
||||
public class CompleteInspectionMessage(object? value = null) : ValueChangedMessage<object?>(value);
|
||||
@@ -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(); });
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public class IntegryApiService(
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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!);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user