From a00fd2278c8a2ed8490dd3303283b2143adead16 Mon Sep 17 00:00:00 2001 From: vran Date: Sun, 22 May 2022 14:40:13 +0800 Subject: [PATCH] fix: diff result table show added but overview show none --- .../domain/document/service/DocumentService.java | 12 ++++++++++-- .../java/com/databasir/core/diff/data/DiffType.java | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java b/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java index da46e13..a1ea136 100644 --- a/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java +++ b/core/src/main/java/com/databasir/core/domain/document/service/DocumentService.java @@ -273,8 +273,16 @@ public class DocumentService { } } result.sort(Comparator.comparing(DatabaseDocumentSimpleResponse.TableData::getName)); - DiffType diffType = result.stream() - .anyMatch(t -> t.getDiffType() == DiffType.MODIFIED) ? DiffType.MODIFIED : DiffType.NONE; + boolean allAdded = result.stream() + .filter(item -> !item.getDiffType().isNone()) + .allMatch(item -> item.getDiffType().isAdded()); + DiffType diffType; + if (allAdded) { + diffType = DiffType.ADDED; + } else { + diffType = result.stream() + .anyMatch(t -> t.getDiffType() != DiffType.NONE) ? DiffType.MODIFIED : DiffType.NONE; + } return documentSimpleResponseConverter.of(document, result, diffType, projectName); } else { tableMetas.sort(Comparator.comparing(DatabaseDocumentSimpleResponse.TableData::getName)); diff --git a/meta/src/main/java/com/databasir/core/diff/data/DiffType.java b/meta/src/main/java/com/databasir/core/diff/data/DiffType.java index 5928ecc..20f2423 100644 --- a/meta/src/main/java/com/databasir/core/diff/data/DiffType.java +++ b/meta/src/main/java/com/databasir/core/diff/data/DiffType.java @@ -6,4 +6,12 @@ public enum DiffType { public static boolean isModified(DiffType type) { return type != null && type != NONE; } + + public boolean isAdded() { + return this == ADDED; + } + + public boolean isNone() { + return this == NONE; + } } \ No newline at end of file