From 54af814b5e9e8509458d3e2b5b36730315c4fe68 Mon Sep 17 00:00:00 2001 From: guo <1716967236@qq.com> Date: Sun, 22 Sep 2024 11:00:39 +0800 Subject: [PATCH] =?UTF-8?q?[xingyu.guo]=20feat:=20=E3=80=90=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E3=80=90=E5=AD=A6=E4=B9=A0=E4=BC=9A=E8=AF=9D=E3=80=91?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=9A=84=E5=AD=A6=E4=B9=A0=E6=AE=8B=E7=89=87?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E4=BB=A5=E5=88=97=E8=A1=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E3=80=91API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StudySessionController.java | 11 +++++++++++ .../service/StudySessionsService.java | 4 ++++ .../impl/StudyReportFragmentsServiceImpl.java | 11 +++++------ .../impl/StudySessionsServiceImpl.java | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) 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 + "]不存在"); + } + } }