Browse Source

Merge remote-tracking branch 'origin/dev' into dev

18339543638 6 months ago
parent
commit
00f8211fee

+ 33 - 0
nb-service/app-doctor/src/main/java/com/nb/app/doctor/service/PatientClientService.java

@@ -107,13 +107,43 @@ public class PatientClientService {
     }
 
     private ModificationComparison buildComparison(String fieldName, Object oldVal, Object newVal) {
+        int comparisonResult = calculateComparisonResult(oldVal, newVal);
         return ModificationComparison.builder()
                 .fieldName(fieldName)
                 .oldValue(formatValue(oldVal))
                 .newValue(formatValue(newVal))
+                .result(comparisonResult)
                 .build();
     }
 
+    private int calculateComparisonResult(Object oldVal, Object newVal) {
+        if (oldVal == null && newVal == null) return 0;
+        if (oldVal == null) return 1;  // 新增记录视为新值更大
+        if (newVal == null) return -1; // 删除记录视为旧值更大
+
+        // 处理 BigDecimal 类型
+        if (oldVal instanceof BigDecimal && newVal instanceof BigDecimal) {
+            return ((BigDecimal) newVal).compareTo((BigDecimal) oldVal);
+        }
+
+        // 处理数值类型(Integer/Long/Double等)
+        if (oldVal instanceof Number && newVal instanceof Number) {
+            double oldNum = ((Number) oldVal).doubleValue();
+            double newNum = ((Number) newVal).doubleValue();
+            return Double.compare(newNum, oldNum);
+        }
+
+        // 默认比较(按字符串或对象比较)
+        try {
+            Comparable oldComp = (Comparable) oldVal;
+            Comparable newComp = (Comparable) newVal;
+            return newComp.compareTo(oldComp);
+        } catch (ClassCastException e) {
+            // 无法比较时视为相等
+            return 0;
+        }
+    }
+
     // 添加变化项
     private void addIfChanged(
             List<ModificationComparison> list,
@@ -123,6 +153,9 @@ public class PatientClientService {
     ) {
         if (!isEqual(oldVal, newVal)) {
             list.add(buildComparison(fieldName, oldVal, newVal));
+        } else {
+            // 值相等时也记录,但 result=0
+            list.add(buildComparison(fieldName, oldVal, newVal));
         }
     }