diff --git a/src/main/java/com/guo/learningprogresstracker/controller/LoginController.java b/src/main/java/com/guo/learningprogresstracker/controller/LoginController.java index fb9c393..32e482d 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/LoginController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/LoginController.java @@ -33,11 +33,10 @@ public class LoginController { return CommonResult.success("登录成功!", token); } - @Operation(summary = "退出登录API-功能未完成") - @PostMapping("/loingOut") - public CommonResult loingOut(@RequestBody LoginBody loginBody) throws AppException { - //todo loginOut 退出登录API -// loginService.loginOut(); + @Operation(summary = "退出登录API") + @PostMapping("/logout") + public CommonResult logout() { + loginService.logout(); return CommonResult.success("已登出"); } -} \ No newline at end of file +} diff --git a/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponse.java b/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponse.java index 1041fac..db0a828 100644 --- a/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponse.java +++ b/src/main/java/com/guo/learningprogresstracker/dto/response/StudySessionResponse.java @@ -28,11 +28,11 @@ public class StudySessionResponse { private LocalDateTime endTime; - @Schema(description = "实际使用时间(分钟)") + @Schema(description = "实际使用时间(秒)") private double actualTime; - @Schema(description = "有效学习时间(分钟)") + @Schema(description = "有效学习时间(秒)") private double effectiveTime; @@ -43,7 +43,7 @@ public class StudySessionResponse { @Schema(description = "学习会话的状态(进行中、暂停、已结束)") private String sessionState; - @Schema(description = "倒计时开始位置(S)") + @Schema(description = "倒计时指针位置(毫秒)") private double pointerPosition; @Schema(description = "系统提示") diff --git a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java index 2baa7df..95e9c4a 100644 --- a/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java +++ b/src/main/java/com/guo/learningprogresstracker/entity/StudySessionsEntity.java @@ -95,6 +95,8 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { StudySessionsEntity studySessionsEntity = new StudySessionsEntity(); studySessionsEntity.setSessionNum(GenerateNumTool.generateNum("SESSION")); studySessionsEntity.setStartTime(LocalDateTime.now()); + studySessionsEntity.setLastStartTime(LocalDateTime.now()); + studySessionsEntity.setPointerPosition(WORK_DURATION * 60 * 1000L); studySessionsEntity.setLastModifiedTime(LocalDateTime.now()); studySessionsEntity.setSessionState(StudySessionStateEnum.ONGOING.name()); return studySessionsEntity; @@ -150,13 +152,7 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { * @return */ public boolean isFirstRun() { - if (ObjectUtils.isEmpty(this.lastStartTime)) { - return false; - } else if (this.lastStartTime.equals(this.startTime)) { - return true; - } else { - return false; - } + return ObjectUtils.isEmpty(this.pointerPosition); } @@ -187,10 +183,13 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { case ONGOING: long elapsedMillis = Duration.between(lastStartTime, LocalDateTime.now()).toMillis(); - long newPointerPosition = pointerPosition - elapsedMillis; + long basePointerPosition = ObjectUtils.isEmpty(pointerPosition) + ? WORK_DURATION * 60 * 1000L + : pointerPosition; + long newPointerPosition = basePointerPosition - elapsedMillis; if (newPointerPosition <= 0) { // 如果循环已经结束,则需要重置指针位置 - this.pointerPosition = WORK_DURATION * 1000L; + this.pointerPosition = WORK_DURATION * 60 * 1000L; } else { this.pointerPosition = newPointerPosition; } @@ -215,4 +214,4 @@ public class StudySessionsEntity extends BaseEntity implements Serializable { long minutes = Duration.between(ObjectUtils.isEmpty(lastStartTime) ? LocalDateTime.now() : lastStartTime, now).toMinutes(); return minutes >= WORK_DURATION * 2; } -} \ No newline at end of file +} diff --git a/src/main/java/com/guo/learningprogresstracker/service/LoginService.java b/src/main/java/com/guo/learningprogresstracker/service/LoginService.java index d10cf8d..c06dfc9 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/LoginService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/LoginService.java @@ -5,4 +5,6 @@ import com.guo.learningprogresstracker.exception.AppException; public interface LoginService { String login(String userId) throws AppException; + + void logout(); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/LoginServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/LoginServiceImpl.java index ca6854b..c14715f 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/LoginServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/LoginServiceImpl.java @@ -3,14 +3,10 @@ package com.guo.learningprogresstracker.service.impl; import cn.dev33.satoken.stp.StpUtil; import com.guo.learningprogresstracker.exception.AppException; import com.guo.learningprogresstracker.service.LoginService; -import com.guo.learningprogresstracker.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class LoginServiceImpl implements LoginService { - @Autowired - private UserService userService; @Override public String login(String userId) throws AppException { @@ -18,4 +14,9 @@ public class LoginServiceImpl implements LoginService { //todo Token只在此处使用了,属于后续优化点 return StpUtil.getTokenInfo().getTokenValue(); } + + @Override + public void logout() { + StpUtil.logout(); + } } 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 f21c398..c44b4a1 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/TasksServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/TasksServiceImpl.java @@ -71,7 +71,17 @@ public class TasksServiceImpl extends ServiceImpl @Override public void updateTask(String taskId, TaskRequest updatedTask) { TaskEntity taskEntity = TaskConvert.MAPPER.taskRequestToTaskEntity(updatedTask); - this.updateById(taskEntity); + int id; + try { + id = Integer.parseInt(taskId); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("任务ID格式错误: " + taskId); + } + taskEntity.setId(id); + boolean updated = this.updateById(taskEntity); + if (!updated) { + throw new IllegalArgumentException("任务不存在或更新失败: " + taskId); + } } @@ -86,4 +96,3 @@ public class TasksServiceImpl extends ServiceImpl - diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 82957aa..38c2f05 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -2,7 +2,7 @@ spring: # 配置数据库 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://mysql8:3306/learning_progress_tracker?allowPublicKeyRetrieval=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 + url: jdbc:mysql://mysql:3306/learning_progress_tracker?allowPublicKeyRetrieval=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 username: root password: GUOxy5157 server: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 82fe589..4bbd53a 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -2,17 +2,18 @@ spring: # 配置数据库 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/learning_progress_tracker?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 + url: jdbc:mysql://39.105.149.197:8109/learning_progress_tracker?allowPublicKeyRetrieval=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 username: root - password: + password: GUOxy5157 server: port: 5157 cors: + allowCredentials: true allowed-origins: - - http://localhost:5158 - - http://192.168.123.199:5158 + - '*' sa-token: cookie: - secure: false \ No newline at end of file + secure: false + sameSite: Lax \ No newline at end of file diff --git a/src/main/resources/mapper/StudyReportsMapper.xml b/src/main/resources/mapper/StudyReportsMapper.xml index 1d63e81..d199754 100644 --- a/src/main/resources/mapper/StudyReportsMapper.xml +++ b/src/main/resources/mapper/StudyReportsMapper.xml @@ -26,6 +26,8 @@ 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} + and t.task_num = #{task_num} + order by ss.last_modified_time desc, ss.created_time desc + limit 1