feat:1. 修正错误命名 2. 为学习会话详情接口增加taskName字段

This commit is contained in:
2025-06-29 16:48:31 +08:00
parent aa9a278108
commit 5f9e01cf14
10 changed files with 106 additions and 36 deletions
@@ -2,7 +2,7 @@ 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.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
@@ -41,12 +41,12 @@ public class StudySessionController {
* 通过sessionNum获取一个【学习会话】
*/
@GetMapping("/{sessionNum}")
public CommonResult<StudySessionResponce> getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = studySessionsServiceImpl.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
StudySessionResponce studySessionResponce = StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
return CommonResult.success(studySessionResponce);
StudySessionResponse studySessionResponse = StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
return CommonResult.success(studySessionResponse);
}
/**
@@ -1,10 +1,9 @@
package com.guo.learningprogresstracker.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guo.learningprogresstracker.common.Ops;
import com.guo.learningprogresstracker.dto.TaskInfo;
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.dto.request.TaskRequest;
@@ -80,9 +79,9 @@ public class TaskController {
* 开始或继续一个【学习会话】
*/
@GetMapping("/{taskNum}/study-sessions/start-or-continue")
public CommonResult<StudySessionResponce> startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空")
public CommonResult<StudySessionResponse> startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空")
@PathVariable String taskNum) throws NotFindEntitiesException {
StudySessionResponce response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
StudySessionResponse response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
return CommonResult.success(response);
}
@@ -91,9 +90,9 @@ public class TaskController {
* 通过学习任务num获取该任务的未结束会话
*/
@GetMapping("/{taskNum}/not-ended-study-session")
public CommonResult<StudySessionResponce> getNotEndedStudySessionByTaskNum(@NotEmpty(message = "taskNum不可为空")
public CommonResult<StudySessionResponse> getNotEndedStudySessionByTaskNum(@NotEmpty(message = "taskNum不可为空")
@PathVariable String taskNum) throws ErrorParameterException {
StudySessionResponce response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum);
StudySessionResponse response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum);
return CommonResult.success(response);
}
}
@@ -0,0 +1,53 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class StudySessionsDto {
private String sessionNum;
/**
* 任务名称
*/
private String taskName;
/**
* 任务编号
*/
private String taskNum;
/**
* 学习开始时间
*/
private LocalDateTime startTime;
private LocalDateTime lastStartTime;
/**
* 学习结束时间
*/
private LocalDateTime endTime;
/**
* 实际使用时间(秒)
*/
private double actualTime;
/**
* 有效学习时间(秒)
*/
private double effectiveTime;
/**
* 有效时间比
*/
private double effectivenessRatio;
/**
* 学习会话的状态(进行中、暂停、已结束)
*/
private String sessionState;
}
@@ -6,12 +6,16 @@ import lombok.Data;
import java.time.LocalDateTime;
@Data
public class StudySessionResponce {
public class StudySessionResponse {
@Schema(description = "会话编号")
private String sessionNum;
private String taskNum;
@Schema(description = "任务名称")
private String taskName;
@Schema(description = "任务编号")
private String taskNum;
@Schema(description = "学习开始时间")
private LocalDateTime startTime;
@@ -29,7 +29,7 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
private String sessionNum;
/**
*
* 任务编号
*/
@TableField(value = "task_num")
private String taskNum;
@@ -1,6 +1,7 @@
package com.guo.learningprogresstracker.mapStruct;
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
import com.guo.learningprogresstracker.dto.StudySessionsDto;
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
@@ -11,5 +12,7 @@ public interface StudySessionConvert {
StudySessionConvert MAPPER = Mappers.getMapper(StudySessionConvert.class);
StudySessionResponce toStudySessionResponce(StudySessionsEntity studySessionsEntity);
StudySessionResponse toStudySessionResponse(StudySessionsEntity studySessionsEntity);
StudySessionResponse toStudySessionResponse(StudySessionsDto dto);
}
@@ -1,8 +1,10 @@
package com.guo.learningprogresstracker.mapper;
import com.guo.learningprogresstracker.dto.StudySessionsDto;
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @author guo
@@ -13,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface StudyReportsMapper extends BaseMapper<StudyReportsEntity> {
StudySessionsDto getNotEndedStudySessionDtoByTaskNum(@Param("task_num") String taskNum);
}
@@ -1,6 +1,6 @@
package com.guo.learningprogresstracker.service;
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.baomidou.mybatisplus.extension.service.IService;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
@@ -14,7 +14,7 @@ import java.util.ArrayList;
*/
public interface StudySessionsService extends IService<StudySessionsEntity> {
StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException;
StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException;
ArrayList<String> getAllFragments(String sessionNum) throws ErrorParameterException;
@@ -2,7 +2,8 @@ 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.dto.StudySessionsDto;
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
@@ -38,7 +39,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
private final StudyReportsMapper studyReportsMapper;
public StudySessionResponce startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
// taskNum是否存在
tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在",taskNum)));
@@ -53,13 +54,13 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
studySessionsEntity.setTaskNum(taskNum);
studySessionsEntity.setLastStartTime(LocalDateTime.now());
this.save(studySessionsEntity);
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
return StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
}else {
// 返回已经存在的会话
StudySessionsEntity studySessionsEntity = oneOpt.get();
studySessionsEntity.continueStudySession();
this.updateById(studySessionsEntity);
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
return StudySessionConvert.MAPPER.toStudySessionResponse(studySessionsEntity);
}
}
@@ -88,12 +89,10 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
}
@Override
public StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getTaskNum, taskNum)
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()))
public StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
StudySessionsDto dto = Optional.ofNullable(studyReportsMapper.getNotEndedStudySessionDtoByTaskNum(taskNum))
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话"));
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
return StudySessionConvert.MAPPER.toStudySessionResponse(dto);
}
@Override
@@ -3,20 +3,29 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.guo.learningprogresstracker.mapper.StudyReportsMapper">
<resultMap id="BaseResultMap" type="com.guo.learningprogresstracker.entity.StudyReportsEntity">
<id property="reportId" column="report_id" jdbcType="INTEGER"/>
<result property="sessionId" column="session_id" jdbcType="INTEGER"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="lastModifiedTime" column="last_modified_time" jdbcType="TIMESTAMP"/>
<result property="lastModifiedBy" column="last_modified_by" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="lastModifiedTime" column="last_modified_time" jdbcType="TIMESTAMP"/>
<result property="lastModifiedBy" column="last_modified_by" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List">
report_id,session_id,content,
created_time,created_by,last_modified_time,
report_id,
session_id,
content,
created_time,
created_by,
last_modified_time,
last_modified_by
</sql>
<select id="getNotEndedStudySessionDtoByTaskNum" resultType="com.guo.learningprogresstracker.dto.StudySessionsDto">
select t.task_name, ss.*
from study_sessions ss
left join tasks t on ss.task_num = t.task_num and ss.session_state != 'ENDED' and ss.deleted = 0
where t.deleted = 0
and t.task_num = ${task_num}
</select>
</mapper>