diff --git a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java index 21c93d7..55d5ac3 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java @@ -1,18 +1,21 @@ package com.guo.learningprogresstracker.controller; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.guo.learningprogresstracker.dto.request.EndedStudySessionRequest; import com.guo.learningprogresstracker.dto.response.StudySessionResponce; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.entity.StudySessionsEntity; import com.guo.learningprogresstracker.exception.ErrorParameterException; import com.guo.learningprogresstracker.mapStruct.StudySessionConvert; import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -49,12 +52,21 @@ public class StudySessionController { /** * 暂停一个【学习会话】 */ - @PostMapping("/{sessionNum}/studay-sessions/pause") + @PostMapping("/{sessionNum}/study-sessions/pause") public CommonResult pauseStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException { studySessionsServiceImpl.pauseStudySession(sessionNum); return CommonResult.success(); } + /** + * 结束一个【学习会话】 + */ + @PostMapping("/{sessionNum}/study-sessions/ended") + public CommonResult endedStudySession(@PathVariable("sessionNum") String sessionNum, + @Valid @RequestBody EndedStudySessionRequest request) throws ErrorParameterException { + studySessionsServiceImpl.endedStudySession(sessionNum,request.getContent()); + return CommonResult.success(); + } /** * 获取【学习会话】所有的学习残片数据,以列表返回 */ diff --git a/src/main/java/com/guo/learningprogresstracker/dto/request/EndedStudySessionRequest.java b/src/main/java/com/guo/learningprogresstracker/dto/request/EndedStudySessionRequest.java new file mode 100644 index 0000000..dcff657 --- /dev/null +++ b/src/main/java/com/guo/learningprogresstracker/dto/request/EndedStudySessionRequest.java @@ -0,0 +1,13 @@ +package com.guo.learningprogresstracker.dto.request; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * @author guo + */ +@Data +public class EndedStudySessionRequest { + @NotBlank(message = "啊?搞无字天书是吧?报告内容不可为空") + private String content; +} diff --git a/src/main/java/com/guo/learningprogresstracker/entity/StudyReportsEntity.java b/src/main/java/com/guo/learningprogresstracker/entity/StudyReportsEntity.java index f104de3..77add7a 100644 --- a/src/main/java/com/guo/learningprogresstracker/entity/StudyReportsEntity.java +++ b/src/main/java/com/guo/learningprogresstracker/entity/StudyReportsEntity.java @@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; -import java.time.LocalDateTime; + import lombok.Data; /** @@ -18,14 +18,14 @@ public class StudyReportsEntity extends BaseEntity implements Serializable { /** * */ - @TableId(value = "report_id", type = IdType.AUTO) - private Integer reportId; + @TableId(value = "id", type = IdType.AUTO) + private Integer id; /** - * + * 会话编码 */ - @TableField(value = "session_id") - private Integer sessionId; + @TableField(value = "session_num") + private String sessionNum; /** * 完整的学习报告内容 diff --git a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java index 1d05a9f..20ddcda 100644 --- a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java +++ b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java @@ -117,4 +117,18 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { this.setSessionState(StudySessionStateEnum.PAUSED.name()); } } + + /** + * 结束会话 + */ + public void endedStudySession() { + if (this.getSessionState().equals(StudySessionStateEnum.ENDED.name())){ + log.warn("不应出现的情况:结束了一个状态为【{}】的学习会话",this.getSessionState()); + }else { + if (this.getSessionState().equals(StudySessionStateEnum.ONGOING.name())) { + this.pausedStudySession(); + } + this.setSessionState(StudySessionStateEnum.ENDED.name()); + } + } } \ No newline at end of file diff --git a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java index 0b5e241..ddbb3a1 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java @@ -17,4 +17,8 @@ public interface StudySessionsService extends IService { StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException; ArrayList getAllFragments(String sessionNum) throws ErrorParameterException; + + void endedStudySession(String sessionNum, String content) throws ErrorParameterException; + + void pauseStudySession(String sessionNum) throws ErrorParameterException; } 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 2befe4d..a6fd742 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java @@ -4,6 +4,7 @@ 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.StudyReportsEntity; import com.guo.learningprogresstracker.entity.StudySessionsEntity; import com.guo.learningprogresstracker.entity.TaskEntity; import com.guo.learningprogresstracker.enums.StudySessionStateEnum; @@ -11,6 +12,7 @@ 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.StudyReportsMapper; import com.guo.learningprogresstracker.mapper.StudySessionsMapper; import com.guo.learningprogresstracker.service.StudySessionsService; import lombok.RequiredArgsConstructor; @@ -29,11 +31,12 @@ import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class StudySessionsServiceImpl extends ServiceImpl - implements StudySessionsService{ + implements StudySessionsService { private final TasksServiceImpl tasksServiceImpl; private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl; private final StudyReportFragmentsMapper studyReportFragmentsMapper; + private final StudyReportsMapper studyReportsMapper; public StudySessionResponce startOrContinueStudySession(String taskNum) throws NotFindEntitiesException { // taskNum是否存在 @@ -60,6 +63,7 @@ public class StudySessionsServiceImpl extends ServiceImpl new ErrorParameterException("会话[" + sessionNum + "]不存在")); + studySessionsEntity.endedStudySession(); + this.updateById(studySessionsEntity); + // 创建学习报告 + StudyReportsEntity studyReportsEntity = new StudyReportsEntity(); + studyReportsEntity.setSessionNum(sessionNum); + studyReportsEntity.setContent(content); + studyReportsMapper.insert(studyReportsEntity); + } + @Override public StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException { StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class) @@ -89,6 +108,7 @@ public class StudySessionsServiceImpl extends ServiceImpl