[xingyu.guo] feat: 【获取【学习会话】所有的学习残片数据,以列表返回】API
This commit is contained in:
@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学习会话控制层
|
* 学习会话控制层
|
||||||
*/
|
*/
|
||||||
@@ -53,4 +55,13 @@ public class StudySessionController {
|
|||||||
return CommonResult.success();
|
return CommonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取【学习会话】所有的学习残片数据,以列表返回
|
||||||
|
*/
|
||||||
|
@GetMapping("/{sessionNum}/all-fragments")
|
||||||
|
public CommonResult getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
|
||||||
|
ArrayList<String> allFragments = studySessionsServiceImpl.getAllFragments(sessionNum);
|
||||||
|
return CommonResult.success(allFragments);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guo
|
* @author guo
|
||||||
* @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service
|
* @description 针对表【study_sessions(记录每次学习会话的具体数据)】的数据库操作Service
|
||||||
@@ -13,4 +15,6 @@ import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
|||||||
public interface StudySessionsService extends IService<StudySessionsEntity> {
|
public interface StudySessionsService extends IService<StudySessionsEntity> {
|
||||||
|
|
||||||
StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException;
|
StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException;
|
||||||
|
|
||||||
|
ArrayList<String> getAllFragments(String sessionNum) throws ErrorParameterException;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-6
@@ -7,8 +7,10 @@ import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
|||||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||||
import com.guo.learningprogresstracker.mapStruct.FragmentsConvert;
|
import com.guo.learningprogresstracker.mapStruct.FragmentsConvert;
|
||||||
|
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||||
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
||||||
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,19 +19,16 @@ import org.springframework.stereotype.Service;
|
|||||||
* @createDate 2024-06-09 15:28:48
|
* @createDate 2024-06-09 15:28:48
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
||||||
implements StudyReportFragmentsService{
|
implements StudyReportFragmentsService{
|
||||||
|
|
||||||
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
private final StudySessionsMapper studySessionsMapper;
|
||||||
|
|
||||||
public StudyReportFragmentsServiceImpl(StudySessionsServiceImpl studySessionsServiceImpl) {
|
|
||||||
this.studySessionsServiceImpl = studySessionsServiceImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
|
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
|
||||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
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()))) {
|
.eq(StudySessionsEntity::getSessionNum,entity.getSessionNum()))) {
|
||||||
this.save(entity);
|
this.save(entity);
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
+19
@@ -3,19 +3,23 @@ package com.guo.learningprogresstracker.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
||||||
|
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||||
import com.guo.learningprogresstracker.enums.StudySessionStateEnum;
|
import com.guo.learningprogresstracker.enums.StudySessionStateEnum;
|
||||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||||
import com.guo.learningprogresstracker.mapStruct.StudySessionConvert;
|
import com.guo.learningprogresstracker.mapStruct.StudySessionConvert;
|
||||||
|
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||||
import com.guo.learningprogresstracker.service.StudySessionsService;
|
import com.guo.learningprogresstracker.service.StudySessionsService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guo
|
* @author guo
|
||||||
@@ -28,6 +32,8 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
implements StudySessionsService{
|
implements StudySessionsService{
|
||||||
|
|
||||||
private final TasksServiceImpl tasksServiceImpl;
|
private final TasksServiceImpl tasksServiceImpl;
|
||||||
|
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
|
||||||
|
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||||
|
|
||||||
public StudySessionResponce startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
|
public StudySessionResponce startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
|
||||||
// taskNum是否存在
|
// taskNum是否存在
|
||||||
@@ -70,6 +76,19 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话"));
|
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话"));
|
||||||
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<String> 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 + "]不存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user