Răsfoiți Sursa

Erster Commit

Leonard Schulz 1 an în urmă
comite
f066b61493

+ 76 - 0
.gitignore

@@ -0,0 +1,76 @@
+# Gradle files
+.gradle/
+build/
+!gradle/wrapper/gradle-wrapper.jar
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+# Gradle Wrapper
+gradle-app.setting
+!gradle-wrapper.properties
+
+# Java compiled files
+*.class
+*.jar
+*.war
+*.ear
+*.nar
+hs_err_pid*
+
+# IDE files
+.idea/
+*.iws
+*.iml
+*.ipr
+out/
+.vscode/
+*.swp
+*.swo
+*~
+
+# Eclipse
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+# NetBeans
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+# OS generated files
+.DS_Store
+.DS_Store?
+._*
+.Spotlight-V100
+.Trashes
+ehthumbs.db
+Thumbs.db
+
+# Log files
+*.log
+
+# Spring Boot
+spring-boot-starter-*.jar
+
+# Temporary files
+*.tmp
+*.temp
+
+# Local environment variables
+.env
+.env.local
+.env.*.local
+
+# Application specific
+application-local.properties
+application-dev.properties

+ 27 - 0
build.gradle

@@ -0,0 +1,27 @@
+plugins {
+    id 'org.springframework.boot' version '3.3.2'
+    id 'io.spring.dependency-management' version '1.1.5'
+    id 'java'
+}
+
+java {
+    toolchain {
+        languageVersion = JavaLanguageVersion.of(21)
+    }
+}
+
+repositories {
+    mavenCentral()
+}
+
+dependencies {
+    implementation 'org.springframework.boot:spring-boot-starter-web'
+    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
+    implementation 'com.fasterxml.jackson.core:jackson-databind'
+    implementation 'com.networknt:json-schema-validator:1.4.2'
+    testImplementation 'org.springframework.boot:spring-boot-starter-test'
+}
+
+test {
+    useJUnitPlatform()
+}

+ 7 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists

+ 251 - 0
gradlew

