|
@@ -114,6 +114,8 @@ public class ArticleService {
|
|
|
List<Article> visible = articlePermissionService.filterVisible(
|
|
List<Article> visible = articlePermissionService.filterVisible(
|
|
|
result.getRecords(), userId, familyId, vendorType);
|
|
result.getRecords(), userId, familyId, vendorType);
|
|
|
|
|
|
|
|
|
|
+ enrichTotalDurationSeconds(visible);
|
|
|
|
|
+
|
|
|
Page<Article> filtered = new Page<>(page, size);
|
|
Page<Article> filtered = new Page<>(page, size);
|
|
|
filtered.setTotal(visible.size());
|
|
filtered.setTotal(visible.size());
|
|
|
filtered.setRecords(visible);
|
|
filtered.setRecords(visible);
|
|
@@ -144,6 +146,8 @@ public class ArticleService {
|
|
|
List<Article> all = articleMapper.selectList(wrapper);
|
|
List<Article> all = articleMapper.selectList(wrapper);
|
|
|
List<Article> visible = articlePermissionService.filterVisible(all, userId, familyId, vendorType);
|
|
List<Article> visible = articlePermissionService.filterVisible(all, userId, familyId, vendorType);
|
|
|
|
|
|
|
|
|
|
+ enrichTotalDurationSeconds(visible);
|
|
|
|
|
+
|
|
|
return visible.size() > size ? visible.subList(0, size) : visible;
|
|
return visible.size() > size ? visible.subList(0, size) : visible;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -382,6 +386,27 @@ public class ArticleService {
|
|
|
return articleMapper.selectById(id);
|
|
return articleMapper.selectById(id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void enrichTotalDurationSeconds(List<Article> articles) {
|
|
|
|
|
+ if (articles == null || articles.isEmpty()) return;
|
|
|
|
|
+ String ids = articles.stream()
|
|
|
|
|
+ .map(a -> String.valueOf(a.getId()))
|
|
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
|
|
+ List<Map<String, Object>> durationRows = jdbcTemplate.queryForList(
|
|
|
|
|
+ "SELECT article_id, SUM(duration_seconds) AS total_duration " +
|
|
|
|
|
+ "FROM article_reading_records WHERE article_id IN (" + ids + ") GROUP BY article_id");
|
|
|
|
|
+ Map<Long, Integer> durationMap = new HashMap<>();
|
|
|
|
|
+ for (Map<String, Object> row : durationRows) {
|
|
|
|
|
+ Number aid = (Number) row.get("article_id");
|
|
|
|
|
+ Number total = (Number) row.get("total_duration");
|
|
|
|
|
+ if (aid != null && total != null) {
|
|
|
|
|
+ durationMap.put(aid.longValue(), total.intValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Article article : articles) {
|
|
|
|
|
+ article.setTotalDurationSeconds(durationMap.getOrDefault(article.getId(), 0));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void enrichWithCategoryName(List<Article> articles) {
|
|
public void enrichWithCategoryName(List<Article> articles) {
|
|
|
if (articles == null || articles.isEmpty()) return;
|
|
if (articles == null || articles.isEmpty()) return;
|
|
|
}
|
|
}
|