[xingyu.guo] feat: 【结束一个【学习会话】】API

This commit is contained in:
guo
2024-09-22 15:52:08 +08:00
parent 54af814b5e
commit cecfa7a800
6 changed files with 71 additions and 8 deletions
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
import com.guo.learningprogresstracker.enums.StudySessionStateEnum;
@@ -11,6 +12,7 @@ import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.mapStruct.StudySessionConvert;
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
import com.guo.learningprogresstracker.mapper.StudyReportsMapper;
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
import com.guo.learningprogresstracker.service.StudySessionsService;
import lombok.RequiredArgsConstructor;
@@ -29,11 +31,12 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, StudySessionsEntity>
implements StudySessionsService{
implements StudySessionsService {
private final TasksServiceImpl tasksServiceImpl;
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
private final StudyReportsMapper studyReportsMapper;
public StudySessionResponce startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
// taskNum是否存在
@@ -60,6 +63,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
}
}
@Override
public void pauseStudySession(String sessionNum) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
@@ -68,6 +72,21 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
this.updateById(studySessionsEntity);
}
@Override
public void endedStudySession(String sessionNum, String content) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
studySessionsEntity.endedStudySession();
this.updateById(studySessionsEntity);
// 创建学习报告
StudyReportsEntity studyReportsEntity = new StudyReportsEntity();
studyReportsEntity.setSessionNum(sessionNum);
studyReportsEntity.setContent(content);
studyReportsMapper.insert(studyReportsEntity);
}
@Override
public StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
@@ -89,6 +108,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
throw new ErrorParameterException("会话[" + sessionNum + "]不存在");
}
}
}