|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.Date;
|
|
|
@@ -234,22 +235,24 @@ public class FsSopDoctorTaskServiceImpl extends ServiceImpl<FsSopDoctorTaskMappe
|
|
|
* 计算未来日期
|
|
|
* @param baseDate 基准日期
|
|
|
* @param daysToAdd 需要增加的天数
|
|
|
- * @return 计算后的未来日期
|
|
|
+ * @return 计算后的未来日期(时间为 00:00:00)
|
|
|
*/
|
|
|
private Date calculateFutureDate(Date baseDate, Integer daysToAdd) {
|
|
|
if (baseDate == null || daysToAdd == null || daysToAdd <= 0) {
|
|
|
- // 根据业务需求决定如何处理无效输入,这里抛异常
|
|
|
- throw new IllegalArgumentException("基准日期和增加天数都不能为空且天数需大于0");
|
|
|
+ throw new CustomException("基准日期和增加天数都不能为空且天数需大于0");
|
|
|
}
|
|
|
- // 1. 将 Date 转换为 LocalDateTime (注意时区,这里假设使用系统默认时区)
|
|
|
- LocalDateTime localDateTimeNow = baseDate.toInstant()
|
|
|
- .atZone(ZoneId.systemDefault())
|
|
|
- .toLocalDateTime();
|
|
|
+ // 1. 将 Date 转换为 Instant,再转换为 LocalDate (忽略时区影响,只取日期部分)
|
|
|
+ LocalDate localDate = baseDate.toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault()) // 使用系统默认时区进行转换
|
|
|
+ .toLocalDate(); // toLocalDate() 自动丢弃时间信息
|
|
|
|
|
|
- // 2. 使用 plusDays 添加天数
|
|
|
- LocalDateTime futureDateTime = localDateTimeNow.plusDays(daysToAdd);
|
|
|
+ // 2. 使用 plusDays 添加天数,得到目标日期
|
|
|
+ LocalDate targetDate = localDate.plusDays(daysToAdd);
|
|
|
|
|
|
- // 3. 将 LocalDateTime 转换回 Date
|
|
|
- return Date.from(futureDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ // 3. 将 LocalDate 转换为当天的开始时刻 (00:00:00) 的 LocalDateTime
|
|
|
+ LocalDateTime startOfDay = targetDate.atStartOfDay(); //生成 YYYY-MM-DDT00:00:00
|
|
|
+
|
|
|
+ // 4. 将 LocalDateTime 转换回 Date
|
|
|
+ return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
}
|
|
|
}
|