feat: 增加响应字段 任务名称
This commit is contained in:
+15
-13
@@ -25,14 +25,14 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
* @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service实现
|
||||
* @createDate 2024-06-09 15:28:48
|
||||
*/
|
||||
* @author guo
|
||||
* @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service实现
|
||||
* @createDate 2024-06-09 15:28:48
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, StudySessionsEntity>
|
||||
implements StudySessionsService {
|
||||
implements StudySessionsService {
|
||||
|
||||
private final TasksServiceImpl tasksServiceImpl;
|
||||
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
|
||||
@@ -41,27 +41,29 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
|
||||
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
|
||||
// taskNum是否存在
|
||||
tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
||||
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在",taskNum)));
|
||||
TaskEntity taskEntity = tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
||||
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在", taskNum)));
|
||||
// 任务taskNum下是否存在非"已结束"的学习会话
|
||||
Optional<StudySessionsEntity> oneOpt = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()));
|
||||
StudySessionsEntity studySessionsEntity;
|
||||
// 有则返回该未完成会话,否则创建新的会话
|
||||
if (oneOpt.isEmpty()) {
|
||||
// 返回一个新的会话
|
||||
StudySessionsEntity studySessionsEntity = StudySessionsEntity.initNewSession();
|
||||
studySessionsEntity = StudySessionsEntity.initNewSession();
|
||||
studySessionsEntity.setTaskNum(taskNum);
|
||||
studySessionsEntity.setLastStartTime(LocalDateTime.now());
|
||||
this.save(studySessionsEntity);
|
||||
return StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
|
||||
}else {
|
||||
} else {
|
||||
// 返回已经存在的会话
|
||||
StudySessionsEntity studySessionsEntity = oneOpt.get();
|
||||
studySessionsEntity = oneOpt.get();
|
||||
studySessionsEntity.continueStudySession();
|
||||
this.updateById(studySessionsEntity);
|
||||
return StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
|
||||
}
|
||||
StudySessionResponse response = StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
|
||||
response.setTaskName(taskEntity.getTaskName());
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,7 +105,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum))
|
||||
.stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new));
|
||||
}else {
|
||||
} else {
|
||||
throw new ErrorParameterException("会话[" + sessionNum + "]不存在");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user