feat: 增加响应字段 任务名称
This commit is contained in:
+7
-5
@@ -41,27 +41,29 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
|
|
||||||
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
|
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
|
||||||
// taskNum是否存在
|
// taskNum是否存在
|
||||||
tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
TaskEntity taskEntity = tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在", taskNum)));
|
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在", taskNum)));
|
||||||
// 任务taskNum下是否存在非"已结束"的学习会话
|
// 任务taskNum下是否存在非"已结束"的学习会话
|
||||||
Optional<StudySessionsEntity> oneOpt = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
Optional<StudySessionsEntity> oneOpt = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||||
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()));
|
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()));
|
||||||
|
StudySessionsEntity studySessionsEntity;
|
||||||
// 有则返回该未完成会话,否则创建新的会话
|
// 有则返回该未完成会话,否则创建新的会话
|
||||||
if (oneOpt.isEmpty()) {
|
if (oneOpt.isEmpty()) {
|
||||||
// 返回一个新的会话
|
// 返回一个新的会话
|
||||||
StudySessionsEntity studySessionsEntity = StudySessionsEntity.initNewSession();
|
studySessionsEntity = StudySessionsEntity.initNewSession();
|
||||||
studySessionsEntity.setTaskNum(taskNum);
|
studySessionsEntity.setTaskNum(taskNum);
|
||||||
studySessionsEntity.setLastStartTime(LocalDateTime.now());
|
studySessionsEntity.setLastStartTime(LocalDateTime.now());
|
||||||
this.save(studySessionsEntity);
|
this.save(studySessionsEntity);
|
||||||
return StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
|
|
||||||
} else {
|
} else {
|
||||||
// 返回已经存在的会话
|
// 返回已经存在的会话
|
||||||
StudySessionsEntity studySessionsEntity = oneOpt.get();
|
studySessionsEntity = oneOpt.get();
|
||||||
studySessionsEntity.continueStudySession();
|
studySessionsEntity.continueStudySession();
|
||||||
this.updateById(studySessionsEntity);
|
this.updateById(studySessionsEntity);
|
||||||
return StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
|
|
||||||
}
|
}
|
||||||
|
StudySessionResponse response = StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
|
||||||
|
response.setTaskName(taskEntity.getTaskName());
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user