feat: 任务开始页面,相关逻辑补充

This commit is contained in:
2025-07-08 09:20:31 +08:00
parent 72c9a0be65
commit 5df805cca7
7 changed files with 71 additions and 28 deletions
@@ -5,6 +5,7 @@ import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.baomidou.mybatisplus.extension.service.IService;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import java.time.LocalDateTime;
import java.util.ArrayList;
/**
@@ -20,5 +21,7 @@ public interface StudySessionsService extends IService<StudySessionsEntity> {
void endedStudySession(String sessionNum, String content) throws ErrorParameterException;
void pauseStudySession(String sessionNum) throws ErrorParameterException;
void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException;
void continueStudySession(String sessionNum) throws ErrorParameterException;
}
@@ -58,7 +58,8 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
} else {
// 返回已经存在的会话
studySessionsEntity = oneOpt.get();
studySessionsEntity.continueStudySession();
// todo 是否调整任务状态,需要再思考思考
// studySessionsEntity.continueStudySession();
this.updateById(studySessionsEntity);
}
StudySessionResponse response = StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
@@ -67,11 +68,15 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
}
@Override
public void pauseStudySession(String sessionNum) throws ErrorParameterException {
public void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
studySessionsEntity.pausedStudySession();
if (StudySessionStateEnum.PAUSED.name().equals(studySessionsEntity.getSessionState())) {
log.error("会话[" + studySessionsEntity.getSessionNum() + "]重复暂停");
throw new ErrorParameterException("会话[" + sessionNum + "]已经暂停,请勿重复暂停!");
}
studySessionsEntity.pausedStudySession(endTime);
this.updateById(studySessionsEntity);
}
@@ -110,6 +115,21 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
}
}
@Override
public void continueStudySession(String sessionNum) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
if (StudySessionStateEnum.ONGOING.name().equals(studySessionsEntity.getSessionState())) {
log.error("会话[" + studySessionsEntity.getSessionNum() + "]重复开始");
throw new ErrorParameterException("会话[" + sessionNum + "]已经开始,请勿重复开始!");
} else if (StudySessionStateEnum.ENDED.name().equals(studySessionsEntity.getSessionState())) {
log.error("会话[" + studySessionsEntity.getSessionNum() + "]处于结束状态,不可开始该会话!");
throw new ErrorParameterException("会话[" + sessionNum + "]处于结束状态,不可开始该会话!");
}
studySessionsEntity.continueStudySession();
this.updateById(studySessionsEntity);
}
}