feat: 增加响应字段 任务名称

This commit is contained in:
2025-07-06 12:16:42 +08:00
parent 5f9e01cf14
commit 939e15ee56
@@ -25,10 +25,10 @@ import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* @author guo * @author guo
* @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service实现 * @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service实现
* @createDate 2024-06-09 15:28:48 * @createDate 2024-06-09 15:28:48
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, StudySessionsEntity> public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, StudySessionsEntity>
@@ -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
@@ -103,7 +105,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class) return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum)) .eq(StudyReportFragmentsEntity::getSessionNum, sessionNum))
.stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new)); .stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new));
}else { } else {
throw new ErrorParameterException("会话[" + sessionNum + "]不存在"); throw new ErrorParameterException("会话[" + sessionNum + "]不存在");
} }
} }