SHA256
StayExport Tracking - StayExportFile ExportDetails new type/format
- Added new class to unify and type the format of StayExportFile.ExportDetails field. Note: This database migration will set to null all StayExportFile.ExportDetails data. This is required to prevent exceptions due to new formatting.
This commit is contained in:
1 parent
cf62a0e55e
commit
54387a6346
15 files changed
+486
-35
No files matched your search
@@ -143,14 +143,16 @@
|
|||||||
|
|
||||||
private async Task ShowExportDetails(StayExportFileDTO dto)
|
private async Task ShowExportDetails(StayExportFileDTO dto)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(dto.ExportDetails))
|
if (dto.ExportDetails == null)
|
||||||
{
|
{
|
||||||
userMessage.ShowMessage("This ExportFile doesn't have any export details", MessageKind.Info);
|
userMessage.ShowMessage("This ExportFile doesn't have any export details", MessageKind.Info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var jDoc = JsonDocument.Parse(dto.ExportDetails);
|
string jsonDetails = JsonSerializer.Serialize(
|
||||||
string jsonDetails = JsonSerializer.Serialize(jDoc, new JsonSerializerOptions { WriteIndented = true });
|
value: dto.ExportDetails,
|
||||||
|
options: new JsonSerializerOptions { WriteIndented = true }
|
||||||
|
);
|
||||||
|
|
||||||
await DialogService.ShowMessageBoxAsync("Details", (MarkupString)$"<pre>{jsonDetails}</pre>");
|
await DialogService.ShowMessageBoxAsync("Details", (MarkupString)$"<pre>{jsonDetails}</pre>");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Somnia.GuestLog.Enums.Models;
|
||||||
|
|
||||||
|
public enum StayExportDetailsStayEntryResult
|
||||||
|
{
|
||||||
|
OK = 0,
|
||||||
|
Error = 1
|
||||||
|
}
|
||||||
@@ -25,9 +25,10 @@ public class StayExportFileEntityConfig : IEntityTypeConfiguration<StayExportFil
|
|||||||
builder.Property(e => e.ExportedPath)
|
builder.Property(e => e.ExportedPath)
|
||||||
.HasMaxLength(256);
|
.HasMaxLength(256);
|
||||||
|
|
||||||
builder.Property(e => e.ExportDetails)
|
builder.ComplexProperty(e => e.ExportDetails, e =>
|
||||||
.HasColumnType(DbConsts.DbType_jsonb);
|
{
|
||||||
|
e.ToJson();
|
||||||
|
});
|
||||||
|
|
||||||
builder.Property(e => e.ExportTime)
|
builder.Property(e => e.ExportTime)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
|
|||||||
+283
@@ -0,0 +1,283 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using Somnia.GuestLog.Infrastructure;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(GuestLogContext))]
|
||||||
|
[Migration("20261009104234_StayExportFile_ExportDetails_UpdatedFormat")]
|
||||||
|
partial class StayExportFile_ExportDetails_UpdatedFormat
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.12")
|
||||||
|
.HasAnnotation("Proxies:ChangeTracking", false)
|
||||||
|
.HasAnnotation("Proxies:CheckEquality", false)
|
||||||
|
.HasAnnotation("Proxies:LazyLoading", true)
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("GuestDocumentStayEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("StayEntryId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<long>("GuestDocumentsId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int>("GuestDocumentsVersion")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("StayEntryId", "GuestDocumentsId", "GuestDocumentsVersion");
|
||||||
|
|
||||||
|
b.HasIndex("GuestDocumentsId", "GuestDocumentsVersion");
|
||||||
|
|
||||||
|
b.ToTable("GuestDocumentStayEntry");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.GuestDocument", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Version")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateOnly>("BirthDate")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreateTime")
|
||||||
|
.HasColumnType("timestamp(3) with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("DocumentNum")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("DocumentType")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("EmailAddress")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("Gender")
|
||||||
|
.HasMaxLength(1)
|
||||||
|
.HasColumnType("character varying(1)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsLastVersion")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<DateOnly?>("IssueDate")
|
||||||
|
.HasColumnType("date");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Nationality")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(3)
|
||||||
|
.HasColumnType("character varying(3)");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("SupportNum")
|
||||||
|
.HasMaxLength(10)
|
||||||
|
.HasColumnType("character varying(10)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Surname2")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdateTime")
|
||||||
|
.HasColumnType("timestamp(3) with time zone");
|
||||||
|
|
||||||
|
b.ComplexProperty(typeof(Dictionary<string, object>), "AddressDetails", "Somnia.GuestLog.Models.Entities.GuestDocument.AddressDetails#GuestAddress", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<string>("Address")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressCity")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressCountry")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(3)
|
||||||
|
.HasColumnType("character varying(3)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressProvince")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("AddressState")
|
||||||
|
.HasMaxLength(128)
|
||||||
|
.HasColumnType("character varying(128)");
|
||||||
|
|
||||||
|
b1.Property<string>("ZipCode")
|
||||||
|
.HasMaxLength(12)
|
||||||
|
.HasColumnType("character varying(12)");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasKey("Id", "Version");
|
||||||
|
|
||||||
|
b.ToTable("GuestDocument", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.StayEntry", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateIn")
|
||||||
|
.HasColumnType("timestamp(0) with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateOut")
|
||||||
|
.HasColumnType("timestamp(0) with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("PaymentMethod")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(5)
|
||||||
|
.HasColumnType("character varying(5)");
|
||||||
|
|
||||||
|
b.Property<int>("RoomCount")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("RoomNumber")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<int>("StayUploadStatus")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("StayUploadStatusTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("UpdateTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("StayEntry", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Somnia.GuestLog.Models.Entities.StayExportFile", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ExportFormat")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ExportResult")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ExportTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ExportedPath")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<int>("FileUploadStatus")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("FileUploadStatusTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.ComplexProperty(typeof(Dictionary<string, object>), "ExportDetails", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportDetails#StayExportDetails", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int?>("ExportedStayCount");
|
||||||
|
|
||||||
|
b1.Property<int?>("StayErrorCount");
|
||||||
|
|
||||||
|
b1.ComplexCollection(typeof(List<Dictionary<string, object>>), "StayEntries", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportDetails#StayExportDetails.StayEntries#StayExportDetailsStayEntry", b2 =>
|
||||||
|
{
|
||||||
|
b2.IsRequired();
|
||||||
|
|
||||||
|
b2.Property<string>("Details");
|
||||||
|
|
||||||
|
b2.Property<int>("ExportResult");
|
||||||
|
|
||||||
|
b2.Property<long>("StayEntryId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b1
|
||||||
|
.ToJson("ExportDetails")
|
||||||
|
.HasColumnType("jsonb");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.ComplexProperty(typeof(Dictionary<string, object>), "ExportParams", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportParams#StayExportParams", b1 =>
|
||||||
|
{
|
||||||
|
b1.IsRequired();
|
||||||
|
|
||||||
|
b1.Property<DateTime?>("ExportPeriodEnd");
|
||||||
|
|
||||||
|
b1.Property<DateTime?>("ExportPeriodStart");
|
||||||
|
|
||||||
|
b1.Property<int>("ExportType");
|
||||||
|
|
||||||
|
b1
|
||||||
|
.ToJson("ExportParams")
|
||||||
|
.HasColumnType("jsonb");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("StayExportFile", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GuestDocumentStayEntry", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Somnia.GuestLog.Models.Entities.StayEntry", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("StayEntryId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Somnia.GuestLog.Models.Entities.GuestDocument", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("GuestDocumentsId", "GuestDocumentsVersion")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class StayExportFile_ExportDetails_UpdatedFormat : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
//Update all StayExportFiles ExportDetails to NULL to prevent format errors when parsing the new types.
|
||||||
|
migrationBuilder.Sql("""UPDATE "StayExportFile" SET "ExportDetails" = NULL;""");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
//Nothing to do. Data can't be recovered!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -199,9 +199,6 @@ namespace Somnia.GuestLog.Infrastructure.Migrations
|
|||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
b.Property<string>("ExportDetails")
|
|
||||||
.HasColumnType("jsonb");
|
|
||||||
|
|
||||||
b.Property<int>("ExportFormat")
|
b.Property<int>("ExportFormat")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
@@ -221,6 +218,28 @@ namespace Somnia.GuestLog.Infrastructure.Migrations
|
|||||||
b.Property<DateTime?>("FileUploadStatusTime")
|
b.Property<DateTime?>("FileUploadStatusTime")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.ComplexProperty(typeof(Dictionary<string, object>), "ExportDetails", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportDetails#StayExportDetails", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<int?>("ExportedStayCount");
|
||||||
|
|
||||||
|
b1.Property<int?>("StayErrorCount");
|
||||||
|
|
||||||
|
b1.ComplexCollection(typeof(List<Dictionary<string, object>>), "StayEntries", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportDetails#StayExportDetails.StayEntries#StayExportDetailsStayEntry", b2 =>
|
||||||
|
{
|
||||||
|
b2.IsRequired();
|
||||||
|
|
||||||
|
b2.Property<string>("Details");
|
||||||
|
|
||||||
|
b2.Property<int>("ExportResult");
|
||||||
|
|
||||||
|
b2.Property<long>("StayEntryId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b1
|
||||||
|
.ToJson("ExportDetails")
|
||||||
|
.HasColumnType("jsonb");
|
||||||
|
});
|
||||||
|
|
||||||
b.ComplexProperty(typeof(Dictionary<string, object>), "ExportParams", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportParams#StayExportParams", b1 =>
|
b.ComplexProperty(typeof(Dictionary<string, object>), "ExportParams", "Somnia.GuestLog.Models.Entities.StayExportFile.ExportParams#StayExportParams", b1 =>
|
||||||
{
|
{
|
||||||
b1.IsRequired();
|
b1.IsRequired();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class StayExportFileDTO
|
|||||||
|
|
||||||
public string? ExportedPath { get; set; }
|
public string? ExportedPath { get; set; }
|
||||||
|
|
||||||
public string? ExportDetails { get; set; }
|
public StayExportDetailsDTO? ExportDetails { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public DateTime? ExportTime { get; set; }
|
public DateTime? ExportTime { get; set; }
|
||||||
@@ -31,3 +31,18 @@ public class StayExportParamsDTO
|
|||||||
public DateTime? ExportPeriodStart { get; set; }
|
public DateTime? ExportPeriodStart { get; set; }
|
||||||
public DateTime? ExportPeriodEnd { get; set; }
|
public DateTime? ExportPeriodEnd { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class StayExportDetailsDTO
|
||||||
|
{
|
||||||
|
public int? ExportedStayCount { get; set; }
|
||||||
|
public int? StayErrorCount { get; set; }
|
||||||
|
|
||||||
|
public List<StayExportDetailsStayEntryDTO> StayEntries { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StayExportDetailsStayEntryDTO
|
||||||
|
{
|
||||||
|
public required long StayEntryId { get; set; }
|
||||||
|
public required StayExportDetailsStayEntryResult ExportResult { get; set; }
|
||||||
|
public string? Details { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using Somnia.GuestLog.Enums.Models;
|
||||||
|
using Somnia.GuestLog.Infrastructure;
|
||||||
|
|
||||||
|
namespace Somnia.GuestLog.Models.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This class store details and extra information about the exported data of a StayExportFile.
|
||||||
|
/// </summary>
|
||||||
|
public class StayExportDetails : BaseEntity
|
||||||
|
{
|
||||||
|
public int? ExportedStayCount { get; set; }
|
||||||
|
public int? StayErrorCount { get; set; }
|
||||||
|
|
||||||
|
public List<StayExportDetailsStayEntry> StayEntries { get; set; } = [];
|
||||||
|
|
||||||
|
public override string GetFullKey() => DbConsts.PK_NotApply;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Export details for each exported stayEntry in a StayExportFile.
|
||||||
|
/// </summary>
|
||||||
|
public class StayExportDetailsStayEntry
|
||||||
|
{
|
||||||
|
public required long StayEntryId { get; set; }
|
||||||
|
public required StayExportDetailsStayEntryResult ExportResult { get; set; }
|
||||||
|
public string? Details { get; set; }
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ public class StayExportFile : BaseEntity
|
|||||||
/// A JSON column to store details about the exported file.
|
/// A JSON column to store details about the exported file.
|
||||||
/// This details can contain information about errors, which stays where included, etc.
|
/// This details can contain information about errors, which stays where included, etc.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ExportDetails { get; set; }
|
public StayExportDetails? ExportDetails { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Date/Time when export file was generated.
|
/// Date/Time when export file was generated.
|
||||||
|
|||||||
@@ -62,6 +62,28 @@ internal static class EntityMapping
|
|||||||
ExportPeriodEnd = entity.ExportParams.ExportPeriodEnd,
|
ExportPeriodEnd = entity.ExportParams.ExportPeriodEnd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StayExportDetailsDTO? detailsDTO = null;
|
||||||
|
|
||||||
|
if (entity.ExportDetails != null)
|
||||||
|
{
|
||||||
|
List<StayExportDetailsStayEntryDTO> entriesDto = [];
|
||||||
|
foreach (var entry in entity.ExportDetails.StayEntries)
|
||||||
|
{
|
||||||
|
entriesDto.Add(new()
|
||||||
|
{
|
||||||
|
StayEntryId = entry.StayEntryId,
|
||||||
|
ExportResult = entry.ExportResult,
|
||||||
|
Details = entry.Details,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
detailsDTO = new()
|
||||||
|
{
|
||||||
|
ExportedStayCount = entity.ExportDetails.ExportedStayCount,
|
||||||
|
StayErrorCount = entity.ExportDetails.StayErrorCount,
|
||||||
|
StayEntries = entriesDto,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
Id = entity.Id,
|
Id = entity.Id,
|
||||||
@@ -69,7 +91,7 @@ internal static class EntityMapping
|
|||||||
ExportParams = exportParamsDto,
|
ExportParams = exportParamsDto,
|
||||||
ExportResult = entity.ExportResult,
|
ExportResult = entity.ExportResult,
|
||||||
ExportedPath = entity.ExportedPath,
|
ExportedPath = entity.ExportedPath,
|
||||||
ExportDetails = entity.ExportDetails,
|
ExportDetails = detailsDTO,
|
||||||
ExportTime = entity.ExportTime.ToLocalTime(),
|
ExportTime = entity.ExportTime.ToLocalTime(),
|
||||||
FileUploadStatus = entity.FileUploadStatus,
|
FileUploadStatus = entity.FileUploadStatus,
|
||||||
FileUploadStatusTime = entity.FileUploadStatusTime?.ToLocalTime(),
|
FileUploadStatusTime = entity.FileUploadStatusTime?.ToLocalTime(),
|
||||||
|
|||||||
@@ -31,13 +31,14 @@ public class StayExportFileEntityService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
StayExportParams exportParams = GetExportParamsFromDTO(dto.ExportParams);
|
StayExportParams exportParams = GetExportParamsFromDTO(dto.ExportParams);
|
||||||
|
StayExportDetails? exportDetails = GetExportDetailsFromDTO(dto.ExportDetails);
|
||||||
StayExportFile dbItem = new()
|
StayExportFile dbItem = new()
|
||||||
{
|
{
|
||||||
ExportFormat = dto.ExportFormat.Value,
|
ExportFormat = dto.ExportFormat.Value,
|
||||||
ExportParams = exportParams,
|
ExportParams = exportParams,
|
||||||
ExportResult = dto.ExportResult.Value,
|
ExportResult = dto.ExportResult.Value,
|
||||||
ExportedPath = dto.ExportedPath,
|
ExportedPath = dto.ExportedPath,
|
||||||
ExportDetails = dto.ExportDetails,
|
ExportDetails = exportDetails,
|
||||||
ExportTime = dto.ExportTime?.ToUniversalTime() ?? DateTime.UtcNow,
|
ExportTime = dto.ExportTime?.ToUniversalTime() ?? DateTime.UtcNow,
|
||||||
FileUploadStatus = UploadStatus.Pending,
|
FileUploadStatus = UploadStatus.Pending,
|
||||||
FileUploadStatusTime = null
|
FileUploadStatusTime = null
|
||||||
@@ -184,5 +185,32 @@ public class StayExportFileEntityService(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static StayExportDetails? GetExportDetailsFromDTO(StayExportDetailsDTO? dto)
|
||||||
|
{
|
||||||
|
if (dto == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get all entries
|
||||||
|
List<StayExportDetailsStayEntry> entries = [];
|
||||||
|
foreach (var entry in dto.StayEntries)
|
||||||
|
{
|
||||||
|
entries.Add(new()
|
||||||
|
{
|
||||||
|
StayEntryId = entry.StayEntryId,
|
||||||
|
ExportResult = entry.ExportResult,
|
||||||
|
Details = entry.Details
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
ExportedStayCount = dto.ExportedStayCount,
|
||||||
|
StayErrorCount = dto.StayErrorCount,
|
||||||
|
StayEntries = entries
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,6 @@ public interface IStayExportFormatProvider
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stayList">List of Stays to export</param>
|
/// <param name="stayList">List of Stays to export</param>
|
||||||
/// <param name="dataStream">Stream to copy exported data.</param>
|
/// <param name="dataStream">Stream to copy exported data.</param>
|
||||||
public Task<(StayExportFileResult fileResult, string? exportDetails)> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream);
|
public Task<(StayExportFileResult fileResult, List<StayExportDetailsStayEntryDTO> detailsEntries)> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,18 +13,27 @@ public class StayExportProviderJson : IStayExportFormatProvider
|
|||||||
=> $"{Enum.GetName(GetFormat())}_{exportTime.ToFileTimeUtc()}.{fileExtension}";
|
=> $"{Enum.GetName(GetFormat())}_{exportTime.ToFileTimeUtc()}.{fileExtension}";
|
||||||
|
|
||||||
|
|
||||||
public async Task<(StayExportFileResult fileResult, string? exportDetails)> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream)
|
public async Task<(StayExportFileResult fileResult, List<StayExportDetailsStayEntryDTO> detailsEntries)> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream)
|
||||||
{
|
{
|
||||||
if (!stayList.Any())
|
if (!stayList.Any())
|
||||||
{
|
{
|
||||||
return (fileResult: StayExportFileResult.NoData, exportDetails: null);
|
return (fileResult: StayExportFileResult.NoData, detailsEntries: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to JSON.
|
// Convert to JSON.
|
||||||
await JsonSerializer.SerializeAsync(dataStream, stayList);
|
await JsonSerializer.SerializeAsync(dataStream, stayList);
|
||||||
|
|
||||||
List<string> exportDetails = [.. stayList.Where(s => s.Id != null).Select(s => s.Id?.ToString() ?? "")];
|
List<StayExportDetailsStayEntryDTO> details = [];
|
||||||
string details = JsonSerializer.Serialize(exportDetails);
|
foreach (var stay in stayList)
|
||||||
return (fileResult: StayExportFileResult.OK, exportDetails: details);
|
{
|
||||||
|
details.Add(new()
|
||||||
|
{
|
||||||
|
StayEntryId = stay.Id!.Value,
|
||||||
|
ExportResult = StayExportDetailsStayEntryResult.OK,
|
||||||
|
Details = null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (fileResult: StayExportFileResult.OK, detailsEntries: details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -18,9 +17,6 @@ public class StayExportProviderSpainParteViajeros(
|
|||||||
{
|
{
|
||||||
private const string fileExtension = "xml";
|
private const string fileExtension = "xml";
|
||||||
|
|
||||||
private const string ExportDetailsResult_Error = "Error";
|
|
||||||
private const string ExportDetailsResult_Ok = "Ok";
|
|
||||||
|
|
||||||
private const string PersonRole = "VI";
|
private const string PersonRole = "VI";
|
||||||
private const string PersonRelation = "OT";
|
private const string PersonRelation = "OT";
|
||||||
|
|
||||||
@@ -41,20 +37,20 @@ public class StayExportProviderSpainParteViajeros(
|
|||||||
public string GetFilename(DateTime exportTime)
|
public string GetFilename(DateTime exportTime)
|
||||||
=> $"{Enum.GetName(GetFormat())}_{exportTime.ToFileTimeUtc()}.{fileExtension}";
|
=> $"{Enum.GetName(GetFormat())}_{exportTime.ToFileTimeUtc()}.{fileExtension}";
|
||||||
|
|
||||||
public async Task<(StayExportFileResult fileResult, string? exportDetails)> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream)
|
public async Task<(StayExportFileResult fileResult, List<StayExportDetailsStayEntryDTO> detailsEntries)> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(config.CodigoEstablecimiento))
|
if (string.IsNullOrEmpty(config.CodigoEstablecimiento))
|
||||||
{
|
{
|
||||||
logger.LogError("StayExportProviderSpainParteViajeros - Config error: CodigoEstablecimiento is not configured!");
|
logger.LogError("StayExportProviderSpainParteViajeros - Config error: CodigoEstablecimiento is not configured!");
|
||||||
return (fileResult: StayExportFileResult.ExportError, exportDetails: null);
|
return (fileResult: StayExportFileResult.ExportError, detailsEntries: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stayList.Any())
|
if (!stayList.Any())
|
||||||
{
|
{
|
||||||
return (fileResult: StayExportFileResult.NoData, exportDetails: null);
|
return (fileResult: StayExportFileResult.NoData, detailsEntries: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<StayExportDetails> stayExportDetails = [];
|
List<StayExportDetailsStayEntryDTO> stayExportDetails = [];
|
||||||
ComunicacionValidator comunicacionValidator = new();
|
ComunicacionValidator comunicacionValidator = new();
|
||||||
|
|
||||||
List<Comunicacion> comunicacionsList = [];
|
List<Comunicacion> comunicacionsList = [];
|
||||||
@@ -64,7 +60,12 @@ public class StayExportProviderSpainParteViajeros(
|
|||||||
if (comunicacion == null)
|
if (comunicacion == null)
|
||||||
{
|
{
|
||||||
logger.LogWarning("StayExportProviderSpainParteViajeros - Stay (ID: {id}) can't be exported: Error: {code}", stay.Id, errorMsg);
|
logger.LogWarning("StayExportProviderSpainParteViajeros - Stay (ID: {id}) can't be exported: Error: {code}", stay.Id, errorMsg);
|
||||||
stayExportDetails.Add(new(StayId: stay.Id ?? -1, ExportResult: ExportDetailsResult_Error, Details: errorMsg));
|
stayExportDetails.Add(new()
|
||||||
|
{
|
||||||
|
StayEntryId = stay.Id ?? -1,
|
||||||
|
ExportResult = StayExportDetailsStayEntryResult.Error,
|
||||||
|
Details = errorMsg
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,13 +73,23 @@ public class StayExportProviderSpainParteViajeros(
|
|||||||
if (!errors.IsValid)
|
if (!errors.IsValid)
|
||||||
{
|
{
|
||||||
logger.LogWarning("StayExportProviderSpainParteViajeros - Stay (ID: {id}) is invalid: Errors: {errors}", stay.Id, errors.Errors);
|
logger.LogWarning("StayExportProviderSpainParteViajeros - Stay (ID: {id}) is invalid: Errors: {errors}", stay.Id, errors.Errors);
|
||||||
stayExportDetails.Add(new(StayId: stay.Id ?? -1, ExportResult: ExportDetailsResult_Error, Details: errors.ToString()));
|
stayExportDetails.Add(new()
|
||||||
|
{
|
||||||
|
StayEntryId = stay.Id ?? -1,
|
||||||
|
ExportResult = StayExportDetailsStayEntryResult.Error,
|
||||||
|
Details = errors.ToString()
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
comunicacionsList.Add(comunicacion);
|
comunicacionsList.Add(comunicacion);
|
||||||
logger.LogInformation("StayExportProviderSpainParteViajeros - Stay (ID: {id}) Exported OK", stay.Id);
|
logger.LogInformation("StayExportProviderSpainParteViajeros - Stay (ID: {id}) Exported OK", stay.Id);
|
||||||
stayExportDetails.Add(new(StayId: stay.Id ?? -1, ExportResult: ExportDetailsResult_Ok, Details: null));
|
stayExportDetails.Add(new()
|
||||||
|
{
|
||||||
|
StayEntryId = stay.Id ?? -1,
|
||||||
|
ExportResult = StayExportDetailsStayEntryResult.OK,
|
||||||
|
Details = null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Peticion peticion = new()
|
Peticion peticion = new()
|
||||||
@@ -97,8 +108,7 @@ public class StayExportProviderSpainParteViajeros(
|
|||||||
XmlSerializer serializer = new(typeof(Peticion));
|
XmlSerializer serializer = new(typeof(Peticion));
|
||||||
serializer.Serialize(stream: dataStream, o: peticion, namespaces: docNamespaces);
|
serializer.Serialize(stream: dataStream, o: peticion, namespaces: docNamespaces);
|
||||||
|
|
||||||
string details = JsonSerializer.Serialize(stayExportDetails);
|
return (fileResult: StayExportFileResult.OK, detailsEntries: stayExportDetails);
|
||||||
return (fileResult: StayExportFileResult.OK, exportDetails: details);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Internal Methods
|
#region Internal Methods
|
||||||
@@ -325,8 +335,6 @@ public class StayExportProviderSpainParteViajeros(
|
|||||||
|
|
||||||
#region Export Data Classes
|
#region Export Data Classes
|
||||||
|
|
||||||
private record StayExportDetails(long StayId, string ExportResult, string? Details);
|
|
||||||
|
|
||||||
[XmlRoot(ElementName = "peticion", Namespace = XmlNamespace_Peticion)]
|
[XmlRoot(ElementName = "peticion", Namespace = XmlNamespace_Peticion)]
|
||||||
public class Peticion
|
public class Peticion
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,7 +58,14 @@ public class StayExportService(
|
|||||||
{
|
{
|
||||||
//Create Format provider and export data to stream.
|
//Create Format provider and export data to stream.
|
||||||
var provider = providerFactory.GetProvider(format);
|
var provider = providerFactory.GetProvider(format);
|
||||||
(exportResult, stayExport.ExportDetails) = await provider.ExportDataAsync(stayList, exportedDataStream);
|
(exportResult, List<StayExportDetailsStayEntryDTO> entriesDetails) = await provider.ExportDataAsync(stayList, exportedDataStream);
|
||||||
|
|
||||||
|
stayExport.ExportDetails = new()
|
||||||
|
{
|
||||||
|
ExportedStayCount = entriesDetails.Count,
|
||||||
|
StayErrorCount = entriesDetails.Count(e => e.ExportResult == StayExportDetailsStayEntryResult.Error),
|
||||||
|
StayEntries = entriesDetails
|
||||||
|
};
|
||||||
|
|
||||||
// "Rewind" stream so it can be read from the begining when uploading.
|
// "Rewind" stream so it can be read from the begining when uploading.
|
||||||
exportedDataStream.Seek(0, SeekOrigin.Begin);
|
exportedDataStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|||||||
Reference in new issue
Block a user