This commit is contained in:
2026-08-25 12:35:54 +08:00
parent 284bc94357
commit 544038fd35
@@ -62,15 +62,14 @@ public class BaseYearTermService implements IBaseYearTermService {
public BaseYearTerm getNowYearTerm() { public BaseYearTerm getNowYearTerm() {
Date now = new Date(); Date now = new Date();
List<BaseYearTerm> yearTermList = getAllYearTerm(); List<BaseYearTerm> yearTermList = getAllYearTerm();
// 升学以 upgradeDate 当天 06:00:00 为界:6点之前算上学期(当前 active 学年),6点(含)之后算新学期 // 上学期升学日期@06:00 <= now < 本学期升学日期@06:00:取 upgradeDate@06:00 升序后第一个严格大于 now 的学年
// 取 upgradeDate@06:00 倒序后第一个 boundary <= now 的学年(即 now 落在该学年 [上学年边界, 本学年边界) 区间内)
return yearTermList.stream() return yearTermList.stream()
.sorted(Comparator.comparing( .sorted(Comparator.comparing(
(BaseYearTerm s) -> toUpgradeBoundary(s.getUpgradeDate()), (BaseYearTerm s) -> toUpgradeBoundary(s.getUpgradeDate()),
Comparator.nullsLast(Comparator.naturalOrder()))) Comparator.nullsLast(Comparator.naturalOrder())))
.filter(s -> { .filter(s -> {
Date boundary = toUpgradeBoundary(s.getUpgradeDate()); Date boundary = toUpgradeBoundary(s.getUpgradeDate());
return boundary != null && boundary.compareTo(now) <= 0; return boundary != null && boundary.compareTo(now) > 0;
}) })
.findFirst() .findFirst()
.orElseThrow(() -> new DException("获取学年失败,当前时间不在当学年时间范围")); .orElseThrow(() -> new DException("获取学年失败,当前时间不在当学年时间范围"));