wangxx 1 день назад
Родитель
Сommit
4fc8583f19

+ 38 - 0
airport-ledger/src/main/java/com/sundot/airport/ledger/service/impl/EmployeePortraitServiceImpl.java

@@ -25,6 +25,9 @@ import org.springframework.stereotype.Service;
25
 
25
 
26
 import java.math.BigDecimal;
26
 import java.math.BigDecimal;
27
 import java.math.RoundingMode;
27
 import java.math.RoundingMode;
28
+import java.time.LocalDate;
29
+import java.time.LocalDateTime;
30
+import java.time.format.DateTimeFormatter;
28
 import java.util.*;
31
 import java.util.*;
29
 import java.util.stream.Collectors;
32
 import java.util.stream.Collectors;
30
 
33
 
@@ -89,6 +92,9 @@ public class EmployeePortraitServiceImpl implements IEmployeePortraitService {
89
         EmployeePortraitVO vo = new EmployeePortraitVO();
92
         EmployeePortraitVO vo = new EmployeePortraitVO();
90
         vo.setPersonName(personName);
93
         vo.setPersonName(personName);
91
 
94
 
95
+        //前提:设置时间开始时间00:00:00 结束时间23:59:59
96
+        beginTime = normalizeBeginTime(beginTime);
97
+        endTime = normalizeEndTime(endTime);
92
         // 1. 用户基本信息
98
         // 1. 用户基本信息
93
         fillUserInfo(vo, personName);
99
         fillUserInfo(vo, personName);
94
 
100
 
@@ -539,4 +545,36 @@ public class EmployeePortraitServiceImpl implements IEmployeePortraitService {
539
         });
545
         });
540
         return result;
546
         return result;
541
     }
547
     }
548
+
549
+    /**
550
+     * 规范化开始时间: 格式化为 yyyy-MM-dd 00:00:00
551
+     */
552
+    private String normalizeBeginTime(String timeStr) {
553
+        if (timeStr == null || timeStr.isEmpty()) {
554
+            return timeStr;
555
+        }
556
+        try {
557
+            LocalDateTime dateTime = LocalDateTime.parse(timeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
558
+            return dateTime.toLocalDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
559
+        } catch (Exception e) {
560
+            LocalDate date = LocalDate.parse(timeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
561
+            return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00";
562
+        }
563
+    }
564
+
565
+    /**
566
+     * 规范化结束时间: 格式化为 yyyy-MM-dd 23:59:59
567
+     */
568
+    private String normalizeEndTime(String timeStr) {
569
+        if (timeStr == null || timeStr.isEmpty()) {
570
+            return timeStr;
571
+        }
572
+        try {
573
+            LocalDateTime dateTime = LocalDateTime.parse(timeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
574
+            return dateTime.toLocalDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 23:59:59";
575
+        } catch (Exception e) {
576
+            LocalDate date = LocalDate.parse(timeStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
577
+            return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 23:59:59";
578
+        }
579
+    }
542
 }
580
 }