@@ -0,0 +1,251 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+#   Gradle start up script for POSIX generated by Gradle.
+#
+#   Important for running:
+#
+#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+#       noncompliant, but you have some other compliant shell such as ksh or
+#       bash, then to run this script, type that shell name before the whole
+#       command line, like:
+#
+#           ksh Gradle
+#
+#       Busybox and similar reduced shells will NOT work, because this script
+#       requires all of these POSIX shell features:
+#         * functions;
+#         * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+#           «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+#         * compound commands having a testable exit status, especially «case»;
+#         * various built-in commands including «command», «set», and «ulimit».
+#
+#   Important for patching:
+#
+#   (2) This script targets any POSIX shell, so it avoids extensions provided
+#       by Bash, Ksh, etc; in particular arrays are avoided.
+#
+#       The "traditional" practice of packing multiple parameters into a
+#       space-separated string is a well documented source of bugs and security
+#       problems, so this is (mostly) avoided, by progressively accumulating
+#       options in "$@", and eventually passing that to Java.
+#
+#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+#       see the in-line comments for details.
+#
+#       There are tweaks for specific operating systems such as AIX, CygWin,
+#       Darwin, MinGW, and NonStop.
+#
+#   (3) This script is generated from the Groovy template
+#       https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+#       within the Gradle project.
+#
+#       You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+    APP_HOME=${app_path%"${app_path##*/}"}  # leaves a trailing /; empty if no leading path
+    [ -h "$app_path" ]
+do
+    ls=$( ls -ld "$app_path" )
+    link=${ls#*' -> '}
+    case $link in             #(
+      /*)   app_path=$link ;; #(
+      *)    app_path=$APP_HOME$link ;;
+    esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+    echo "$*"
+} >&2
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in                #(
+  CYGWIN* )         cygwin=true  ;; #(
+  Darwin* )         darwin=true  ;; #(
+  MSYS* | MINGW* )  msys=true    ;; #(
+  NONSTOP* )        nonstop=true ;;
+esac
+
+CLASSPATH="\\\"\\\""
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD=$JAVA_HOME/jre/sh/java
+    else
+        JAVACMD=$JAVA_HOME/bin/java
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD=java
+    if ! command -v java >/dev/null 2>&1
+    then
+        die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+    case $MAX_FD in #(
+      max*)
+        # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+        # shellcheck disable=SC2039,SC3045
+        MAX_FD=$( ulimit -H -n ) ||
+            warn "Could not query maximum file descriptor limit"
+    esac
+    case $MAX_FD in  #(
+      '' | soft) :;; #(
+      *)
+        # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+        # shellcheck disable=SC2039,SC3045
+        ulimit -n "$MAX_FD" ||
+            warn "Could not set maximum file descriptor limit to $MAX_FD"
+    esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+#   * args from the command line
+#   * the main class name
+#   * -classpath
+#   * -D...appname settings
+#   * --module-path (only if needed)
+#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+    APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+    CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+    JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    for arg do
+        if
+            case $arg in                                #(
+              -*)   false ;;                            # don't mess with options #(
+              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath
+                    [ -e "$t" ] ;;                      #(
+              *)    false ;;
+            esac
+        then
+            arg=$( cygpath --path --ignore --mixed "$arg" )
+        fi
+        # Roll the args list around exactly as many times as the number of
+        # args, so each arg winds up back in the position where it started, but
+        # possibly modified.
+        #
+        # NB: a `for` loop captures its iteration list before it begins, so
+        # changing the positional parameters here affects neither the number of
+        # iterations, nor the values presented in `arg`.
+        shift                   # remove old arg
+        set -- "$@" "$arg"      # push replacement arg
+    done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+#     and any embedded shellness will be escaped.
+#   * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+#     treated as '${Hostname}' itself on the command line.
+
+set -- \
+        "-Dorg.gradle.appname=$APP_BASE_NAME" \
+        -classpath "$CLASSPATH" \
+        -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
+        "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+    die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+#   readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+#   set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+        printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+        xargs -n1 |
+        sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+        tr '\n' ' '
+    )" '"$@"'
+
+exec "$JAVACMD" "$@"

+ 94 - 0
gradlew.bat

@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem      https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

+ 1 - 0
settings.gradle

@@ -0,0 +1 @@
+rootProject.name = 'inwo-vgl-service'

+ 12 - 0
src/main/java/com/tsystems/inwo/vgl/InwoVglServiceApplication.java

@@ -0,0 +1,12 @@
+package com.tsystems.inwo.vgl;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class InwoVglServiceApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(InwoVglServiceApplication.class, args);
+    }
+}

+ 8 - 0
src/main/java/com/tsystems/inwo/vgl/service/SchemaValidationService.java

@@ -0,0 +1,8 @@
+package com.tsystems.inwo.vgl.service;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.List;
+
+public interface SchemaValidationService {
+    List<String> validate(JsonNode data, String schemaName);
+}

+ 26 - 0
src/main/java/com/tsystems/inwo/vgl/service/impl/SchemaValidationServiceImpl.java

@@ -0,0 +1,26 @@
+package com.tsystems.inwo.vgl.service.impl;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.networknt.schema.*;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.stereotype.Service;
+import com.tsystems.inwo.vgl.service.SchemaValidationService;
+import java.io.InputStream;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class SchemaValidationServiceImpl implements SchemaValidationService {
+    
+    public List<String> validate(JsonNode data, String schemaName) {
+        try (InputStream in = new ClassPathResource("schemas/" + schemaName + ".schema.json").getInputStream()) {
+            JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V202012);
+            JsonSchema schema = factory.getSchema(in);
+            return schema.validate(data).stream()
+                    .map(ValidationMessage::getMessage)
+                    .collect(Collectors.toList());
+        } catch (Exception e) {
+            return List.of("Schema-Fehler: " + e.getMessage());
+        }
+    }
+}

+ 34 - 0
src/main/java/com/tsystems/inwo/vgl/util/FormatUtil.java

@@ -0,0 +1,34 @@
+package com.tsystems.inwo.vgl.util;
+
+import java.text.NumberFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.Locale;
+
+public final class FormatUtil {
+    private static final DateTimeFormatter D = DateTimeFormatter.ofPattern("dd.MM.yyyy");
+    private static final NumberFormat EUR = NumberFormat.getCurrencyInstance(Locale.GERMANY);
+    
+    private FormatUtil() {}
+    
+    public static String date(String iso) {
+        try {
+            return (iso == null || iso.isBlank()) ? "" : LocalDate.parse(iso).format(D);
+        } catch (Exception e) {
+            return iso == null ? "" : iso;
+        }
+    }
+    
+    public static String money(Number n) {
+        if (n == null) return "";
+        return EUR.format(n.doubleValue() / 100.0); // falls Werte in Cent
+    }
+    
+    public static String bool(Boolean b) {
+        return Boolean.TRUE.equals(b) ? "✓" : "–";
+    }
+    
+    public static String text(String s) {
+        return s == null ? "" : s;
+    }
+}

+ 5 - 0
src/main/java/com/tsystems/inwo/vgl/view/EinkommenZeile.java

@@ -0,0 +1,5 @@
+package com.tsystems.inwo.vgl.view;
+
+public record EinkommenZeile(String symbol, String symbolClass, String rowClass,
+                             String artHtml, String frequenzHtml, String betragHtml,
+                             String zuschlagHtml, String abschlagHtml, String werbungskostenHtml, String berechnungsartHtml) {}

+ 4 - 0
src/main/java/com/tsystems/inwo/vgl/view/FreibetragZeile.java

@@ -0,0 +1,4 @@
+package com.tsystems.inwo.vgl.view;
+
+public record FreibetragZeile(String symbol, String symbolClass, String rowClass,
+                              String artHtml, String frequenzHtml, String betragHtml, String fristHtml) {}

+ 4 - 0
src/main/java/com/tsystems/inwo/vgl/view/KitaZeile.java

@@ -0,0 +1,4 @@
+package com.tsystems.inwo.vgl.view;
+
+public record KitaZeile(String symbol, String symbolClass, String rowClass,
+                        String kindNameHtml, String betragHtml) {}

+ 5 - 0
src/main/java/com/tsystems/inwo/vgl/view/MitgliedRow.java

@@ -0,0 +1,5 @@
+package com.tsystems.inwo.vgl.view;
+
+public record MitgliedRow(String personId, String symbol, String symbolClass, String rowClass,
+                          String nameHtml, String geburtsdatumHtml, String familienstandHtml,
+                          String geschlechtHtml, String verwandtschaftHtml, String sozialstellungHtml, String istKindHtml) {}

+ 3 - 0
src/main/java/com/tsystems/inwo/vgl/view/Summary.java

@@ -0,0 +1,3 @@
+package com.tsystems.inwo.vgl.view;
+
+public record Summary(int added, int removed, int changed, int typeMismatch, int total) {}

+ 14 - 0
src/main/java/com/tsystems/inwo/vgl/web/HealthController.java

@@ -0,0 +1,14 @@
+package com.tsystems.inwo.vgl.web;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+import java.util.Map;
+
+@RestController
+public class HealthController {
+
+    @GetMapping("/api/health")
+    public Map<String, String> ok() {
+        return Map.of("status", "ok");
+    }
+}

+ 844 - 0
src/main/java/com/tsystems/inwo/vgl/web/VergleichController.java

@@ -0,0 +1,844 @@
+package com.tsystems.inwo.vgl.web;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.node.*;
+import com.tsystems.inwo.vgl.service.SchemaValidationService;
+import com.tsystems.inwo.vgl.util.FormatUtil;
+import com.tsystems.inwo.vgl.view.*;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Controller
+public class VergleichController {
+    private final ObjectMapper om;
+    private final SchemaValidationService validator;
+    
+    public VergleichController(ObjectMapper om, SchemaValidationService v) {
+        this.om = om;
+        this.validator = v;
+    }
+
+    @GetMapping("/test")
+    public String test(Model model) {
+        model.addAttribute("validate", true);
+        model.addAttribute("schemaName", "haushalt-einkommen");
+        return "test";
+    }
+
+    @PostMapping("/vergleich")
+    public String vergleich(
+            @RequestParam String leftJson,
+            @RequestParam String rightJson,
+            @RequestParam(required = false, defaultValue = "true") boolean validate,
+            @RequestParam(required = false, defaultValue = "haushalt-einkommen") String schemaName,
+            @RequestParam(required = false) String leftVorgangId,
+            @RequestParam(required = false) String leftZeitraumId,
+            @RequestParam(required = false) String rightZeitraumId,
+            @RequestParam(required = false) String personId,
+            Model model) throws Exception {
+
+        JsonNode left = om.readTree(leftJson);
+        JsonNode right = om.readTree(rightJson);
+
+        if (validate) {
+            List<String> err = new ArrayList<>();
+            err.addAll(validator.validate(left, schemaName));
+            err.addAll(validator.validate(right, schemaName));
+            if (!err.isEmpty()) {
+                model.addAttribute("schemaErrors", err);
+                model.addAttribute("leftJson", leftJson);
+                model.addAttribute("rightJson", rightJson);
+                model.addAttribute("validate", validate);
+                model.addAttribute("schemaName", schemaName);
+                // versuche dennoch Periodenlisten zu füllen (best-effort) optional
+                return "test";
+            }
+        }
+
+        // --- Rechts (Master) Zeitraum wählen ---
+        List<Z> zeitrechte = extractZeitraeume(right);
+        if (zeitrechte.isEmpty()) throw new IllegalArgumentException("Right JSON hat keine Zeiträume");
+        if (rightZeitraumId == null) rightZeitraumId = zeitrechte.get(0).id;
+        JsonNode rightZeitraum = findZeitraumById(right, rightZeitraumId);
+
+        // --- Find the stammvorgang that contains the selected zeitraum ---
+        JsonNode stammvorgangJsonNode = findStammvorgangByZeitraumId(right, rightZeitraumId);
+        StammvorgangInfo stammvorgangRight = createStammvorgangInfo(stammvorgangJsonNode);
+
+        // --- Links (Baseline) Kandidaten & Auswahl ---
+        List<Vorgang> leftCand = parseLeftCandidates(left);
+        List<Z> leftZ = List.of();
+        JsonNode leftZeitraum = null;
+        if (!leftCand.isEmpty()) {
+            if (leftVorgangId == null) leftVorgangId = leftCand.get(0).id;
+            final String finalLeftVorgangId = leftVorgangId;
+            leftZ = leftCand.stream().filter(v -> v.id.equals(finalLeftVorgangId)).findFirst().orElse(leftCand.get(0)).zeitraeume;
+            if (leftZeitraumId == null && !leftZ.isEmpty()) leftZeitraumId = leftZ.get(0).id;
+            if (leftZeitraumId != null) leftZeitraum = findZeitraumById(getRootOfVorgang(left, leftVorgangId), leftZeitraumId);
+        }
+
+        // --- Personenliste rechts + Default personId ---
+        List<PersonRef> personenRight = listRightPersons(rightZeitraum);
+        if (personId == null && !personenRight.isEmpty()) personId = personenRight.get(0).id;
+
+        // --- Personen-Tabelle (UNION via person.id) ---
+        Map<String, Pair<JsonNode, JsonNode>> personenPairs = unionByKey(
+                personsArray(rightZeitraum), personsArray(leftZeitraum), n -> n.path("person").path("id").asText()
+        );
+        List<MitgliedRow> mitgliederRows = personenPairs.entrySet().stream()
+                .map(e -> buildMitgliedRow(e.getKey(), e.getValue().right, e.getValue().left))
+                .sorted(Comparator.comparing(MitgliedRow::personId))
+                .toList();
+
+        // --- Details für ausgewählte Person ---
+        JsonNode rightPerson = personenPairs.getOrDefault(personId, new Pair<>(null, null)).right;
+        JsonNode leftPerson = personenPairs.getOrDefault(personId, new Pair<>(null, null)).left;
+
+        String personLabel = (rightPerson != null)
+                ? rightPerson.path("person").path("nachname").asText("") + ", " + rightPerson.path("person").path("vorname").asText("")
+                : "(keine Person)";
+        Map<String, String> personNameByIdRight = personenRight.stream().collect(Collectors.toMap(p -> p.id, p -> p.label));
+
+        // Einkommen / Freibeträge / Kita: jeweils UNION per id
+        List<EinkommenZeile> einkommenZeilen = buildEinkommenZeilen(rightPerson, leftPerson);
+        List<FreibetragZeile> freibetragZeilen = buildFreibetragZeilen(rightPerson, leftPerson);
+        List<KitaZeile> kitaZeilen = buildKitaZeilen(rightPerson, leftPerson, personNameByIdRight);
+
+        // Summary aus Status zählen (einfach aus allen Zeilen)
+        Summary summary = countSummary(mitgliederRows, einkommenZeilen, freibetragZeilen, kitaZeilen);
+
+        // --- Model füllen & rendern ---
+        model.addAttribute("leftJson", leftJson);
+        model.addAttribute("rightJson", rightJson);
+        model.addAttribute("validate", validate);
+        model.addAttribute("schemaName", schemaName);
+        model.addAttribute("leftCandidates", leftCand);
+        model.addAttribute("leftZeitraeumeOfSelected", leftZ);
+        model.addAttribute("leftVorgangId", leftVorgangId);
+        model.addAttribute("leftZeitraumId", leftZeitraumId);
+        model.addAttribute("zeitraeumeRight", zeitrechte);
+        model.addAttribute("rightZeitraumId", rightZeitraumId);
+        model.addAttribute("stammvorgangRight", stammvorgangRight);
+        model.addAttribute("personenRight", personenRight);
+        model.addAttribute("personId", personId);
+        model.addAttribute("mitgliederRows", mitgliederRows);
+        model.addAttribute("personLabel", personLabel);
+        model.addAttribute("einkommenZeilen", einkommenZeilen);
+        model.addAttribute("freibetragZeilen", freibetragZeilen);
+        model.addAttribute("kitaZeilen", kitaZeilen);
+        model.addAttribute("summary", summary);
+        return "vergleich";
+    }
+
+    // ===== Helper-Typen =====
+    public record Z(String id, String beginn, String ende) {}
+    public record Vorgang(String id, String aktenzeichen, List<Z> zeitraeume) {}
+    public record PersonRef(String id, String label) {}
+    public record StammvorgangInfo(String id, String aktenzeichen, String beginn, String ende, String bemerkung) {}
+    public static final class Pair<R, L> {
+        public final R right;
+        public final L left;
+        public Pair(R r, L l) {
+            right = r;
+            left = l;
+        }
+    }
+
+    // ===== Helper-Methoden =====
+    private static StammvorgangInfo createStammvorgangInfo(JsonNode stammvorgangNode) {
+        if (stammvorgangNode == null || stammvorgangNode.isMissingNode()) {
+            return new StammvorgangInfo("", "", "", "", "");
+        }
+        
+        String id = stammvorgangNode.path("id").asText("");
+        String aktenzeichen = stammvorgangNode.path("aktenzeichen").asText("");
+        String beginn = stammvorgangNode.path("beginn").asText("");
+        String ende = stammvorgangNode.path("ende").asText("");
+        String bemerkung = stammvorgangNode.path("bemerkung").asText("");
+        
+        return new StammvorgangInfo(id, aktenzeichen, beginn, ende, bemerkung);
+    }
+
+    private static List<Z> extractZeitraeume(JsonNode root) {
+        List<Z> result = new ArrayList<>();
+        
+        // Check if this is the new vorgaenge structure
+        if (root.has("vorgaenge") && root.get("vorgaenge").isArray()) {
+            // For vorgaenge structure, collect zeitraeume from all vorgaenge
+            for (JsonNode vorgang : root.get("vorgaenge")) {
+                if (vorgang.has("zeitraeume") && vorgang.get("zeitraeume").isArray()) {
+                    for (JsonNode zeitraum : vorgang.get("zeitraeume")) {
+                        String id = zeitraum.path("id").asText("");
+                        String beginn = zeitraum.path("beginn").asText("");
+                        String ende = zeitraum.path("ende").asText("");
+                        result.add(new Z(id, beginn, ende));
+                    }
+                }
+            }
+        } else if (root.has("zeitraeume") && root.get("zeitraeume").isArray()) {
+            // Legacy single vorgang structure
+            for (JsonNode zeitraum : root.get("zeitraeume")) {
+                String id = zeitraum.path("id").asText("");
+                String beginn = zeitraum.path("beginn").asText("");
+                String ende = zeitraum.path("ende").asText("");
+                result.add(new Z(id, beginn, ende));
+            }
+        }
+        
+        return result;
+    }
+    
+    private static JsonNode findZeitraumById(JsonNode root, String id) {
+        // Check if this is the new vorgaenge structure
+        if (root.has("vorgaenge") && root.get("vorgaenge").isArray()) {
+            // Search in all vorgaenge
+            for (JsonNode vorgang : root.get("vorgaenge")) {
+                if (vorgang.has("zeitraeume") && vorgang.get("zeitraeume").isArray()) {
+                    for (JsonNode zeitraum : vorgang.get("zeitraeume")) {
+                        if (id.equals(zeitraum.path("id").asText(""))) {
+                            return zeitraum;
+                        }
+                    }
+                }
+            }
+        } else if (root.has("zeitraeume") && root.get("zeitraeume").isArray()) {
+            // Legacy single vorgang structure
+            for (JsonNode zeitraum : root.get("zeitraeume")) {
+                if (id.equals(zeitraum.path("id").asText(""))) {
+                    return zeitraum;
+                }
+            }
+        }
+        return NullNode.getInstance();
+    }
+    
+    private static JsonNode findStammvorgangByZeitraumId(JsonNode root, String zeitraumId) {
+        // Check if this is the new vorgaenge structure
+        if (root.has("vorgaenge") && root.get("vorgaenge").isArray()) {
+            // Search in all vorgaenge for the one containing this zeitraum
+            for (JsonNode vorgang : root.get("vorgaenge")) {
+                if (vorgang.has("zeitraeume") && vorgang.get("zeitraeume").isArray()) {
+                    for (JsonNode zeitraum : vorgang.get("zeitraeume")) {
+                        if (zeitraumId.equals(zeitraum.path("id").asText(""))) {
+                            return vorgang.path("stammvorgang");
+                        }
+                    }
+                }
+            }
+        } else {
+            // Legacy single vorgang structure - stammvorgang is at root level
+            return root.path("stammvorgang");
+        }
+        return NullNode.getInstance();
+    }
+    
+    private static List<Vorgang> parseLeftCandidates(JsonNode left) {
+        List<Vorgang> result = new ArrayList<>();
+        
+        if (left.has("vorgaenge") && left.get("vorgaenge").isArray()) {
+            // a) wenn left.vorgaenge Array
+            for (JsonNode v : left.get("vorgaenge")) {
+                JsonNode stammvorgang = v.path("stammvorgang");
+                String id = stammvorgang.path("id").asText("");
+                String aktenzeichen = stammvorgang.path("aktenzeichen").asText("");
+                List<Z> zeitraeume = extractZeitraeume(v);
+                result.add(new Vorgang(id, aktenzeichen, zeitraeume));
+            }
+        } else {
+            // b) sonst: single vorgang
+            JsonNode stammvorgang = left.path("stammvorgang");
+            String id = stammvorgang.path("id").asText("");
+            String aktenzeichen = stammvorgang.path("aktenzeichen").asText("");
+            List<Z> zeitraeume = extractZeitraeume(left);
+            result.add(new Vorgang(id, aktenzeichen, zeitraeume));
+        }
+        
+        return result;
+    }
+    
+    private static JsonNode getRootOfVorgang(JsonNode left, String vorgangId) {
+        if (left.has("vorgaenge") && left.get("vorgaenge").isArray()) {
+            for (JsonNode v : left.get("vorgaenge")) {
+                if (vorgangId.equals(v.path("stammvorgang").path("id").asText(""))) {
+                    return v;
+                }
+            }
+        }
+        return left;
+    }
+    
+    private static List<PersonRef> listRightPersons(JsonNode zeitraum) {
+        List<PersonRef> result = new ArrayList<>();
+        if (zeitraum != null && zeitraum.has("personen") && zeitraum.get("personen").isArray()) {
+            for (JsonNode personImZeitraum : zeitraum.get("personen")) {
+                JsonNode person = personImZeitraum.path("person");
+                String id = person.path("id").asText("");
+                String nachname = person.path("nachname").asText("");
+                String vorname = person.path("vorname").asText("");
+                String geburtsdatum = person.path("geburtsdatum").asText("");
+                
+                String label = nachname + ", " + vorname;
+                if (!geburtsdatum.isEmpty()) {
+                    label += " (" + FormatUtil.date(geburtsdatum) + ")";
+                }
+                
+                result.add(new PersonRef(id, label));
+            }
+        }
+        return result;
+    }
+    
+    private static ArrayNode personsArray(JsonNode zeitraum) {
+        return zeitraum != null && zeitraum.has("personen") && zeitraum.get("personen").isArray()
+                ? (ArrayNode) zeitraum.get("personen")
+                : new ObjectMapper().createArrayNode();
+    }
+    
+    private static <T> Map<String, Pair<JsonNode, JsonNode>> unionByKey(ArrayNode rightArr, ArrayNode leftArr, Function<JsonNode, String> keyFn) {
+        Map<String, Pair<JsonNode, JsonNode>> result = new LinkedHashMap<>();
+        
+        // Add all right items
+        for (JsonNode node : rightArr) {
+            String key = keyFn.apply(node);
+            result.put(key, new Pair<>(node, null));
+        }
+        
+        // Merge left items
+        for (JsonNode node : leftArr) {
+            String key = keyFn.apply(node);
+            result.merge(key, new Pair<>(null, node), (existing, newPair) -> 
+                new Pair<>(existing.right, newPair.left));
+        }
+        
+        return result;
+    }
+    
+    private static MitgliedRow buildMitgliedRow(String personId, JsonNode rightItem, JsonNode leftItem) {
+        // Extract person data from both items
+        JsonNode rightPerson = rightItem != null ? rightItem.path("person") : null;
+        JsonNode leftPerson = leftItem != null ? leftItem.path("person") : null;
+        
+        // Determine status and detect changes
+        String symbol = "";
+        String symbolClass = "";
+        String rowClass = "";
+        boolean hasChanges = false;
+        
+        if (rightItem != null && leftItem != null) {
+            // Both exist - check for changes
+            hasChanges = detectPersonChanges(rightItem, rightPerson, leftItem, leftPerson);
+            if (hasChanges) {
+                symbol = symFor("CHANGED");
+                symbolClass = symClassFor("CHANGED");
+                rowClass = "";
+            }
+        } else if (rightItem != null && leftItem == null) {
+            symbol = symFor("ADDED");
+            symbolClass = symClassFor("ADDED");
+            rowClass = rowClassFor("ADDED");
+        } else if (rightItem == null && leftItem != null) {
+            symbol = symFor("REMOVED");
+            symbolClass = symClassFor("REMOVED");
+            rowClass = rowClassFor("REMOVED");
+        }
+        
+        // Use right (current) data as primary, fall back to left for missing data
+        JsonNode primaryPerson = rightPerson != null ? rightPerson : leftPerson;
+        JsonNode primaryItem = rightItem != null ? rightItem : leftItem;
+        
+        if (primaryPerson == null) {
+            return new MitgliedRow(personId, symbol, symbolClass, rowClass, "", "", "", "", "", "", "");
+        }
+        
+        // Extract data with change detection for HTML
+        String nameHtml = buildPersonFieldHtml(
+            rightPerson, leftPerson, 
+            p -> p.path("nachname").asText("") + ", " + p.path("vorname").asText(""),
+            hasChanges
+        );
+        
+        String geburtsdatumHtml = buildPersonFieldHtml(
+            rightPerson, leftPerson,
+            p -> !p.path("geburtsdatum").asText("").isEmpty() ? FormatUtil.date(p.path("geburtsdatum").asText("")) : "",
+            hasChanges
+        );
+        
+        String familienstandHtml = buildPersonFieldHtml(
+            rightPerson, leftPerson,
+            p -> p.path("familienstand").asText(""),
+            hasChanges
+        );
+        
+        String geschlechtHtml = buildPersonFieldHtml(
+            rightPerson, leftPerson,
+            p -> p.path("geschlecht").asText(""),
+            hasChanges
+        );
+        
+        String verwandtschaftHtml = buildItemFieldHtml(
+            rightItem, leftItem,
+            i -> i.path("verwandtschaft").asText(""),
+            hasChanges
+        );
+        
+        String sozialstellungHtml = buildItemFieldHtml(
+            rightItem, leftItem,
+            i -> i.path("sozialstellung").asText(""),
+            hasChanges
+        );
+        
+        String istKindHtml = buildItemFieldHtml(
+            rightItem, leftItem,
+            i -> i.path("istKind").asBoolean(false) ? "Ja" : "Nein",
+            hasChanges
+        );
+        
+        return new MitgliedRow(
+            personId,
+            symbol,
+            symbolClass,
+            rowClass,
+            nameHtml,
+            geburtsdatumHtml,
+            familienstandHtml,
+            geschlechtHtml,
+            verwandtschaftHtml,
+            sozialstellungHtml,
+            istKindHtml
+        );
+    }
+    
+    private static boolean detectPersonChanges(JsonNode rightItem, JsonNode rightPerson, JsonNode leftItem, JsonNode leftPerson) {
+        if (rightPerson == null || leftPerson == null) return false;
+        
+        // Check person fields
+        return !Objects.equals(rightPerson.path("nachname").asText(""), leftPerson.path("nachname").asText("")) ||
+               !Objects.equals(rightPerson.path("vorname").asText(""), leftPerson.path("vorname").asText("")) ||
+               !Objects.equals(rightPerson.path("geburtsdatum").asText(""), leftPerson.path("geburtsdatum").asText("")) ||
+               !Objects.equals(rightPerson.path("familienstand").asText(""), leftPerson.path("familienstand").asText("")) ||
+               !Objects.equals(rightPerson.path("geschlecht").asText(""), leftPerson.path("geschlecht").asText("")) ||
+               !Objects.equals(rightItem.path("verwandtschaft").asText(""), leftItem.path("verwandtschaft").asText("")) ||
+               !Objects.equals(rightItem.path("sozialstellung").asText(""), leftItem.path("sozialstellung").asText("")) ||
+               rightItem.path("istKind").asBoolean(false) != leftItem.path("istKind").asBoolean(false);
+    }
+    
+    private static String buildPersonFieldHtml(JsonNode rightPerson, JsonNode leftPerson, Function<JsonNode, String> extractor, boolean hasChanges) {
+        if (!hasChanges || rightPerson == null) {
+            JsonNode primary = rightPerson != null ? rightPerson : leftPerson;
+            return primary != null ? escape(extractor.apply(primary)) : "";
+        }
+        
+        String rightVal = rightPerson != null ? extractor.apply(rightPerson) : "";
+        String leftVal = leftPerson != null ? extractor.apply(leftPerson) : "";
+        
+        if (!Objects.equals(rightVal, leftVal)) {
+            return cellHtml(rightVal, leftVal, true);
+        } else {
+            return escape(rightVal);
+        }
+    }
+    
+    private static String buildItemFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
+        if (!hasChanges || rightItem == null) {
+            JsonNode primary = rightItem != null ? rightItem : leftItem;
+            return primary != null ? escape(extractor.apply(primary)) : "";
+        }
+        
+        String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
+        String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
+        
+        if (!Objects.equals(rightVal, leftVal)) {
+            return cellHtml(rightVal, leftVal, true);
+        } else {
+            return escape(rightVal);
+        }
+    }
+    
+    private static List<EinkommenZeile> buildEinkommenZeilen(JsonNode rightPerson, JsonNode leftPerson) {
+        // Extract einkommen arrays from both persons
+        ArrayNode rightEinkommen = rightPerson != null && rightPerson.has("einkommen") && rightPerson.get("einkommen").isArray()
+                ? (ArrayNode) rightPerson.get("einkommen")
+                : new ObjectMapper().createArrayNode();
+        ArrayNode leftEinkommen = leftPerson != null && leftPerson.has("einkommen") && leftPerson.get("einkommen").isArray()
+                ? (ArrayNode) leftPerson.get("einkommen")
+                : new ObjectMapper().createArrayNode();
+        
+        // UNION über einkommen[].id
+        Map<String, Pair<JsonNode, JsonNode>> einkommenPairs = unionByKey(
+                rightEinkommen, leftEinkommen, n -> n.path("id").asText()
+        );
+        
+        List<EinkommenZeile> result = new ArrayList<>();
+        for (Map.Entry<String, Pair<JsonNode, JsonNode>> entry : einkommenPairs.entrySet()) {
+            JsonNode rightItem = entry.getValue().right;
+            JsonNode leftItem = entry.getValue().left;
+            
+            // Determine status and changes
+            String symbol = "";
+            String symbolClass = "";
+            String rowClass = "";
+            boolean hasChanges = false;
+            
+            if (rightItem != null && leftItem != null) {
+                hasChanges = detectEinkommenChanges(rightItem, leftItem);
+                if (hasChanges) {
+                    symbol = symFor("CHANGED");
+                    symbolClass = symClassFor("CHANGED");
+                }
+            } else if (rightItem != null && leftItem == null) {
+                symbol = symFor("ADDED");
+                symbolClass = symClassFor("ADDED");
+                rowClass = rowClassFor("ADDED");
+            } else if (rightItem == null && leftItem != null) {
+                symbol = symFor("REMOVED");
+                symbolClass = symClassFor("REMOVED");
+                rowClass = rowClassFor("REMOVED");
+            }
+            
+            // Use primary data (right first, then left)
+            JsonNode primaryItem = rightItem != null ? rightItem : leftItem;
+            
+            if (primaryItem != null) {
+                String artHtml = buildEinkommenFieldHtml(rightItem, leftItem, 
+                    i -> {
+                        String art = i.path("art").asText("");
+                        String artZusatz = i.path("artZusatz").asText("");
+                        return !artZusatz.isEmpty() ? art + " (" + artZusatz + ")" : art;
+                    }, hasChanges);
+                
+                String frequenzHtml = buildEinkommenFieldHtml(rightItem, leftItem,
+                    i -> {
+                        int frequenz = i.path("frequenz").asInt(1);
+                        return frequenz == 1 ? "monatlich" : 
+                               frequenz == 12 ? "jährlich" : 
+                               frequenz + "x/Jahr";
+                    }, hasChanges);
+                
+                String betragHtml = buildEinkommenFieldHtml(rightItem, leftItem,
+                    i -> String.format("%.2f €", i.path("betrag").asDouble(0.0)), hasChanges);
+                
+                String zuschlagHtml = buildEinkommenFieldHtml(rightItem, leftItem,
+                    i -> {
+                        double zuschlag = i.path("zuschlag").asDouble(0.0);
+                        return zuschlag > 0 ? String.format("%.2f €", zuschlag) : "";
+                    }, hasChanges);
+                
+                String abschlagHtml = buildEinkommenFieldHtml(rightItem, leftItem,
+                    i -> {
+                        double abschlag = i.path("abschlag").asDouble(0.0);
+                        return abschlag > 0 ? String.format("%.2f €", abschlag) : "";
+                    }, hasChanges);
+                
+                String werbungskostenHtml = buildEinkommenFieldHtml(rightItem, leftItem,
+                    i -> {
+                        double werbungskosten = i.path("werbungskosten").asDouble(0.0);
+                        return werbungskosten > 0 ? String.format("%.2f €", werbungskosten) : "";
+                    }, hasChanges);
+                
+                String berechnungsartHtml = buildEinkommenFieldHtml(rightItem, leftItem,
+                    i -> i.path("berechnungsart").asText(""), hasChanges);
+                
+                result.add(new EinkommenZeile(
+                    symbol, symbolClass, rowClass,
+                    artHtml, frequenzHtml, betragHtml,
+                    zuschlagHtml, abschlagHtml, werbungskostenHtml, berechnungsartHtml
+                ));
+            }
+        }
+        
+        return result;
+    }
+    
+    private static boolean detectEinkommenChanges(JsonNode rightItem, JsonNode leftItem) {
+        return !Objects.equals(rightItem.path("art").asText(""), leftItem.path("art").asText("")) ||
+               !Objects.equals(rightItem.path("artZusatz").asText(""), leftItem.path("artZusatz").asText("")) ||
+               rightItem.path("frequenz").asInt(1) != leftItem.path("frequenz").asInt(1) ||
+               rightItem.path("betrag").asDouble(0.0) != leftItem.path("betrag").asDouble(0.0) ||
+               rightItem.path("zuschlag").asDouble(0.0) != leftItem.path("zuschlag").asDouble(0.0) ||
+               rightItem.path("abschlag").asDouble(0.0) != leftItem.path("abschlag").asDouble(0.0) ||
+               rightItem.path("werbungskosten").asDouble(0.0) != leftItem.path("werbungskosten").asDouble(0.0) ||
+               !Objects.equals(rightItem.path("berechnungsart").asText(""), leftItem.path("berechnungsart").asText(""));
+    }
+    
+    private static String buildEinkommenFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
+        if (!hasChanges || rightItem == null) {
+            JsonNode primary = rightItem != null ? rightItem : leftItem;
+            return primary != null ? escape(extractor.apply(primary)) : "";
+        }
+        
+        String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
+        String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
+        
+        if (!Objects.equals(rightVal, leftVal)) {
+            return cellHtml(rightVal, leftVal, true);
+        } else {
+            return escape(rightVal);
+        }
+    }
+    
+    private static List<FreibetragZeile> buildFreibetragZeilen(JsonNode rightPerson, JsonNode leftPerson) {
+        // Extract freibetraege arrays from both persons
+        ArrayNode rightFreibetraege = rightPerson != null && rightPerson.has("freibetraege") && rightPerson.get("freibetraege").isArray()
+                ? (ArrayNode) rightPerson.get("freibetraege")
+                : new ObjectMapper().createArrayNode();
+        ArrayNode leftFreibetraege = leftPerson != null && leftPerson.has("freibetraege") && leftPerson.get("freibetraege").isArray()
+                ? (ArrayNode) leftPerson.get("freibetraege")
+                : new ObjectMapper().createArrayNode();
+        
+        // UNION über freibetraege[].id
+        Map<String, Pair<JsonNode, JsonNode>> freibetragPairs = unionByKey(
+                rightFreibetraege, leftFreibetraege, n -> n.path("id").asText()
+        );
+        
+        List<FreibetragZeile> result = new ArrayList<>();
+        for (Map.Entry<String, Pair<JsonNode, JsonNode>> entry : freibetragPairs.entrySet()) {
+            JsonNode rightItem = entry.getValue().right;
+            JsonNode leftItem = entry.getValue().left;
+            
+            // Determine status and changes
+            String symbol = "";
+            String symbolClass = "";
+            String rowClass = "";
+            boolean hasChanges = false;
+            
+            if (rightItem != null && leftItem != null) {
+                hasChanges = detectFreibetragChanges(rightItem, leftItem);
+                if (hasChanges) {
+                    symbol = symFor("CHANGED");
+                    symbolClass = symClassFor("CHANGED");
+                }
+            } else if (rightItem != null && leftItem == null) {
+                symbol = symFor("ADDED");
+                symbolClass = symClassFor("ADDED");
+                rowClass = rowClassFor("ADDED");
+            } else if (rightItem == null && leftItem != null) {
+                symbol = symFor("REMOVED");
+                symbolClass = symClassFor("REMOVED");
+                rowClass = rowClassFor("REMOVED");
+            }
+            
+            // Use primary data (right first, then left)
+            JsonNode primaryItem = rightItem != null ? rightItem : leftItem;
+            
+            if (primaryItem != null) {
+                String artHtml = buildFreibetragFieldHtml(rightItem, leftItem,
+                    i -> i.path("art").asText(""), hasChanges);
+                
+                String frequenzHtml = buildFreibetragFieldHtml(rightItem, leftItem,
+                    i -> {
+                        int frequenz = i.path("frequenz").asInt(1);
+                        return frequenz == 1 ? "monatlich" : 
+                               frequenz == 12 ? "jährlich" : 
+                               frequenz + "x/Jahr";
+                    }, hasChanges);
+                
+                String betragHtml = buildFreibetragFieldHtml(rightItem, leftItem,
+                    i -> String.format("%.2f €", i.path("betrag").asDouble(0.0)), hasChanges);
+                
+                String fristHtml = buildFreibetragFieldHtml(rightItem, leftItem,
+                    i -> {
+                        String fristDatum = i.path("fristDatum").asText("");
+                        return !fristDatum.isEmpty() ? FormatUtil.date(fristDatum) : "";
+                    }, hasChanges);
+                
+                result.add(new FreibetragZeile(
+                    symbol, symbolClass, rowClass,
+                    artHtml, frequenzHtml, betragHtml, fristHtml
+                ));
+            }
+        }
+        
+        return result;
+    }
+    
+    private static boolean detectFreibetragChanges(JsonNode rightItem, JsonNode leftItem) {
+        return !Objects.equals(rightItem.path("art").asText(""), leftItem.path("art").asText("")) ||
+               rightItem.path("frequenz").asInt(1) != leftItem.path("frequenz").asInt(1) ||
+               rightItem.path("betrag").asDouble(0.0) != leftItem.path("betrag").asDouble(0.0) ||
+               !Objects.equals(rightItem.path("fristDatum").asText(""), leftItem.path("fristDatum").asText(""));
+    }
+    
+    private static String buildFreibetragFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
+        if (!hasChanges || rightItem == null) {
+            JsonNode primary = rightItem != null ? rightItem : leftItem;
+            return primary != null ? escape(extractor.apply(primary)) : "";
+        }
+        
+        String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
+        String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
+        
+        if (!Objects.equals(rightVal, leftVal)) {
+            return cellHtml(rightVal, leftVal, true);
+        } else {
+            return escape(rightVal);
+        }
+    }
+    
+    private static List<KitaZeile> buildKitaZeilen(JsonNode rightPerson, JsonNode leftPerson, Map<String, String> personNameByIdRight) {
+        // Extract kinderbetreuung arrays from both persons
+        ArrayNode rightKinderbetreuung = rightPerson != null && rightPerson.has("kinderbetreuung") && rightPerson.get("kinderbetreuung").isArray()
+                ? (ArrayNode) rightPerson.get("kinderbetreuung")
+                : new ObjectMapper().createArrayNode();
+        ArrayNode leftKinderbetreuung = leftPerson != null && leftPerson.has("kinderbetreuung") && leftPerson.get("kinderbetreuung").isArray()
+                ? (ArrayNode) leftPerson.get("kinderbetreuung")
+                : new ObjectMapper().createArrayNode();
+        
+        // UNION über kinderbetreuung[].id
+        Map<String, Pair<JsonNode, JsonNode>> kitaPairs = unionByKey(
+                rightKinderbetreuung, leftKinderbetreuung, n -> n.path("id").asText()
+        );
+        
+        List<KitaZeile> result = new ArrayList<>();
+        for (Map.Entry<String, Pair<JsonNode, JsonNode>> entry : kitaPairs.entrySet()) {
+            JsonNode rightItem = entry.getValue().right;
+            JsonNode leftItem = entry.getValue().left;
+            
+            // Determine status and changes
+            String symbol = "";
+            String symbolClass = "";
+            String rowClass = "";
+            boolean hasChanges = false;
+            
+            if (rightItem != null && leftItem != null) {
+                hasChanges = detectKitaChanges(rightItem, leftItem);
+                if (hasChanges) {
+                    symbol = symFor("CHANGED");
+                    symbolClass = symClassFor("CHANGED");
+                }
+            } else if (rightItem != null && leftItem == null) {
+                symbol = symFor("ADDED");
+                symbolClass = symClassFor("ADDED");
+                rowClass = rowClassFor("ADDED");
+            } else if (rightItem == null && leftItem != null) {
+                symbol = symFor("REMOVED");
+                symbolClass = symClassFor("REMOVED");
+                rowClass = rowClassFor("REMOVED");
+            }
+            
+            // Use primary data (right first, then left)
+            JsonNode primaryItem = rightItem != null ? rightItem : leftItem;
+            
+            if (primaryItem != null) {
+                String kindNameHtml = buildKitaFieldHtml(rightItem, leftItem,
+                    i -> {
+                        String kindRef = i.path("kindRef").asText("");
+                        return personNameByIdRight.getOrDefault(kindRef, "Kind ID: " + kindRef);
+                    }, hasChanges);
+                
+                String betragHtml = buildKitaFieldHtml(rightItem, leftItem,
+                    i -> String.format("%.2f €", i.path("betrag").asDouble(0.0)), hasChanges);
+                
+                result.add(new KitaZeile(
+                    symbol, symbolClass, rowClass,
+                    kindNameHtml, betragHtml
+                ));
+            }
+        }
+        
+        return result;
+    }
+    
+    private static boolean detectKitaChanges(JsonNode rightItem, JsonNode leftItem) {
+        return !Objects.equals(rightItem.path("kindRef").asText(""), leftItem.path("kindRef").asText("")) ||
+               rightItem.path("betrag").asDouble(0.0) != leftItem.path("betrag").asDouble(0.0);
+    }
+    
+    private static String buildKitaFieldHtml(JsonNode rightItem, JsonNode leftItem, Function<JsonNode, String> extractor, boolean hasChanges) {
+        if (!hasChanges || rightItem == null) {
+            JsonNode primary = rightItem != null ? rightItem : leftItem;
+            return primary != null ? escape(extractor.apply(primary)) : "";
+        }
+        
+        String rightVal = rightItem != null ? extractor.apply(rightItem) : "";
+        String leftVal = leftItem != null ? extractor.apply(leftItem) : "";
+        
+        if (!Objects.equals(rightVal, leftVal)) {
+            return cellHtml(rightVal, leftVal, true);
+        } else {
+            return escape(rightVal);
+        }
+    }
+    
+    private static Summary countSummary(List<MitgliedRow> m, List<EinkommenZeile> e, List<FreibetragZeile> f, List<KitaZeile> k) {
+        int added = 0, removed = 0, changed = 0, typeMismatch = 0;
+        
+        // Count MitgliedRow changes
+        for (MitgliedRow row : m) {
+            if ("plus".equals(row.symbolClass())) added++;
+            else if ("minus".equals(row.symbolClass())) removed++;
+            else if ("warn".equals(row.symbolClass())) changed++;
+        }
+        
+        // Count EinkommenZeile changes
+        for (EinkommenZeile row : e) {
+            if ("plus".equals(row.symbolClass())) added++;
+            else if ("minus".equals(row.symbolClass())) removed++;
+            else if ("warn".equals(row.symbolClass())) changed++;
+        }
+        
+        // Count FreibetragZeile changes
+        for (FreibetragZeile row : f) {
+            if ("plus".equals(row.symbolClass())) added++;
+            else if ("minus".equals(row.symbolClass())) removed++;
+            else if ("warn".equals(row.symbolClass())) changed++;
+        }
+        
+        // Count KitaZeile changes
+        for (KitaZeile row : k) {
+            if ("plus".equals(row.symbolClass())) added++;
+            else if ("minus".equals(row.symbolClass())) removed++;
+            else if ("warn".equals(row.symbolClass())) changed++;
+        }
+        
+        int total = added + removed + changed + typeMismatch;
+        return new Summary(added, removed, changed, typeMismatch, total);
+    }
+
+    // Hilfs-Bausteine für Status und Zellen:
+    private static String symFor(String status) {
+        return switch (status) {
+            case "ADDED" -> "+";
+            case "REMOVED" -> "−";
+            case "CHANGED" -> "!";
+            default -> "";
+        };
+    }
+    
+    private static String symClassFor(String status) {
+        return switch (status) {
+            case "ADDED" -> "plus";
+            case "REMOVED" -> "minus";
+            case "CHANGED" -> "warn";
+            default -> "";
+        };
+    }
+    
+    private static String rowClassFor(String status) {
+        return switch (status) {
+            case "ADDED" -> "diff-row-added";
+            case "REMOVED" -> "diff-row-removed";
+            default -> "";
+        };
+    }
+    
+    private static String cellHtml(String newVal, String oldVal, boolean changed) {
+        if (!changed) {
+            return escape(newVal);
+        }
+        
+        // Handle empty old values
+        String displayOldVal = (oldVal == null || oldVal.trim().isEmpty()) ? "leer" : oldVal;
+        
+        // Return with cell-changed class and proper old value display
+        return "<span class='cell-changed'>" + escape(newVal) + 
+               "<div class='old'>Alt: " + escape(displayOldVal) + "</div></span>";
+    }
+    
+    private static String escape(String s) {
+        return s == null ? "" : s.replace("&", "&").replace("<", "<").replace(">", ">");
+    }
+}

+ 1 - 0
src/main/resources/application.properties

@@ -0,0 +1 @@
+server.compression.enabled=true

+ 343 - 0
src/main/resources/schemas/haushalt-einkommen.schema.json

@@ -0,0 +1,343 @@
+{
+  "$id": "https://example.com/haushalt-einkommen.schema.json",
+  "$schema": "https://json-schema.org/draft/2020-12/schema",
+  "title": "Vergleichsansicht – Seite Haushaltsmitglieder & Einkommen",
+  "description": "Seite mit Vorgängen → Zeiträume → Personen je Zeitraum inkl. Einkommen, Freibeträge, Kinderbetreuung.",
+  "type": "object",
+  "oneOf": [
+    {
+      "additionalProperties": false,
+      "properties": {
+        "vorgaenge": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/Vorgang"
+          }
+        }
+      },
+      "required": ["vorgaenge"]
+    },
+    {
+      "additionalProperties": false,
+      "properties": {
+        "stammvorgang": {
+          "$ref": "#/$defs/Stammvorgang"
+        },
+        "zeitraeume": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/Zeitraum"
+          }
+        }
+      },
+      "required": ["stammvorgang", "zeitraeume"]
+    }
+  ],
+  "$defs": {
+    "Vorgang": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "stammvorgang": {
+          "$ref": "#/$defs/Stammvorgang"
+        },
+        "zeitraeume": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/Zeitraum"
+          }
+        }
+      },
+      "required": ["stammvorgang", "zeitraeume"]
+    },
+    "Stammvorgang": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "id": {
+          "type": "string"
+        },
+        "aktenzeichen": {
+          "type": "string"
+        },
+        "beginn": {
+          "type": "string",
+          "format": "date"
+        },
+        "ende": {
+          "type": "string",
+          "format": "date"
+        },
+        "bemerkung": {
+          "type": "string"
+        }
+      },
+      "required": ["id"]
+    },
+    "Adresse": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "strasse": {
+          "type": "string"
+        },
+        "hausnummer": {
+          "type": "string"
+        },
+        "zusatz": {
+          "type": "string"
+        },
+        "plz": {
+          "type": "string",
+          "pattern": "^[0-9]{5}$"
+        },
+        "ort": {
+          "type": "string"
+        }
+      }
+    },
+    "PersonBasis": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "id": {
+          "type": "string",
+          "description": "Interne ID in dieser Ansicht"
+        },
+        "nachname": {
+          "type": "string"
+        },
+        "vorname": {
+          "type": "string"
+        },
+        "geburtsname": {
+          "type": "string"
+        },
+        "geburtsdatum": {
+          "type": "string",
+          "format": "date"
+        },
+        "geschlecht": {
+          "type": "string"
+        },
+        "staatsangehoerigkeit": {
+          "type": "string"
+        },
+        "adresse": {
+          "$ref": "#/$defs/Adresse"
+        },
+        "telefon": {
+          "type": "string"
+        },
+        "email": {
+          "type": "string",
+          "format": "email"
+        },
+        "familienstand": {
+          "type": "string",
+          "description": "z.B. ledig, verheiratet, geschieden, verwitwet"
+        },
+        "verwandtschaftsverhaeltnis": {
+          "type": "string",
+          "description": "Beziehung zum/ zur Antragstellenden in diesem Zeitraum"
+        },
+        "transferleistungJN": {
+          "type": "string",
+          "maxLength": 1,
+          "description": "J/N"
+        },
+        "transferleistungArt": {
+          "type": "string"
+        },
+        "sozialstellung": {
+          "type": "string"
+        },
+        "sozialhilfeArt": {
+          "type": "string"
+        },
+        "aufenthaltstitelEnde": {
+          "type": "string",
+          "format": "date"
+        },
+        "istKind": {
+          "type": "boolean",
+          "description": "true, falls Kind im Sinne der Berechnung"
+        }
+      },
+      "required": [
+        "id",
+        "nachname",
+        "vorname"
+      ]
+    },
+    "Einkommen": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "id": {
+          "type": "string"
+        },
+        "art": {
+          "type": "string",
+          "description": "Einkommensart (z.B. Erwerb, Rente, Unterhalt)"
+        },
+        "artZusatz": {
+          "type": "string"
+        },
+        "frequenz": {
+          "type": "integer",
+          "description": "z.B. 1=monatlich, 12=jährlich o. ä."
+        },
+        "betrag": {
+          "type": "number",
+          "minimum": 0
+        },
+        "werbungskosten": {
+          "type": "number",
+          "minimum": 0
+        },
+        "berechnungsart": {
+          "type": "string",
+          "description": "intern/extern/pauschal etc."
+        },
+        "verglRechnungJN": {
+          "type": "string",
+          "maxLength": 1
+        },
+        "zuschlag": {
+          "type": "number",
+          "minimum": 0
+        },
+        "abschlag": {
+          "type": "number",
+          "minimum": 0
+        }
+      },
+      "required": [
+        "id",
+        "art",
+        "betrag"
+      ]
+    },
+    "Freibetrag": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "id": {
+          "type": "string"
+        },
+        "art": {
+          "type": "string",
+          "description": "z.B. Erwerbstätigenfreibetrag, Alleinerziehendenfreibetrag"
+        },
+        "frequenz": {
+          "type": "integer"
+        },
+        "betrag": {
+          "type": "number",
+          "minimum": 0
+        },
+        "fristDatum": {
+          "type": "string",
+          "format": "date"
+        },
+        "verglRechnungJN": {
+          "type": "string",
+          "maxLength": 1
+        }
+      },
+      "required": [
+        "id",
+        "art",
+        "betrag"
+      ]
+    },
+    "Kinderbetreuung": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "id": {
+          "type": "string"
+        },
+        "kindRef": {
+          "type": "string",
+          "description": "PersonBasis.id des Kindes in diesem Zeitraum"
+        },
+        "betrag": {
+          "type": "number",
+          "minimum": 0
+        }
+      },
+      "required": [
+        "id",
+        "kindRef",
+        "betrag"
+      ]
+    },
+    "PersonImZeitraum": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "rolleImHaushalt": {
+          "type": "string",
+          "description": "z.B. Antragsteller:in, Partner:in, Kind"
+        },
+        "person": {
+          "$ref": "#/$defs/PersonBasis"
+        },
+        "einkommen": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/Einkommen"
+          }
+        },
+        "freibetraege": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/Freibetrag"
+          }
+        },
+        "kinderbetreuung": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/Kinderbetreuung"
+          }
+        }
+      },
+      "required": [
+        "person"
+      ]
+    },
+    "Zeitraum": {
+      "type": "object",
+      "additionalProperties": false,
+      "properties": {
+        "id": {
+          "type": "string"
+        },
+        "beginn": {
+          "type": "string",
+          "format": "date"
+        },
+        "ende": {
+          "type": "string",
+          "format": "date"
+        },
+        "grund": {
+          "type": "string"
+        },
+        "personen": {
+          "type": "array",
+          "items": {
+            "$ref": "#/$defs/PersonImZeitraum"
+          }
+        }
+      },
+      "required": [
+        "id",
+        "beginn",
+        "personen"
+      ]
+    }
+  }
+}

+ 32 - 0
src/main/resources/static/styles.css

@@ -0,0 +1,32 @@
+:root{
+  --rot-hell:#FFD6D6; --gelb-hell:#FFF5CC; --gruen-hell:#D6F5D6;
+  --rot:#800000; --gelb:#784801; --gruen:#006633;
+  --weiss:#FFFFFF; --schwarz:#000000; --grau-hell:#F7F9FA; --grau-stark:#D7D8D9;
+}
+*{box-sizing:border-box}
+body{margin:0;padding:16px;background:var(--grau-hell);color:var(--schwarz);font:14px/1.4 system-ui,sans-serif}
+h1,h2,h3{margin:.2rem 0 .6rem}
+.muted{opacity:.8}
+.row{display:flex;gap:.5rem;align-items:center}
+.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
+.grid-2 .full{grid-column:1/-1}
+textarea,input,select{width:100%;padding:.5rem;background:var(--weiss);color:var(--schwarz);border:1px solid var(--grau-stark);border-radius:4px}
+button{padding:.5rem .9rem;border:1px solid var(--grau-stark);background:#fff;cursor:pointer}
+.error-box{background:var(--rot-hell);border-left:4px solid var(--rot);padding:.6rem;margin:.6rem 0}
+
+table{width:100%;border-collapse:collapse;background:var(--weiss);border:1px solid var(--grau-stark);margin:.6rem 0 1rem}
+th,td{border:1px solid var(--grau-stark);padding:.5rem;vertical-align:top}
+th{background:var(--grau-stark);position:sticky;top:0}
+.sym{width:2.5rem;text-align:center;font-weight:700}
+.sym.plus{color:var(--gruen)}
+.sym.minus{color:var(--rot)}
+.sym.warn{color:var(--gelb)}
+.diff-row-added{background:var(--gruen-hell)}
+.diff-row-removed{background:var(--rot-hell)}
+.cell-changed,td:has(.cell-changed){background:var(--gelb-hell)}
+.old{display:block;font-size:.85em;margin-top:.2rem;opacity:.9}
+.header{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
+.legend{margin:.5rem 0 1rem}
+.person-selected{outline:3px solid var(--grau-stark);outline-offset:-3px}
+.table-action{padding:.25rem .5rem;border:1px solid var(--grau-stark);background:#fff;cursor:pointer;font-size:.85rem}
+.table-action:hover{filter:brightness(0.98)}

+ 54 - 0
src/main/resources/templates/test.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="de" xmlns:th="http://www.thymeleaf.org">
+<head><meta charset="UTF-8"/><title>Vergleich – Test</title><link rel="stylesheet" href="/styles.css"/></head>
+<body>
+  <h1>Vergleich – Testseite</h1>
+  <div th:if="${schemaErrors != null}" class="error-box">
+    <strong>Schema-Fehler</strong>
+    <ul><li th:each="e : ${schemaErrors}" th:text="${e}"></li></ul>
+  </div>
+
+  <form method="post" action="/vergleich" class="grid-2">
+    <div><label>Left JSON (Basis/Alt)</label><textarea name="leftJson" th:text="${leftJson}"></textarea></div>
+    <div><label>Right JSON (Neu/Wahrheit)</label><textarea name="rightJson" th:text="${rightJson}"></textarea></div>
+    <div class="full row">
+      <label><input type="checkbox" name="validate" th:checked="${validate ?: true}"> Gegen Schema validieren</label>
+      <label>Schema-Name: <input type="text" name="schemaName" th:value="${schemaName ?: 'haushalt-einkommen'}"></label>
+      <button type="submit">Vergleichen & anzeigen</button>
+    </div>
+  </form>
+
+  <!-- Nach erstem Submit: Vorgang/Zeitraum-Auswahl -->
+  <div class="full" th:if="${leftCandidates != null}">
+    <h2>Baseline-Auswahl (links)</h2>
+    <form method="post" action="/vergleich" class="row">
+      <input type="hidden" name="leftJson" th:value="${leftJson}"/>
+      <input type="hidden" name="rightJson" th:value="${rightJson}"/>
+      <input type="hidden" name="validate" th:value="${validate}"/>
+      <input type="hidden" name="schemaName" th:value="${schemaName}"/>
+
+      <label>Vorgang (links):
+        <select name="leftVorgangId">
+          <option th:each="v : ${leftCandidates}" th:value="${v.id}"
+                  th:text="${v.aktenzeichen != null ? v.aktenzeichen : v.id}"
+                  th:selected="${v.id == leftVorgangId}"></option>
+        </select>
+      </label>
+      <label>Zeitraum (links):
+        <select name="leftZeitraumId">
+          <option th:each="z : ${leftZeitraeumeOfSelected}" th:value="${z.id}"
+                  th:text="${z.beginn} + ' – ' + ${z.ende}"
+                  th:selected="${z.id == leftZeitraumId}"></option>
+        </select>
+      </label>
+      <label>Zeitraum (rechts):
+        <select name="rightZeitraumId">
+          <option th:each="z : ${zeitraeumeRight}" th:value="${z.id}"
+                  th:text="${z.beginn} + ' – ' + ${z.ende}"
+                  th:selected="${z.id == rightZeitraumId}"></option>
+        </select>
+      </label>
+      <button type="submit">Ansicht aktualisieren</button>
+    </form>
+  </div>
+</body></html>

+ 126 - 0
src/main/resources/templates/vergleich.html

@@ -0,0 +1,126 @@
+<!DOCTYPE html>
+<html lang="de" xmlns:th="http://www.thymeleaf.org">
+<head><meta charset="UTF-8"/><title>Vergleich – Haushaltsmitglieder & Einkommen</title><link rel="stylesheet" href="/styles.css"/></head>
+<body>
+  <header class="header">
+    <div>
+      <h1>Vergleich – Haushaltsmitglieder & Einkommen</h1>
+      <div class="muted" th:if="${stammvorgangRight != null}">
+        Aktenzeichen: <span th:text="${stammvorgangRight.aktenzeichen}">—</span>
+      </div>
+    </div>
+    <form method="post" action="/vergleich" class="row">
+      <input type="hidden" name="schemaName" th:value="${schemaName}"/>
+      <input type="hidden" name="validate" th:value="${validate}"/>
+      <input type="hidden" name="leftJson" th:value="${leftJson}"/>
+      <input type="hidden" name="rightJson" th:value="${rightJson}"/>
+      <input type="hidden" name="leftVorgangId" th:value="${leftVorgangId}"/>
+      <input type="hidden" name="leftZeitraumId" th:value="${leftZeitraumId}"/>
+      <label>Zeitraum (rechts):
+        <select name="rightZeitraumId">
+          <option th:each="z : ${zeitraeumeRight}" th:value="${z.id}"
+                  th:selected="${z.id == rightZeitraumId}"
+                  th:text="${z.beginn} + ' – ' + ${z.ende}"></option>
+        </select>
+      </label>
+      <button type="submit">Wechseln</button>
+    </form>
+  </header>
+
+  <section class="legend">
+    <span class="sym plus">+</span> hinzugefügt (grün) &nbsp; 
+    <span class="sym minus">−</span> gelöscht (rot) &nbsp; 
+    <span class="sym warn">!</span> geändert (gelb je Feld)
+  </section>
+
+  <section class="summary" th:if="${summary != null}">
+    <span>Neu: <b th:text="${summary.added}">0</b></span>
+    <span>Gelöscht: <b th:text="${summary.removed}">0</b></span>
+    <span>Geändert: <b th:text="${summary.changed}">0</b></span>
+    <span>Typkonflikte: <b th:text="${summary.typeMismatch}">0</b></span>
+    <span>Gesamt: <b th:text="${summary.total}">0</b></span>
+  </section>
+
+  <!-- Haushaltsmitglieder (rechts Master). Auswahl NUR hier über „Wählen" -->
+  <h2>Haushaltsmitglieder</h2>
+  <table>
+    <thead>
+      <tr>
+        <th>Δ</th><th>Name</th><th>Geburtsdatum</th><th>Familienstand</th>
+        <th>Geschlecht</th><th>Verwandtschaft</th><th>Sozialstellung</th><th>Kind</th><th>Aktion</th>
+      </tr>
+    </thead>
+    <tbody>
+      <tr th:each="r : ${mitgliederRows}"
+          th:class="${r.rowClass} + ((${r.personId} == ${personId}) ? ' person-selected' : '')">
+        <td class="sym" th:classappend="' ' + ${r.symbolClass}" th:text="${r.symbol}"></td>
+        <td th:utext="${r.nameHtml}"></td>
+        <td th:utext="${r.geburtsdatumHtml}"></td>
+        <td th:utext="${r.familienstandHtml}"></td>
+        <td th:utext="${r.geschlechtHtml}"></td>
+        <td th:utext="${r.verwandtschaftHtml}"></td>
+        <td th:utext="${r.sozialstellungHtml}"></td>
+        <td th:utext="${r.istKindHtml}"></td>
+        <td>
+          <form method="post" action="/vergleich">
+            <input type="hidden" name="leftJson" th:value="${leftJson}"/>
+            <input type="hidden" name="rightJson" th:value="${rightJson}"/>
+            <input type="hidden" name="validate" th:value="${validate}"/>
+            <input type="hidden" name="schemaName" th:value="${schemaName}"/>
+            <input type="hidden" name="leftVorgangId" th:value="${leftVorgangId}"/>
+            <input type="hidden" name="leftZeitraumId" th:value="${leftZeitraumId}"/>
+            <input type="hidden" name="rightZeitraumId" th:value="${rightZeitraumId}"/>
+            <input type="hidden" name="personId" th:value="${r.personId}"/>
+            <button class="table-action" type="submit">Wählen</button>
+          </form>
+        </td>
+      </tr>
+    </tbody>
+  </table>
+
+  <h2>Details zur Person</h2>
+  <h3 th:text="${personLabel}">—</h3>
+
+  <h2>Einkommen</h2>
+  <table>
+    <thead><tr><th>Δ</th><th>Art</th><th>Frequenz</th><th>Betrag</th><th>Zuschlag</th><th>Abschlag</th><th>Werbungskosten</th><th>Berechnungsart</th></tr></thead>
+    <tbody>
+      <tr th:each="z : ${einkommenZeilen}" th:class="${z.rowClass}">
+        <td class="sym" th:classappend="' ' + ${z.symbolClass}" th:text="${z.symbol}"></td>
+        <td th:utext="${z.artHtml}"></td>
+        <td th:utext="${z.frequenzHtml}"></td>
+        <td th:utext="${z.betragHtml}"></td>
+        <td th:utext="${z.zuschlagHtml}"></td>
+        <td th:utext="${z.abschlagHtml}"></td>
+        <td th:utext="${z.werbungskostenHtml}"></td>
+        <td th:utext="${z.berechnungsartHtml}"></td>
+      </tr>
+    </tbody>
+  </table>
+
+  <h2>Freibeträge</h2>
+  <table>
+    <thead><tr><th>Δ</th><th>Art</th><th>Frequenz</th><th>Betrag</th><th>Frist</th></tr></thead>
+    <tbody>
+      <tr th:each="z : ${freibetragZeilen}" th:class="${z.rowClass}">
+        <td class="sym" th:classappend="' ' + ${z.symbolClass}" th:text="${z.symbol}"></td>
+        <td th:utext="${z.artHtml}"></td>
+        <td th:utext="${z.frequenzHtml}"></td>
+        <td th:utext="${z.betragHtml}"></td>
+        <td th:utext="${z.fristHtml}"></td>
+      </tr>
+    </tbody>
+  </table>
+
+  <h2>Kinderbetreuungskosten</h2>
+  <table>
+    <thead><tr><th>Δ</th><th>Kind</th><th>Betrag</th></tr></thead>
+    <tbody>
+      <tr th:each="z : ${kitaZeilen}" th:class="${z.rowClass}">
+        <td class="sym" th:classappend="' ' + ${z.symbolClass}" th:text="${z.symbol}"></td>
+        <td th:utext="${z.kindNameHtml}"></td>
+        <td th:utext="${z.betragHtml}"></td>
+      </tr>
+    </tbody>
+  </table>
+</body></html>