Browse Source

代码修复

G 5 days ago
parent
commit
c7bdb1e432

+ 28 - 14
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/handle/TimeRangeHandler.java

@@ -1,6 +1,9 @@
 package cn.tr.module.phototherapy.common.handle;
 
+import cn.tr.module.phototherapy.common.utils.QueryParamUtil;
+
 import java.time.LocalDate;
+import java.util.Calendar;
 import java.util.Date;
 
 /**
@@ -19,30 +22,41 @@ public class TimeRangeHandler {
     public static Date[] handleTimeRange(Date startDate, Date endDate, Integer timeRangeType) {
         if (timeRangeType != null && timeRangeType > 0) {
             Date now = new Date();
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(now);
+
+            // 复用你已有的工具类,统一时间边界
+            Date endOfDay = QueryParamUtil.convertToEndOfDayFromDate(now);
+
             switch (timeRangeType) {
-                case 1: // 今日数据
-                    startDate = now;
-                    endDate = now;
+                case 1: // 今日数据(00:00-23:59)
+                    startDate = QueryParamUtil.convertToStartOfDayFromDate(now);
+                    endDate = endOfDay;
                     break;
                 case 2: // 最近一周
-                    startDate = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
-                    endDate = now;
+                    cal.add(Calendar.DAY_OF_MONTH, -7);
+                    startDate = QueryParamUtil.convertToStartOfDayFromDate(cal.getTime());
+                    endDate = endOfDay;
                     break;
                 case 3: // 最近两周
-                    startDate = new Date(now.getTime() - 14 * 24 * 60 * 60 * 1000);
-                    endDate = now;
+                    cal.add(Calendar.DAY_OF_MONTH, -14);
+                    startDate = QueryParamUtil.convertToStartOfDayFromDate(cal.getTime());
+                    endDate = endOfDay;
                     break;
                 case 4: // 最近三周
-                    startDate = new Date(now.getTime() - 21 * 24 * 60 * 60 * 1000);
-                    endDate = now;
+                    cal.add(Calendar.DAY_OF_MONTH, -21);
+                    startDate = QueryParamUtil.convertToStartOfDayFromDate(cal.getTime());
+                    endDate = endOfDay;
                     break;
                 case 5: // 最近一月
-                    startDate = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
-                    endDate = now;
+                    cal.add(Calendar.DAY_OF_MONTH, -30);
+                    startDate = QueryParamUtil.convertToStartOfDayFromDate(cal.getTime());
+                    endDate = endOfDay;
                     break;
-                case 6: // 最近半年
-                    startDate = new Date(now.getTime() - 180 * 24 * 60 * 60 * 1000);
-                    endDate = now;
+                case 6: // 最近半年(彻底修复溢出)
+                    cal.add(Calendar.DAY_OF_MONTH, -180);
+                    startDate = QueryParamUtil.convertToStartOfDayFromDate(cal.getTime());
+                    endDate = endOfDay;
                     break;
                 default:
                     // 未知类型,保留原始值

+ 1 - 4
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/impl/BusDeviceHistoryServiceImpl.java

@@ -119,11 +119,8 @@ public class BusDeviceHistoryServiceImpl extends ServiceImpl<BusDeviceHistoryRep
         endDate = dateRange[1];
 
         // 执行多表联查
-        Date startDateTime = QueryParamUtil.convertToStartOfDayFromDate(startDate);
-        Date endDateTime = QueryParamUtil.convertToEndOfDayFromDate(endDate);
-
         // 从Repository获取原始数据
-        List<DeviceRunningLogDTO> results = busDeviceHistoryRepository.selectDeviceRunningLog(patientUniqueId, startDateTime, endDateTime);
+        List<DeviceRunningLogDTO> results = busDeviceHistoryRepository.selectDeviceRunningLog(patientUniqueId, startDate, endDate);
 
         // 转换为VO并按状态聚合
         return results;

+ 1 - 4
tr-modules/tr-modules-phototherapy/src/main/java/cn/tr/module/phototherapy/common/service/impl/BusTherapyRecordServiceImpl.java

@@ -128,10 +128,7 @@ public class BusTherapyRecordServiceImpl extends ServiceImpl<BusTherapyRecordRep
         endDate = dateRange[1];
 
         // 执行多表联查
-        Date startDateTime = QueryParamUtil.convertToStartOfDayFromDate(startDate);
-        Date endDateTime = QueryParamUtil.convertToEndOfDayFromDate(endDate);
-
-        List<TherapyRecordDetailVO> results = therapyRecordRepository.selectTherapyRecordWithPlan(patientUniqueId, startDateTime, endDateTime);
+        List<TherapyRecordDetailVO> results = therapyRecordRepository.selectTherapyRecordWithPlan(patientUniqueId, startDate, endDate);
 
         // 使用 Mapper 转换为 DTO
         return BusTherapyRecordMapper.INSTANCE.toTherapyRecordDetailDTOList(results);