diff --git a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java index c68209c..9cfa94f 100644 --- a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java +++ b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java @@ -132,6 +132,11 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { } } + /** + * 有效学习时间的最小阈值(秒),低于此值不计入总学习时间 + */ + private static final double MIN_EFFECTIVE_TIME_SECONDS = 10 * 60; + /** * 结束会话 */ @@ -140,7 +145,12 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { log.warn("不应出现的情况:结束了一个状态为【{}】的学习会话",this.getSessionState()); }else { if (this.getSessionState().equals(StudySessionStateEnum.ONGOING.name())) { - this.pausedStudySession(endTime); + this.pausedStudySession(LocalDateTime.now()); + } + if (this.getEffectiveTime() < MIN_EFFECTIVE_TIME_SECONDS) { + log.info("会话[{}]有效学习时间({}秒)不足10分钟,不计入总学习时间", this.getSessionNum(), this.getEffectiveTime()); + this.setEffectiveTime(0); + this.setEffectivenessRatio(0); } this.setSessionState(StudySessionStateEnum.ENDED.name()); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java index 77a8a4d..43880e6 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java @@ -20,7 +20,7 @@ public interface StudySessionsService extends IService { ArrayList getAllFragments(String sessionNum) throws ErrorParameterException; - void endedStudySession(String sessionNum, String content) throws ErrorParameterException; + String endedStudySession(String sessionNum, String content) throws ErrorParameterException; void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException, ServiceException;