Просмотр исходного кода

feat(backend): add article_id and updated_at to article_reading_records

Xiaogang Liao 1 месяц назад
Родитель
Сommit
44af43e57d

+ 20 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -6889,5 +6889,25 @@ private void runMigration100() {
 		ensureColumn("promotion_tier", "team_size_1st", "INT DEFAULT 0 COMMENT '一层团队人数'");
 		ensureColumn("promotion_tier", "team_size_2nd", "INT DEFAULT 0 COMMENT '二层团队人数'");
 		ensureColumn("promotion_tier", "team_size_3rd", "INT DEFAULT 0 COMMENT '三层团队人数'");
+
+		// 迁移105: article_reading_records表添加article_id和updated_at列
+		try {
+			jdbcTemplate.execute("ALTER TABLE article_reading_records ADD COLUMN article_id BIGINT DEFAULT NULL COMMENT '文章ID' AFTER id");
+			log.info("已添加article_id列到article_reading_records表");
+		} catch (Exception e) {
+			// 列已存在,忽略
+		}
+		try {
+			jdbcTemplate.execute("ALTER TABLE article_reading_records ADD COLUMN updated_at DATETIME DEFAULT NULL COMMENT '更新时间' AFTER read_at");
+			log.info("已添加updated_at列到article_reading_records表");
+		} catch (Exception e) {
+			// 列已存在,忽略
+		}
+		try {
+			jdbcTemplate.execute("ALTER TABLE article_reading_records ADD INDEX idx_article_child_date (article_id, child_id, read_at)");
+			log.info("已添加idx_article_child_date索引");
+		} catch (Exception e) {
+			// 索引已存在,忽略
+		}
 	}
 }

+ 4 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/ArticleReadingRecord.java

@@ -19,6 +19,8 @@ public class ArticleReadingRecord implements Serializable {
 
     private Long childId;
 
+    private Long articleId;
+
     private String content;
 
     private Integer durationSeconds;
@@ -28,5 +30,7 @@ public class ArticleReadingRecord implements Serializable {
 
     private Date readAt;
 
+    private Date updatedAt;
+
     private Date createdAt;
 }

+ 17 - 0
cfc-backend/src/main/resources/schema.sql

@@ -3461,3 +3461,20 @@ CREATE TABLE IF NOT EXISTS points_exchange_records (
     INDEX idx_product (product_id),
     INDEX idx_status (status)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='积分兑换记录';
+
+-- 文章阅读记录表
+CREATE TABLE IF NOT EXISTS article_reading_records (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    article_id BIGINT DEFAULT NULL COMMENT '文章ID',
+    user_id BIGINT COMMENT '用户ID',
+    child_id BIGINT NOT NULL COMMENT '孩子ID',
+    content VARCHAR(500) COMMENT '阅读内容摘要',
+    duration_seconds INT DEFAULT 0 COMMENT '阅读时长(秒)',
+    task_id BIGINT DEFAULT NULL COMMENT '关联的任务ID',
+    read_at DATETIME COMMENT '阅读时间',
+    updated_at DATETIME DEFAULT NULL COMMENT '更新时间',
+    created_at DATETIME,
+    INDEX idx_child_id (child_id),
+    INDEX idx_read_at (read_at),
+    INDEX idx_article_child_date (article_id, child_id, read_at)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章阅读记录表';

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-a5cdd0080659a2bd12a931afc2fc05443a56389e
+0efeeb2812dab4e47ef6ca3cee10aa0939069745