diff --git a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java index dcaf722..9174800 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java @@ -67,8 +67,8 @@ public class StudySessionController { @PostMapping("/{sessionNum}/study-sessions/ended") public CommonResult endedStudySession(@PathVariable("sessionNum") String sessionNum, @Valid @RequestBody EndedStudySessionRequest request) throws ErrorParameterException { - studySessionsServiceImpl.endedStudySession(sessionNum, request.getContent()); - return CommonResult.success(); + String message = studySessionsServiceImpl.endedStudySession(sessionNum, request.getContent()); + return message != null ? CommonResult.success(message) : CommonResult.success(); } /** diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java index 2a7065a..d8d55a1 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java @@ -93,16 +93,21 @@ public class StudySessionsServiceImpl extends ServiceImpl new ErrorParameterException("会话[" + sessionNum + "]不存在")); + boolean wasOngoing = StudySessionStateEnum.ONGOING.name().equals(studySessionsEntity.getSessionState()); studySessionsEntity.endedStudySession(); this.updateById(studySessionsEntity); StudyReportsEntity studyReportsEntity = new StudyReportsEntity(); studyReportsEntity.setSessionNum(sessionNum); studyReportsEntity.setContent(content); studyReportsMapper.insert(studyReportsEntity); + if (wasOngoing && studySessionsEntity.getEffectiveTime() == 0) { + return "本次有效学习时间不足10分钟,不计入总学习时间"; + } + return null; } @Override