feat(import): RennmausPro-III-Backup-Importer (analyze+execute, Dedup, Fotos)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 22:43:19 +02:00
parent 5e14124322
commit 3ad276637c
19 changed files with 2620 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
using GerbilManagerWebAPI.Models;
namespace GerbilManagerWebAPI.Import.Rpro3
{
/// <summary>
/// Quelle eines RPRO3-Tier-Datensatzes. „stamm" = eigenes Tier, „fremd" = externer Ahn,
/// „wurftier" = Welpe eines Wurfs (nur relevant, wenn nicht in ein stamm-Tier überführt).
/// </summary>
public enum Rpro3Src { Stamm, Fremd, Wurftier }
/// <summary>Einheitlicher Tier-Datensatz aus der RPRO3-SQLite (vor Dedup).
/// `Rid` ist die RPRO3-ID im jeweiligen Namensraum: "N"=stamm, "uN"=fremd, "XjY"=wurftier.</summary>
public sealed class Rpro3Animal
{
public required string Rid { get; init; }
public Rpro3Src Src { get; init; }
public string? Name { get; set; }
public Gender Gender { get; set; }
public DateOnly? Dob { get; set; }
public string? Farbe { get; set; } // _FARBE Farbschlagname
public string? Fcode { get; set; } // _FCODE 8-Locus-Genotyp
public string? Origin { get; set; } // aufgelöster Herkunfts-Name (herk_tb)
public int? OriginHerkId { get; set; } // herk_tb.id (1 = eigene Zucht)
public string? Zb { get; set; }
public string? MidRaw { get; set; } // Mutter-Ref im RPRO3-Namensraum
public string? PidRaw { get; set; } // Vater-Ref im RPRO3-Namensraum
public DateOnly? DateOfDeath { get; set; }
public string? CauseOfDeath { get; set; }
public string? Defects { get; set; } // _FEHLER
public bool IsCastrated { get; set; }
public int? StatusCode { get; set; } // stamm._STATUS (RPRO3)
// Dedup-Schlüssel (normalisiert), wird von Rpro3Dedup gesetzt.
public string NameKey { get; set; } = "";
public string FarbeKey { get; set; } = "";
public string OriginKey { get; set; } = "";
}
public sealed class Rpro3Litter
{
public required int Id { get; init; }
public string? Name { get; set; } // _BEZ "Wurf A"
public DateOnly? Date { get; set; } // _AM
public string? MotherRid { get; set; } // stamm-id als string
public string? FatherRid { get; set; }
public string? Notes { get; set; } // _BEM
}
public sealed class Rpro3Pup
{
public required string Id { get; init; } // "XjY"
public int WurfId { get; init; }
public string? Name { get; set; }
public Gender Gender { get; set; }
public DateOnly? Dob { get; set; }
public string? Sid { get; set; } // → stamm-id, falls als eigenes Tier behalten
public DateOnly? DateOfDeath { get; set; }
public string? CauseOfDeath { get; set; }
public DateOnly? AbgabeDate { get; set; }
public int? AbnId { get; set; } // → abn_tb
public decimal? Price { get; set; }
public string? Zb { get; set; }
public string? Defects { get; set; }
}
public sealed class Rpro3Contact
{
public required int Id { get; init; }
public required string Namespace { get; init; } // "herk" | "abn"
public string? Bez { get; set; }
public string? Anrede { get; set; }
public string? Vname { get; set; }
public string? Nname { get; set; }
public string? Clan { get; set; }
public string? Str { get; set; }
public string? Ort { get; set; }
public string? Plz { get; set; }
public string? Telp { get; set; }
public string? Teld { get; set; }
public string? Mail { get; set; }
public string? Http { get; set; }
public string? Memo { get; set; }
public string? Bem { get; set; }
/// <summary>Anzeigename: Bezeichnung/Cattery, sonst Clan, sonst Vor+Nachname.</summary>
public string DisplayName =>
FirstNonEmpty(Bez, Clan, $"{Vname} {Nname}".Trim()) ?? "Unbekannt";
private static string? FirstNonEmpty(params string?[] vals) =>
vals.FirstOrDefault(v => !string.IsNullOrWhiteSpace(v));
}
public sealed class Rpro3Weight
{
public required string Tid { get; init; } // stamm-id (waage) bzw. wurftier-id (jungwaage)
public DateOnly? Date { get; set; }
public int Grams { get; set; }
public string? Notes { get; set; }
}
public sealed class Rpro3Health
{
public required string Tid { get; init; }
public DateOnly? Date { get; set; }
public string? Description { get; set; }
public string? Medication { get; set; }
}
public sealed class Rpro3Diary
{
public required string Tid { get; init; }
public DateOnly? Date { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
}
public sealed class Rpro3PhotoSet
{
public required string Tid { get; init; } // stamm-id
public List<string> FileNames { get; } = new();
}
/// <summary>Vollständig geparster RPRO3-Backup-Inhalt.</summary>
public sealed class Rpro3Data
{
public List<Rpro3Animal> Animals { get; } = new(); // stamm + fremd
public Dictionary<int, Rpro3Litter> Litters { get; } = new();
public Dictionary<string, Rpro3Pup> Pups { get; } = new();
public Dictionary<string, Rpro3Contact> HerkContacts { get; } = new();
public Dictionary<string, Rpro3Contact> AbnContacts { get; } = new();
public List<Rpro3Weight> Weights { get; } = new();
public List<Rpro3Health> Health { get; } = new();
public List<Rpro3Diary> Diary { get; } = new();
public Dictionary<string, Rpro3PhotoSet> Photos { get; } = new();
// Roh-Zählungen (vor Dedup) für den Report.
public int ColorStammCount { get; set; }
public int ColorExtCount { get; set; }
/// <summary>Löst eine RPRO3-Ref ("N"/"uN"/"XjY") in einen Anzeigenamen auf (für Provenance/Report).</summary>
public Func<string?, string?> ResolveName { get; set; } = _ => null;
}
}