feat: 复习总览分页与全局汇总
This commit is contained in:
@@ -2,8 +2,10 @@ package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.ReviewFeedItem;
|
||||
import com.guo.learningprogresstracker.dto.ReviewSortPreference;
|
||||
import com.guo.learningprogresstracker.dto.ReviewSummary;
|
||||
import com.guo.learningprogresstracker.dto.ReviewTaskStats;
|
||||
import com.guo.learningprogresstracker.dto.StudyReportDetail;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateStandardMindMapRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.ReviewFeedbackRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateStudyReportRequest;
|
||||
@@ -85,11 +87,29 @@ public class ReviewController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务维度的复习统计汇总
|
||||
* 复习总览的全局汇总(任务/报告/碎片总数)。
|
||||
*
|
||||
* <p>列表接口分页后,前端只能看到当前页;把每页相加会得到「本页合计」而不是总数,
|
||||
* 因此汇总单独出接口,口径不受分页影响。</p>
|
||||
*/
|
||||
@GetMapping("/summary")
|
||||
public CommonResult<ReviewSummary> summary() {
|
||||
return CommonResult.success(reviewService.summary());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取任务维度的复习统计汇总。
|
||||
*
|
||||
* <p>分页不只为了排版:聚合(时长/报告数/碎片数)只算当前这一页的任务,
|
||||
* 不再对全部任务做 IN 聚合。{@code markerName} 把「点标签即筛选」下推到服务端,
|
||||
* 否则客户端只能筛当前页、total 也会不对。</p>
|
||||
*/
|
||||
@GetMapping("/tasks")
|
||||
public CommonResult<List<ReviewTaskStats>> getReviewTaskStats() {
|
||||
return CommonResult.success(reviewService.getReviewTaskStats());
|
||||
public CommonResult<Page<ReviewTaskStats>> getReviewTaskStats(
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
|
||||
@RequestParam(value = "markerName", required = false) String markerName) {
|
||||
return CommonResult.success(reviewService.getReviewTaskStats(pageNum, pageSize, markerName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 复习总览的全局汇总。
|
||||
*
|
||||
* <p>刻意单独出接口:任务列表已分页,客户端只能看到当前页,
|
||||
* 再把每页的报告数/碎片数相加会得到一个「看起来是总数、其实是本页合计」的错数字。</p>
|
||||
*
|
||||
* <p>口径与 {@code /review/tasks} 的列表完全一致(列表逐页相加 == 这里的汇总):
|
||||
* 报告按「报告 → 会话 → 任务」归属,碎片按内容归属({@code owner_task_num})统计。
|
||||
* 因此待归类碎片不计入 {@code fragmentTotal}(由总览的「待归类内容」独立区块展示),
|
||||
* 任务删除后残留的报告也不计入。</p>
|
||||
*/
|
||||
public record ReviewSummary(
|
||||
@Schema(description = "任务总数")
|
||||
long taskTotal,
|
||||
@Schema(description = "学习报告总数")
|
||||
long reportTotal,
|
||||
@Schema(description = "学习碎片总数")
|
||||
long fragmentTotal) {
|
||||
}
|
||||
@@ -27,6 +27,17 @@ public interface StudyReportFragmentsMapper extends BaseMapper<StudyReportFragme
|
||||
*/
|
||||
List<TaskContentCount> countFragmentsByTask(@Param("taskNums") Collection<String> taskNums);
|
||||
|
||||
/**
|
||||
* 复习总览汇总:当前用户全量「已归属」碎片数(不含待归类)。
|
||||
*
|
||||
* <p>口径必须与 {@link #countFragmentsByTask} 一致——按内容归属({@code owner_task_num})统计,
|
||||
* 只算仍指向现存(未删除)任务的碎片。待归类碎片由总览的「待归类内容」独立区块展示,
|
||||
* 不能在这里重复计数,否则汇总与列表逐页相加的结果对不上。</p>
|
||||
*
|
||||
* <p>语句见 {@code resources/mapper/StudyReportFragmentsMapper.xml}。</p>
|
||||
*/
|
||||
long countOwnedFragments();
|
||||
|
||||
/**
|
||||
* 取知识碎片的主键区间(复习-03):供随机取样计算随机起点。
|
||||
* <p>语句见 {@code resources/mapper/StudyReportFragmentsMapper.xml};无数据时两列为 null。</p>
|
||||
|
||||
@@ -28,6 +28,17 @@ public interface StudyReportsMapper extends BaseMapper<StudyReportsEntity> {
|
||||
* @param taskNums 需要统计的任务编号;为空时返回空列表
|
||||
*/
|
||||
List<TaskContentCount> countReportsByTask(@Param("taskNums") Collection<String> taskNums);
|
||||
|
||||
/**
|
||||
* 复习总览汇总:当前用户全量报告数。
|
||||
*
|
||||
* <p>口径必须与 {@link #countReportsByTask} 一致——按「报告 → 会话 → 任务」归属,
|
||||
* 只统计仍归属于现存(未删除)任务的报告。否则任务删除后残留的报告会被算进总览,
|
||||
* 与列表逐页相加的结果对不上。</p>
|
||||
*
|
||||
* <p>语句见 {@code resources/mapper/StudyReportsMapper.xml}。</p>
|
||||
*/
|
||||
long countOwnedReports();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.guo.learningprogresstracker.mapper;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
@@ -13,6 +15,18 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface TasksMapper extends BaseMapper<TaskEntity> {
|
||||
|
||||
/**
|
||||
* 按用户标签分页筛选任务(点标签即筛选)。
|
||||
*
|
||||
* <p>标记过滤直接下推到 SQL({@code EXISTS} 子查询),由数据库在一次查询里算出命中任务,
|
||||
* 不再「先查全部命中对象号、再拼 {@code IN} 回查」——命中量大时 {@code IN} 会膨胀,
|
||||
* 优化器也拿不到好的执行计划。排序与任务列表一致(优先级倒序、id 兜底保证翻页稳定)。</p>
|
||||
*
|
||||
* <p>语句见 {@code resources/mapper/TasksMapper.xml};租户条件由拦截器给 tasks 与 markers 分别追加。</p>
|
||||
*
|
||||
* @param markerName 用户标签名({@code kind=USER});空白时调用方不应走这个分支
|
||||
*/
|
||||
IPage<TaskEntity> selectPageByMarker(IPage<TaskEntity> page, @Param("markerName") String markerName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.guo.learningprogresstracker.service;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.ReviewFeedItem;
|
||||
import com.guo.learningprogresstracker.dto.ReviewSummary;
|
||||
import com.guo.learningprogresstracker.dto.ReviewTaskStats;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,9 +21,18 @@ public interface ReviewService {
|
||||
List<ReviewFeedItem> getReviewFeed(int limit, String mode);
|
||||
|
||||
/**
|
||||
* 获取所有任务的复习统计数据
|
||||
* 分页获取任务的复习统计数据(优先级倒序,同优先级按 id 倒序保证翻页稳定)。
|
||||
*
|
||||
* @param markerName 可选:只返回带该用户标签的任务(单个标记筛选,不做组合)
|
||||
*/
|
||||
List<ReviewTaskStats> getReviewTaskStats();
|
||||
Page<ReviewTaskStats> getReviewTaskStats(int pageNum, int pageSize, String markerName);
|
||||
|
||||
/**
|
||||
* 复习总览的全局汇总(任务/报告/碎片总数)。
|
||||
*
|
||||
* <p>不能由前端把分页后的每页数字相加:那样得到的是「本页合计」而不是总数。</p>
|
||||
*/
|
||||
ReviewSummary summary();
|
||||
|
||||
/**
|
||||
* 获取指定任务的复习统计数据
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guo.learningprogresstracker.dto.IdRange;
|
||||
import com.guo.learningprogresstracker.dto.ReviewFeedItem;
|
||||
import com.guo.learningprogresstracker.dto.ReviewSummary;
|
||||
import com.guo.learningprogresstracker.dto.ReviewTaskStats;
|
||||
import com.guo.learningprogresstracker.dto.StudyReportDetail;
|
||||
import com.guo.learningprogresstracker.dto.TaskRecallRatio;
|
||||
@@ -247,17 +250,40 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReviewTaskStats> getReviewTaskStats() {
|
||||
List<TaskEntity> tasks = tasksMapper.selectList(
|
||||
Wrappers.<TaskEntity>lambdaQuery()
|
||||
.orderByDesc(TaskEntity::getCalculatedPriority));
|
||||
public ReviewSummary summary() {
|
||||
// 口径必须与 /review/tasks 的列表一致(列表逐页相加 == 这里的汇总):
|
||||
// 报告按「报告 → 会话 → 任务」归属,碎片按内容归属(owner_task_num)统计。
|
||||
// 不能用裸表的 selectCount:那样「学习残片」会把待归类碎片也算进来,
|
||||
// 与列表逐页相加的结果对不上(待归类在总览里有独立区块展示)。
|
||||
return new ReviewSummary(
|
||||
tasksMapper.selectCount(null),
|
||||
studyReportsMapper.countOwnedReports(),
|
||||
studyReportFragmentsMapper.countOwnedFragments());
|
||||
}
|
||||
|
||||
List<ReviewTaskStats> stats = tasks.stream()
|
||||
@Override
|
||||
public Page<ReviewTaskStats> getReviewTaskStats(int pageNum, int pageSize, String markerName) {
|
||||
// 点标签即筛选:过滤下推到 SQL(EXISTS 子查询),由数据库一次算出命中任务并分页;
|
||||
// 不再「先查全部命中对象号、再拼 IN 回查」——命中量大时 IN 会膨胀。
|
||||
IPage<TaskEntity> taskPage;
|
||||
if (StringUtils.hasText(markerName)) {
|
||||
taskPage = tasksMapper.selectPageByMarker(new Page<>(pageNum, pageSize), markerName.trim());
|
||||
} else {
|
||||
taskPage = tasksMapper.selectPage(new Page<>(pageNum, pageSize),
|
||||
Wrappers.<TaskEntity>lambdaQuery()
|
||||
.orderByDesc(TaskEntity::getCalculatedPriority)
|
||||
// 优先级相同的任务之间要有稳定次序,否则翻页会重复或漏掉
|
||||
.orderByDesc(TaskEntity::getId));
|
||||
}
|
||||
List<ReviewTaskStats> stats = taskPage.getRecords().stream()
|
||||
.map(this::newTaskStats)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 聚合只算这一页的任务,不再对全部任务做 IN 聚合
|
||||
fillReviewTaskStats(stats);
|
||||
return stats;
|
||||
|
||||
Page<ReviewTaskStats> result = new Page<>(taskPage.getCurrent(), taskPage.getSize(), taskPage.getTotal());
|
||||
result.setRecords(stats);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user