|
@@ -307,6 +307,35 @@ public class ArticleService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void reportReadingTime(Long articleId, Long userId, Long childId, int durationSeconds) {
|
|
|
|
|
+ if (childId == null) return;
|
|
|
|
|
+
|
|
|
|
|
+ // 查找当日已有记录(同文章+同孩子)
|
|
|
|
|
+ LambdaQueryWrapper<ArticleReadingRecord> wrapper = new LambdaQueryWrapper<ArticleReadingRecord>()
|
|
|
|
|
+ .eq(ArticleReadingRecord::getArticleId, articleId)
|
|
|
|
|
+ .eq(ArticleReadingRecord::getChildId, childId)
|
|
|
|
|
+ .apply("DATE(read_at) = CURDATE()")
|
|
|
|
|
+ .last("LIMIT 1");
|
|
|
|
|
+ ArticleReadingRecord existing = articleReadingRecordMapper.selectOne(wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (existing != null) {
|
|
|
|
|
+ // 累加时长
|
|
|
|
|
+ existing.setDurationSeconds(existing.getDurationSeconds() + durationSeconds);
|
|
|
|
|
+ existing.setUpdatedAt(new Date());
|
|
|
|
|
+ articleReadingRecordMapper.updateById(existing);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 新建记录
|
|
|
|
|
+ ArticleReadingRecord record = new ArticleReadingRecord();
|
|
|
|
|
+ record.setArticleId(articleId);
|
|
|
|
|
+ record.setUserId(userId);
|
|
|
|
|
+ record.setChildId(childId);
|
|
|
|
|
+ record.setDurationSeconds(durationSeconds);
|
|
|
|
|
+ record.setReadAt(new Date());
|
|
|
|
|
+ record.setCreatedAt(new Date());
|
|
|
|
|
+ articleReadingRecordMapper.insert(record);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Article getById(Long id) {
|
|
public Article getById(Long id) {
|
|
|
return articleMapper.selectById(id);
|
|
return articleMapper.selectById(id);
|
|
|
}
|
|
}
|