diff --git a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java index 009c2de..21c93d7 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java @@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; + /** * 学习会话控制层 */ @@ -53,4 +55,13 @@ public class StudySessionController { return CommonResult.success(); } + /** + * 获取【学习会话】所有的学习残片数据,以列表返回 + */ + @GetMapping("/{sessionNum}/all-fragments") + public CommonResult getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException { + ArrayList allFragments = studySessionsServiceImpl.getAllFragments(sessionNum); + return CommonResult.success(allFragments); + + } } diff --git a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java index 8dbcaf3..0b5e241 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java @@ -5,6 +5,8 @@ import com.guo.learningprogresstracker.entity.StudySessionsEntity; import com.baomidou.mybatisplus.extension.service.IService; import com.guo.learningprogresstracker.exception.ErrorParameterException; +import java.util.ArrayList; + /** * @author guo * @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service @@ -13,4 +15,6 @@ import com.guo.learningprogresstracker.exception.ErrorParameterException; public interface StudySessionsService extends IService { StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException; + + ArrayList getAllFragments(String sessionNum) throws ErrorParameterException; } diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java index 5bc0c9e..04fc023 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java @@ -7,8 +7,10 @@ import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity; import com.guo.learningprogresstracker.entity.StudySessionsEntity; import com.guo.learningprogresstracker.exception.NotFindEntitiesException; import com.guo.learningprogresstracker.mapStruct.FragmentsConvert; +import com.guo.learningprogresstracker.mapper.StudySessionsMapper; import com.guo.learningprogresstracker.service.StudyReportFragmentsService; import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; /** @@ -17,19 +19,16 @@ import org.springframework.stereotype.Service; * @createDate 2024-06-09 15:28:48 */ @Service +@RequiredArgsConstructor public class StudyReportFragmentsServiceImpl extends ServiceImpl implements StudyReportFragmentsService{ - private final StudySessionsServiceImpl studySessionsServiceImpl; - - public StudyReportFragmentsServiceImpl(StudySessionsServiceImpl studySessionsServiceImpl) { - this.studySessionsServiceImpl = studySessionsServiceImpl; - } + private final StudySessionsMapper studySessionsMapper; @Override public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException { StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request); - if (studySessionsServiceImpl.exists(Wrappers.lambdaQuery(StudySessionsEntity.class) + if (studySessionsMapper.exists(Wrappers.lambdaQuery(StudySessionsEntity.class) .eq(StudySessionsEntity::getSessionNum,entity.getSessionNum()))) { this.save(entity); }else { diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java index 9273d4f..2befe4d 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java @@ -3,19 +3,23 @@ package com.guo.learningprogresstracker.service.impl; 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.StudySessionsEntity; import com.guo.learningprogresstracker.entity.TaskEntity; import com.guo.learningprogresstracker.enums.StudySessionStateEnum; 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.StudySessionsMapper; import com.guo.learningprogresstracker.service.StudySessionsService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Optional; +import java.util.stream.Collectors; /** * @author guo @@ -28,6 +32,8 @@ public class StudySessionsServiceImpl extends ServiceImpl new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话")); return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity); } + + @Override + public ArrayList getAllFragments(String sessionNum) throws ErrorParameterException { + if (this.exists(Wrappers.lambdaQuery(StudySessionsEntity.class) + .eq(StudySessionsEntity::getSessionNum, sessionNum))) { + // todo guo 后续可在此补充更高级的整理方式 + return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class) + .eq(StudyReportFragmentsEntity::getSessionNum, sessionNum)) + .stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new)); + }else { + throw new ErrorParameterException("会话[" + sessionNum + "]不存在"); + } + } }