From 6005782b14dca67a15808dc3e6a9eeec51a32f9b Mon Sep 17 00:00:00 2001 From: guo <1716967236@qq.com> Date: Sun, 22 Sep 2024 08:20:48 +0800 Subject: [PATCH] =?UTF-8?q?[xingyu.guo]=20feat:=201.=20=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=93=8D=E5=BA=94=E5=80=BC=E4=B8=AD=E7=9A=84?= =?UTF-8?q?id=E4=B8=BAnum,=E4=B8=8D=E5=B0=86=E9=9D=9E=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=B1=95=E7=A4=BA=E7=BB=99=E5=A4=96=E9=83=A8?= =?UTF-8?q?=202.=20=E8=B0=83=E6=95=B4[=E5=AE=9E=E9=99=85=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=97=B6=E9=97=B4]=E7=AD=89=E5=AD=97=E6=AE=B5=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=BAdouble,=E6=96=B9=E4=BE=BF=E8=AE=A1=E7=AE=97\?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=B8=8E=E8=AF=BB=E5=8F=96=203.=20=E3=80=90?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89=E4=BB=BB=E5=8A=A1=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E3=80=91api=EF=BC=8C=E5=AE=8C=E5=96=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=204.=E5=B0=86int=E7=B1=BB=E5=9E=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8Integer=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E5=8A=A0=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StudySessionController.java | 18 +++++++++------- .../controller/TaskController.java | 8 ++++--- .../learningprogresstracker/dto/TaskInfo.java | 20 ++++++++++++++++++ .../dto/response/StudySessionResponce.java | 8 +++---- .../dto/response/TasksListInfoResponse.java | 11 +--------- .../entity/StudySessionsEntity.java | 18 +++++++++------- .../entity/TaskEntity.java | 8 +++---- .../mapStruct/TaskConvert.java | 8 +++++++ .../service/TasksService.java | 7 ++++--- .../impl/StudySessionsServiceImpl.java | 9 +++++--- .../service/impl/TasksServiceImpl.java | 17 +++++++++++---- .../resources/mapper/StudySessionsMapper.xml | 21 ------------------- 12 files changed, 86 insertions(+), 67 deletions(-) create mode 100644 src/main/java/com/guo/learningprogresstracker/dto/TaskInfo.java diff --git a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java index 34a8a52..d762513 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java @@ -1,5 +1,6 @@ package com.guo.learningprogresstracker.controller; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.guo.learningprogresstracker.dto.response.StudySessionResponce; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.entity.StudySessionsEntity; @@ -32,12 +33,13 @@ public class StudySessionController { } /** - * 通过sessionId获取一个【学习会话】 + * 通过sessionNum获取一个【学习会话】 */ - @GetMapping("/{sessionId}") - public CommonResult getStudySession(@NotEmpty(message = "sessionId不可为空") @PathVariable String sessionId) throws ErrorParameterException { - StudySessionsEntity studySessionsEntity = studySessionsServiceImpl.getOptById(sessionId) - .orElseThrow(() -> new ErrorParameterException("会话[" + sessionId + "]不存在")); + @GetMapping("/{sessionNum}") + public CommonResult getStudySession(@NotEmpty(message = "sessionId不可为空") @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); } @@ -45,9 +47,9 @@ public class StudySessionController { /** * 暂停一个【学习会话】 */ - @PostMapping("/{taskId}/studay-sessions/pause") - public CommonResult pauseStudySession(@PathVariable("sessionId") String sessionId) throws ErrorParameterException { - studySessionsServiceImpl.pauseStudySession(sessionId); + @PostMapping("/{sessionNum}/studay-sessions/pause") + public CommonResult pauseStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException { + studySessionsServiceImpl.pauseStudySession(sessionNum); return CommonResult.success(); } diff --git a/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java b/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java index 05ee47c..0bd74d8 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.rmi.ServerException; @@ -64,8 +65,9 @@ public class TaskController { @GetMapping("/tasks") @Operation(summary = "获取所有任务列表") - public CommonResult tasksList() { - return CommonResult.success(tasksService.taskList()); + public CommonResult tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + return CommonResult.success(tasksService.taskList(pageNum, pageSize)); } /** @@ -73,7 +75,7 @@ public class TaskController { * */ @GetMapping("/{taskNum}/studay-sessions/start-or-continue") - public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskId不可为空") + public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空") @PathVariable String taskNum) throws NotFindEntitiesException { StudySessionResponce responce = studySessionsServiceImpl.startOrContinueStudySession(taskNum); return CommonResult.success(responce); diff --git a/src/main/java/com/guo/learningprogresstracker/dto/TaskInfo.java b/src/main/java/com/guo/learningprogresstracker/dto/TaskInfo.java new file mode 100644 index 0000000..fbba707 --- /dev/null +++ b/src/main/java/com/guo/learningprogresstracker/dto/TaskInfo.java @@ -0,0 +1,20 @@ +package com.guo.learningprogresstracker.dto; + +import lombok.Data; + +/** + * @author guo + */ +@Data +public class TaskInfo { + // 任务编码 + private String taskNum; + // 任务名称 + private String taskName; + // 任务描述 + private String taskDescription; + // 任务优先级 + private Double taskPriority; + // 上次该任务学习情况 + private String lastLearningStatus; +} diff --git a/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponce.java b/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponce.java index d7a8e02..ea01c44 100644 --- a/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponce.java +++ b/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponce.java @@ -8,9 +8,9 @@ import java.time.LocalDateTime; @Data public class StudySessionResponce { - private Integer sessionId; + private String sessionNum; - private Integer taskId; + private String taskNum; @Schema(description = "学习开始时间") @@ -25,11 +25,11 @@ public class StudySessionResponce { @Schema(description = "实际使用时间(分钟)") - private Integer actualTime; + private double actualTime; @Schema(description = "有效学习时间(分钟)") - private Integer effectiveTime; + private double effectiveTime; @Schema(description = "有效时间比") diff --git a/src/main/java/com/guo/learningprogresstracker/dto/response/TasksListInfoResponse.java b/src/main/java/com/guo/learningprogresstracker/dto/response/TasksListInfoResponse.java index 2ca6c45..d872c93 100644 --- a/src/main/java/com/guo/learningprogresstracker/dto/response/TasksListInfoResponse.java +++ b/src/main/java/com/guo/learningprogresstracker/dto/response/TasksListInfoResponse.java @@ -1,5 +1,6 @@ package com.guo.learningprogresstracker.dto.response; +import com.guo.learningprogresstracker.dto.TaskInfo; import lombok.Data; import java.util.List; @@ -13,14 +14,4 @@ public class TasksListInfoResponse { private List taskList; - static class TaskInfo{ - // 任务名称 - private String taskName; - // 任务描述 - private String taskDescription; - // 任务优先级 - private Integer taskPriority; - // 上次该任务学习情况 - private String lastLearningStatus; - } } diff --git a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java index c95fb8d..1d05a9f 100644 --- a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java +++ b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.guo.learningprogresstracker.enums.StudySessionStateEnum; +import com.guo.learningprogresstracker.utils.GenerateNumTool; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -49,22 +50,22 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { private LocalDateTime endTime; /** - * 实际使用时间(分钟) + * 实际使用时间(秒) */ @TableField(value = "actual_time") - private Integer actualTime; + private double actualTime; /** - * 有效学习时间(分钟) + * 有效学习时间(秒) */ @TableField(value = "effective_time") - private Integer effectiveTime; + private double effectiveTime; /** * 有效时间比 */ @TableField(value = "effectiveness_ratio") - private Double effectivenessRatio; + private double effectivenessRatio; /** * 学习会话的状态(进行中、暂停、已结束) @@ -82,6 +83,7 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { */ public static StudySessionsEntity initNewSession(){ StudySessionsEntity studySessionsEntity = new StudySessionsEntity(); + studySessionsEntity.setSessionNum(GenerateNumTool.generateNum("SESSION")); studySessionsEntity.setStartTime(LocalDateTime.now()); studySessionsEntity.setLastModifiedTime(LocalDateTime.now()); studySessionsEntity.setSessionState(StudySessionStateEnum.ONGOING.name()); @@ -105,11 +107,13 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { */ public void pausedStudySession(){ if (this.getSessionState().equals(StudySessionStateEnum.PAUSED.name())){ + log.warn("不应出现的情况:暂停了一个状态为【{}】的学习会话",this.getSessionState()); // }else { this.setEndTime(LocalDateTime.now()); - this.setEffectiveTime((int) Duration.between(this.lastStartTime,this.endTime).toMinutes()); - this.setActualTime((int) Duration.between(this.endTime,this.startTime).toMinutes()); + this.setActualTime(Duration.between(this.startTime,this.endTime).toSeconds()); + this.setEffectiveTime(this.getEffectiveTime()+Duration.between(this.lastStartTime,this.endTime).toSeconds()); + this.setEffectivenessRatio(this.effectiveTime/this.actualTime); this.setSessionState(StudySessionStateEnum.PAUSED.name()); } } diff --git a/src/main/java/com/guo/learningprogresstracker/entity/TaskEntity.java b/src/main/java/com/guo/learningprogresstracker/entity/TaskEntity.java index cc80c0b..0ebc041 100644 --- a/src/main/java/com/guo/learningprogresstracker/entity/TaskEntity.java +++ b/src/main/java/com/guo/learningprogresstracker/entity/TaskEntity.java @@ -4,13 +4,13 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; - import lombok.Data; -import lombok.EqualsAndHashCode; + +import java.io.Serializable; /** * 存储学习任务的基本信息,包括优先级的多维度计算 + * @author guo * @TableName tasks */ @TableName(value ="tasks") @@ -18,7 +18,7 @@ import lombok.EqualsAndHashCode; public class TaskEntity extends BaseEntity implements Serializable { @TableId(value = "id",type = IdType.AUTO) - private int id; + private Integer id; /** * 任务编码 diff --git a/src/main/java/com/guo/learningprogresstracker/mapStruct/TaskConvert.java b/src/main/java/com/guo/learningprogresstracker/mapStruct/TaskConvert.java index 6acb88f..c6be1c5 100644 --- a/src/main/java/com/guo/learningprogresstracker/mapStruct/TaskConvert.java +++ b/src/main/java/com/guo/learningprogresstracker/mapStruct/TaskConvert.java @@ -1,10 +1,13 @@ package com.guo.learningprogresstracker.mapStruct; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.guo.learningprogresstracker.dto.TaskInfo; import com.guo.learningprogresstracker.dto.request.TaskRequest; import com.guo.learningprogresstracker.dto.response.TaskInfoResponse; import com.guo.learningprogresstracker.entity.TaskEntity; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.ReportingPolicy; import org.mapstruct.factory.Mappers; @@ -19,4 +22,9 @@ public interface TaskConvert { TaskEntity taskRequestToTaskEntity(TaskRequest taskRequest); TaskInfoResponse taskEntityToTaskInfoResponse(TaskEntity taskEntity); + + @Mapping(source = "calculatedPriority",target = "taskPriority") + TaskInfo toTaskInfo(TaskEntity taskEntity); + + Page toTaskInfoPage(Page page); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/TasksService.java b/src/main/java/com/guo/learningprogresstracker/service/TasksService.java index d8f5e2d..680cd53 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/TasksService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/TasksService.java @@ -1,10 +1,11 @@ package com.guo.learningprogresstracker.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.guo.learningprogresstracker.dto.TaskInfo; import com.guo.learningprogresstracker.dto.request.TaskRequest; import com.guo.learningprogresstracker.dto.response.TaskInfoResponse; -import com.guo.learningprogresstracker.dto.response.TasksListInfoResponse; import com.guo.learningprogresstracker.entity.TaskEntity; -import com.baomidou.mybatisplus.extension.service.IService; import java.rmi.ServerException; @@ -15,7 +16,7 @@ import java.rmi.ServerException; */ public interface TasksService extends IService { - TasksListInfoResponse taskList(); + Page taskList(Integer pageNum, Integer pageSize); String addTask(TaskRequest taskRequest); 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 f8706df..e696f27 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java @@ -14,6 +14,7 @@ import com.guo.learningprogresstracker.service.StudySessionsService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.Optional; /** @@ -41,6 +42,7 @@ public class StudySessionsServiceImpl extends ServiceImpl new ErrorParameterException("会话[" + sessionId + "]不存在")); + public void pauseStudySession(String sessionNum) throws ErrorParameterException { + StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class) + .eq(StudySessionsEntity::getSessionNum, sessionNum)) + .orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在")); studySessionsEntity.pausedStudySession(); this.updateById(studySessionsEntity); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/TasksServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/TasksServiceImpl.java index 5e25076..c721fc4 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/TasksServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/TasksServiceImpl.java @@ -1,13 +1,18 @@ package com.guo.learningprogresstracker.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.guo.learningprogresstracker.dto.PriorityDto; +import com.guo.learningprogresstracker.dto.TaskInfo; import com.guo.learningprogresstracker.dto.request.TaskRequest; import com.guo.learningprogresstracker.dto.response.TaskInfoResponse; import com.guo.learningprogresstracker.dto.response.TasksListInfoResponse; import com.guo.learningprogresstracker.entity.TaskEntity; import com.guo.learningprogresstracker.mapStruct.RequestConvert; import com.guo.learningprogresstracker.mapStruct.TaskConvert; +import com.guo.learningprogresstracker.mapStruct.TaskConvertImpl; import com.guo.learningprogresstracker.service.TasksService; import com.guo.learningprogresstracker.mapper.TasksMapper; import com.guo.learningprogresstracker.utils.CalculatedPriorityTool; @@ -17,6 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.rmi.ServerException; +import java.util.List; /** * @author guo @@ -30,12 +36,15 @@ public class TasksServiceImpl extends ServiceImpl implements TasksService{ - @Override - public TasksListInfoResponse taskList() { + private final TasksMapper tasksMapper; + private final TaskConvertImpl taskConvertImpl; - TasksListInfoResponse result = new TasksListInfoResponse(); + @Override + public Page taskList(Integer pageNum, Integer pageSize) { + Page page = tasksMapper.selectPage(new Page(pageNum, pageSize), Wrappers.lambdaQuery(TaskEntity.class)); //todo 补充返回内容 - return result; + Page response = taskConvertImpl.MAPPER.toTaskInfoPage(page); + return response; } @Override diff --git a/src/main/resources/mapper/StudySessionsMapper.xml b/src/main/resources/mapper/StudySessionsMapper.xml index 1ce2b96..886fdcd 100644 --- a/src/main/resources/mapper/StudySessionsMapper.xml +++ b/src/main/resources/mapper/StudySessionsMapper.xml @@ -4,25 +4,4 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - session_id,task_id,start_time, - end_time,actual_time,effective_time, - effectiveness_ratio,session_state,created_by, - last_modified_time,last_modified_by,created_time -