package com.guo.learningprogresstracker.common; import lombok.Getter; /** * 学习会话的时间口径(会话-04 起改为可配置的值对象)。 * *

番茄钟长度、遗忘判定阈值、硬兜底阈值与有效时间下限集中在此处,避免阈值散落在实体与服务的各个角落。 * 生产路径由 Spring 从 {@code lpt.study-time} 配置构建并注入;{@link #DEFAULT} 只保留设计口径的默认值, * 供实体自身的默认重载与单测使用,不要在服务里直接用它。

*/ @Getter public class StudyTimePolicy { /** 与 lpt-docs 设计口径一致的默认值 */ public static final StudyTimePolicy DEFAULT = new StudyTimePolicy(25, 50, 120, 600); /** * 番茄钟长度(分钟)。 */ private final int workDurationMinutes; /** * 遗忘判定阈值(分钟):通常为 2 × 番茄钟。 */ private final int forgetThresholdMinutes; /** * 硬兜底阈值(分钟):进行中的会话超过该时长未收敛,服务端强制暂停。 */ private final int forcePauseMinutes; /** * 有效学习时间下限(秒)。 */ private final long minEffectiveTimeSeconds; public StudyTimePolicy(int workDurationMinutes, int forgetThresholdMinutes, int forcePauseMinutes, long minEffectiveTimeSeconds) { if (workDurationMinutes <= 0) { throw new IllegalArgumentException("番茄钟长度必须大于 0 分钟"); } if (forgetThresholdMinutes < workDurationMinutes) { throw new IllegalArgumentException("遗忘判定阈值不能小于番茄钟长度"); } if (forcePauseMinutes < forgetThresholdMinutes) { throw new IllegalArgumentException("硬兜底阈值不能小于遗忘判定阈值"); } if (minEffectiveTimeSeconds < 0) { throw new IllegalArgumentException("有效学习时间下限不能为负数"); } this.workDurationMinutes = workDurationMinutes; this.forgetThresholdMinutes = forgetThresholdMinutes; this.forcePauseMinutes = forcePauseMinutes; this.minEffectiveTimeSeconds = minEffectiveTimeSeconds; } /** * 番茄钟长度(毫秒)。 */ public long workDurationMillis() { return workDurationMinutes * 60_000L; } }