From c1385911c61d55300bcf1b3deac6124f284cd274 Mon Sep 17 00:00:00 2001 From: cat_shark <1716967236@qq.com> Date: Sun, 5 Jul 2026 10:35:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BC=9A=E8=AF=9D)=EF=BC=9A=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=AE=8B=E7=89=87/=E6=8A=A5=E5=91=8A=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StudySessionsService 新增: - getTaskFragments(taskNum, page, size, keyword) → Page - getTaskReports(taskNum, page, size, keyword) → Page 通过子查询 session_num in (select session_num from study_sessions where task_num = ?) 实现跨 session 聚合,keyword 支持 content 字段 LIKE 搜索。接口使用 MyBatis-Plus Page 分页。 控制器新增两个 GET 端点: - /study-sessions/tasks/{taskNum}/fragments - /study-sessions/tasks/{taskNum}/reports --- .../controller/StudySessionController.java | 23 ++++++++++++++++ .../service/StudySessionsService.java | 8 ++++++ .../impl/StudySessionsServiceImpl.java | 27 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java index 7c26c59..62011e5 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java @@ -4,8 +4,11 @@ import com.google.protobuf.ServiceException; import com.guo.learningprogresstracker.dto.request.EndedStudySessionRequest; import com.guo.learningprogresstracker.dto.request.UpsertExpectationRequest; import com.guo.learningprogresstracker.dto.response.StudySessionResponse; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.entity.StudyExpectationsEntity; +import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity; +import com.guo.learningprogresstracker.entity.StudyReportsEntity; import com.guo.learningprogresstracker.exception.ErrorParameterException; import com.guo.learningprogresstracker.service.StudyExpectationsService; import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl; @@ -107,4 +110,24 @@ public class StudySessionController { public CommonResult getReportDraft(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException { return CommonResult.success("请求成功", studySessionsServiceImpl.generateReportDraft(sessionNum)); } + + /** 分页查询任务的残片历史 */ + @GetMapping("/tasks/{taskNum}/fragments") + public CommonResult> getTaskFragments( + @PathVariable String taskNum, + @RequestParam(defaultValue = "1") int page, + @RequestParam(defaultValue = "10") int size, + @RequestParam(required = false) String keyword) { + return CommonResult.success(studySessionsServiceImpl.getTaskFragments(taskNum, page, size, keyword)); + } + + /** 分页查询任务的报告历史 */ + @GetMapping("/tasks/{taskNum}/reports") + public CommonResult> getTaskReports( + @PathVariable String taskNum, + @RequestParam(defaultValue = "1") int page, + @RequestParam(defaultValue = "10") int size, + @RequestParam(required = false) String keyword) { + return CommonResult.success(studySessionsServiceImpl.getTaskReports(taskNum, page, size, keyword)); + } } diff --git a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java index 43880e6..3348823 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java @@ -2,7 +2,11 @@ package com.guo.learningprogresstracker.service; import com.google.protobuf.ServiceException; 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; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.guo.learningprogresstracker.exception.ErrorParameterException; @@ -25,4 +29,8 @@ public interface StudySessionsService extends IService { void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException, ServiceException; void continueStudySession(String sessionNum) throws ErrorParameterException, ServiceException; + + Page getTaskFragments(String taskNum, int page, int size, String keyword); + + Page getTaskReports(String taskNum, int page, int size, String keyword); } 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 8b7c083..159e57d 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java @@ -1,6 +1,7 @@ package com.guo.learningprogresstracker.service.impl; 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.google.protobuf.ServiceException; import com.guo.learningprogresstracker.dto.StudySessionsDto; @@ -190,4 +191,30 @@ public class StudySessionsServiceImpl extends ServiceImpl String.join("\n", fragments)); } + // ============ 分页查询任务的历史残片/报告 ============ + + @Override + public Page getTaskFragments(String taskNum, int page, int size, String keyword) { + Page pg = new Page<>(page, size); + var wrapper = Wrappers.lambdaQuery(StudyReportFragmentsEntity.class) + .apply("session_num in (select session_num from study_sessions where task_num = {0})", taskNum) + .orderByDesc(StudyReportFragmentsEntity::getCreatedTime); + if (keyword != null && !keyword.isBlank()) { + wrapper.like(StudyReportFragmentsEntity::getContent, keyword); + } + return studyReportFragmentsMapper.selectPage(pg, wrapper); + } + + @Override + public Page getTaskReports(String taskNum, int page, int size, String keyword) { + Page pg = new Page<>(page, size); + var wrapper = Wrappers.lambdaQuery(StudyReportsEntity.class) + .apply("session_num in (select session_num from study_sessions where task_num = {0})", taskNum) + .orderByDesc(StudyReportsEntity::getCreatedTime); + if (keyword != null && !keyword.isBlank()) { + wrapper.like(StudyReportsEntity::getContent, keyword); + } + return studyReportsMapper.selectPage(pg, wrapper); + } + }