Explorar el Código

fix(beisen): normalize midnight end times

malk hace 4 semanas
padre
commit
882d830bf7

+ 23 - 3
mjava-akdsbeisen/src/main/java/com/malk/service/beisen/BSDataSyncService.java

@@ -299,7 +299,7 @@ public class BSDataSyncService {
                 formData.put("textField_mmk1vzvn", toStringValue(data.get("oId")));
                 formData.put("employeeField_mmizoplw", staffId);
                 formData.put("dateField_mmk1vzvt", dateToTimestamp(data.get("startDate")));
-                formData.put("dateField_mmk1vzvu", dateToTimestamp(data.get("stopDate")));
+                formData.put("dateField_mmk1vzvu", dateToEndTimestamp(data.get("stopDate")));
                 formData.put("numberField_mmk1vzvv", toStringValue(data.get("overTimeDuration")));
 
                 break;
@@ -308,7 +308,7 @@ public class BSDataSyncService {
 
                 formData.put("employeeField_mmizoplw", staffId);
                 formData.put("dateField_mmk1vzvt", dateToTimestamp(data.get("startDateTime")));
-                formData.put("dateField_mmk1vzvu", dateToTimestamp(data.get("stopDateTime")));
+                formData.put("dateField_mmk1vzvu", dateToEndTimestamp(data.get("stopDateTime")));
                 formData.put("numberField_mmk1vzvv", toStringValue(data.get("businessDuration")));
                 formData.put("numberField_mmlsurjx", toStringValue(data.get("dayValOfDuration")));
                 break;
@@ -318,7 +318,7 @@ public class BSDataSyncService {
                 formData.put("textField_mmk1vzvo", toStringValue(data.get("vacationType")));
 
                 formData.put("dateField_mmk1vzvt", dateToTimestamp(data.get("vacationStartDateTime")));
-                formData.put("dateField_mmk1vzvu", dateToTimestamp(data.get("vacationStopDateTime")));
+                formData.put("dateField_mmk1vzvu", dateToEndTimestamp(data.get("vacationStopDateTime")));
                 formData.put("numberField_mmk1vzvv", toStringValue(data.get("dayValueOfDuration")));
 
                 break;
@@ -368,6 +368,26 @@ public class BSDataSyncService {
         }
     }
 
+    /**
+     * // prd 北森结束时间为当天 00:00:00 时按当天结束处理,避免日期边界歧义。
+     */
+    Long dateToEndTimestamp(Object dateObj) {
+        Long timestamp = dateToTimestamp(dateObj);
+        if (timestamp == null) {
+            return null;
+        }
+        ZonedDateTime dateTime = Instant.ofEpochMilli(timestamp).atZone(ZoneId.systemDefault());
+        if (dateTime.toLocalTime().equals(java.time.LocalTime.MIDNIGHT)) {
+            return dateTime.withHour(23)
+                    .withMinute(59)
+                    .withSecond(59)
+                    .withNano(0)
+                    .toInstant()
+                    .toEpochMilli();
+        }
+        return timestamp;
+    }
+
     private String SXW(long  timestamp) {
      String  SXW="";
         Instant instant = Instant.ofEpochMilli(timestamp);

+ 48 - 0
mjava-akdsbeisen/src/test/java/com/malk/service/beisen/BSDataSyncServiceTest.java

@@ -0,0 +1,48 @@
+package com.malk.service.beisen;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class BSDataSyncServiceTest {
+
+    private final BSDataSyncService service = new BSDataSyncService();
+
+    @Test
+    void shouldConvertMidnightEndTimeToEndOfSameDay() {
+        long expected = LocalDateTime.of(2026, 8, 24, 23, 59, 59)
+                .atZone(ZoneId.systemDefault())
+                .toInstant()
+                .toEpochMilli();
+
+        assertEquals(expected, service.dateToEndTimestamp("2026-08-24 00:00:00"));
+        assertEquals(expected, service.dateToEndTimestamp("2026-08-24"));
+    }
+
+    @Test
+    void shouldConvertMidnightTimestampToEndOfSameDay() {
+        long midnight = LocalDateTime.of(2026, 8, 24, 0, 0)
+                .atZone(ZoneId.systemDefault())
+                .toInstant()
+                .toEpochMilli();
+        long expected = LocalDateTime.of(2026, 8, 24, 23, 59, 59)
+                .atZone(ZoneId.systemDefault())
+                .toInstant()
+                .toEpochMilli();
+
+        assertEquals(expected, service.dateToEndTimestamp(midnight));
+    }
+
+    @Test
+    void shouldKeepNonMidnightEndTimeUnchanged() {
+        long expected = LocalDateTime.of(2026, 8, 24, 18, 30)
+                .atZone(ZoneId.systemDefault())
+                .toInstant()
+                .toEpochMilli();
+
+        assertEquals(expected, service.dateToEndTimestamp("2026-08-24 18:30:00"));
+    }
+}