feat: 新增复习耗时统计与按任务汇总
This commit is contained in:
@@ -378,6 +378,45 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
});
|
||||
|
||||
fillReportAndFragmentCount(sessionToTaskNum, statsByTaskNum);
|
||||
fillReviewDuration(statsByTaskNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按任务汇总复习行为累计耗时(复习-07)。在 SQL 侧聚合,只把任务数量的行拉回内存,
|
||||
* 不随回忆记录条数增长。
|
||||
*/
|
||||
private void fillReviewDuration(Map<String, ReviewTaskStats> statsByTaskNum) {
|
||||
List<Map<String, Object>> rows = reviewRecallRecordMapper.selectMaps(
|
||||
Wrappers.<ReviewRecallRecordEntity>query()
|
||||
.select("task_num AS taskNum",
|
||||
"COALESCE(SUM(review_duration_seconds), 0) AS reviewDurationSeconds")
|
||||
.in("task_num", statsByTaskNum.keySet())
|
||||
.groupBy("task_num"));
|
||||
|
||||
for (Map<String, Object> row : rows) {
|
||||
Object taskNum = columnValue(row, "taskNum");
|
||||
Object duration = columnValue(row, "reviewDurationSeconds");
|
||||
ReviewTaskStats stats = taskNum == null ? null : statsByTaskNum.get(taskNum.toString());
|
||||
if (stats != null && duration instanceof Number number) {
|
||||
stats.setReviewDurationSeconds(number.longValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取聚合结果的列:别名大小写随数据库实现不同(MySQL 保留、H2 会转为小写),这里统一不区分大小写。
|
||||
*/
|
||||
private static Object columnValue(Map<String, Object> row, String column) {
|
||||
Object direct = row.get(column);
|
||||
if (direct != null) {
|
||||
return direct;
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
if (entry.getKey() != null && entry.getKey().equalsIgnoreCase(column)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fillReportAndFragmentCount(Map<String, String> sessionToTaskNum,
|
||||
|
||||
Reference in New Issue
Block a user