学年
This commit is contained in:
@@ -62,14 +62,31 @@ public class BaseYearTermService implements IBaseYearTermService {
|
||||
public BaseYearTerm getNowYearTerm() {
|
||||
Date now = new Date();
|
||||
List<BaseYearTerm> yearTermList = getAllYearTerm();
|
||||
// 当前学期开始时间 <= now < 下一学期开始时间:按开始时间倒序后,取第一个已开始(开始时间<=now)的学期
|
||||
// 升学以 upgradeDate 当天 06:00:00 为界:6点之前算上学期(当前 active 学年),6点(含)之后算新学期
|
||||
// 取 upgradeDate@06:00 倒序后第一个 boundary <= now 的学年(即 now 落在该学年 [上学年边界, 本学年边界) 区间内)
|
||||
return yearTermList.stream()
|
||||
.sorted(Comparator.comparing(BaseYearTerm::getYearStartDate).reversed())
|
||||
.filter(s -> s.getYearStartDate().compareTo(now) <= 0)
|
||||
.sorted(Comparator.comparing(
|
||||
(BaseYearTerm s) -> toUpgradeBoundary(s.getUpgradeDate()),
|
||||
Comparator.nullsLast(Comparator.naturalOrder())))
|
||||
.filter(s -> {
|
||||
Date boundary = toUpgradeBoundary(s.getUpgradeDate());
|
||||
return boundary != null && boundary.compareTo(now) <= 0;
|
||||
})
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new DException("获取学年失败,当前时间不在当学年时间范围"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将升学日期转换为当天 06:00:00 的边界时间(用于判定学期切换:6点之前算上学期,6点含之后算新学期)
|
||||
*/
|
||||
private Date toUpgradeBoundary(Date upgradeDate) {
|
||||
if (upgradeDate == null) {
|
||||
return null;
|
||||
}
|
||||
LocalDate day = upgradeDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
return Date.from(day.atTime(6, 0, 0).atZone(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user