API-INFO-005 P0 | 扩展 LearningSession 字段与 Repository 【status:partial】 #126

Closed
opened 2026-06-07 11:16:03 +08:00 by wangdl · 2 comments
Owner

目标

LearningSession 当前缺少 materialId/clientSessionId,无法被阅读事件聚合。

新增字段

clientSessionId, readingTargetType?, materialId?, knowledgeBaseId?,
mode, status, durationSeconds, focusMinutes,
startedAt, endedAt?, lastEventAt?, metadata?

索引

  • unique(userId, clientSessionId)
  • index(status, lastEventAt)

关键规则

  • durationSeconds 通过 activeSecondsDelta 累加,不用 Date.now() - startedAt

详见设计文档 API-INFO-000。

## 目标 LearningSession 当前缺少 materialId/clientSessionId,无法被阅读事件聚合。 ### 新增字段 ```text clientSessionId, readingTargetType?, materialId?, knowledgeBaseId?, mode, status, durationSeconds, focusMinutes, startedAt, endedAt?, lastEventAt?, metadata? ``` ### 索引 - unique(userId, clientSessionId) - index(status, lastEventAt) ### 关键规则 - durationSeconds 通过 activeSecondsDelta 累加,不用 Date.now() - startedAt 详见设计文档 API-INFO-000。
wangdl added this to the M8:学习信息收集与基础分析闭环 milestone 2026-06-07 11:16:03 +08:00
wangdl changed title from API-INFO-006A P0 | 扩展 LearningSession 支持阅读事件聚合 to API-INFO-005 P0 | 扩展 LearningSession 支持阅读事件 2026-06-07 11:22:14 +08:00
wangdl changed title from API-INFO-005 P0 | 扩展 LearningSession 支持阅读事件 to API-INFO-005 P0 | 扩展 LearningSession 字段与 Repository 【status:partial】 2026-06-07 19:04:11 +08:00
Author
Owner

审查结论:当前 API 项目学习信息收集体系基本为全新建设。可复用:JWT Guard、LearningSession 基础表/CRUD、DailyLearningActivity 基础表、ActivityController 部分接口、LearningRecord schema。其余 ReadingEvent/TemporaryMaterial/Progress/批量上报/Processor/聚合/查询接口/错误码/去重/权限/测试/文档均不存在或仅部分存在。

本 Issue: 基础 CRUD 存在,缺 clientSessionId/materialId/增量时长。end() 用 wall clock 算时长。

标签: audit:reviewed audit:api-info status:partial work:extend-existing

## 审查结论:当前 API 项目学习信息收集体系基本为全新建设。可复用:JWT Guard、LearningSession 基础表/CRUD、DailyLearningActivity 基础表、ActivityController 部分接口、LearningRecord schema。其余 ReadingEvent/TemporaryMaterial/Progress/批量上报/Processor/聚合/查询接口/错误码/去重/权限/测试/文档均不存在或仅部分存在。 **本 Issue**: 基础 CRUD 存在,缺 clientSessionId/materialId/增量时长。end() 用 wall clock 算时长。 **标签**: audit:reviewed audit:api-info status:partial work:extend-existing
Author
Owner

完成报告

交付

1. Prisma SchemaLearningSession 新增 6 个 M8 字段:

model LearningSession {
  // ... 现有字段 (id, userId, knowledgeBaseId, mode, status, startedAt, endedAt, durationSeconds, focusMinutes, metadata) ...

  // ── M8 新增 ──
  clientSessionId   String?             // Rust client_session_id
  materialId        String?             // 阅读资料 materialId
  readingTargetType String?  @db.VarChar(32)  // knowledge_source | temporary_file
  totalActiveSeconds Int     @default(0)      // Rust tracker 累计
  lastPosition      Json?               // 最后阅读位置
  lastEventAt       DateTime?           // 最后事件时间

  @@index([clientSessionId])
  @@index([materialId])
}

2. Servicelearning-session.service.ts 新增方法:

upsertFromReadingEvent(data: {
  userId, clientSessionId, materialId, readingTargetType,
  knowledgeBaseId?, eventType, activeSecondsDelta, position?, timestampMs, startedAt
})

字段映射

Rust ReadingSessionV2 API LearningSession
client_session_id clientSessionId
material.material_id materialId
total_active_seconds totalActiveSeconds
last_position lastPosition
started_at_ms startedAt
## 完成报告 ### 交付 **1. Prisma Schema** — `LearningSession` 新增 6 个 M8 字段: ```prisma model LearningSession { // ... 现有字段 (id, userId, knowledgeBaseId, mode, status, startedAt, endedAt, durationSeconds, focusMinutes, metadata) ... // ── M8 新增 ── clientSessionId String? // Rust client_session_id materialId String? // 阅读资料 materialId readingTargetType String? @db.VarChar(32) // knowledge_source | temporary_file totalActiveSeconds Int @default(0) // Rust tracker 累计 lastPosition Json? // 最后阅读位置 lastEventAt DateTime? // 最后事件时间 @@index([clientSessionId]) @@index([materialId]) } ``` **2. Service** — `learning-session.service.ts` 新增方法: ```typescript upsertFromReadingEvent(data: { userId, clientSessionId, materialId, readingTargetType, knowledgeBaseId?, eventType, activeSecondsDelta, position?, timestampMs, startedAt }) ``` **字段映射**: | Rust ReadingSessionV2 | API LearningSession | |---|---| | client_session_id | clientSessionId | | material.material_id | materialId | | total_active_seconds | totalActiveSeconds | | last_position | lastPosition | | started_at_ms | startedAt |
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#126
No description provided.