Browse Source

feat(backend): report_blocks 表迁移(通用报告展示块)

Xiaogang Liao 1 month ago
parent
commit
f2ef9739fa

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

@@ -8569,5 +8569,22 @@ private void runMigration100() {
 		} catch (Exception e) {
 			log.warn("创建survey_records表失败(可能已存在): " + e.getMessage());
 		}
+
+		// 迁移211: 创建 report_blocks 表(通用报告展示块,按报告类型存储 blocks JSON)
+		try {
+			jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS report_blocks (" +
+					"id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
+					"report_type VARCHAR(32) NOT NULL COMMENT 'gut_flora/dan/physical_exam/tongue', " +
+					"report_id BIGINT NOT NULL COMMENT '各类型报告主键ID', " +
+					"blocks JSON NOT NULL COMMENT '块数组 [{type,title,items,extra}]', " +
+					"version INT DEFAULT 1, " +
+					"created_at DATETIME, " +
+					"updated_at DATETIME, " +
+					"UNIQUE KEY uk_report_type_id (report_type, report_id)" +
+					") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='报告通用展示块'");
+			log.info("已创建report_blocks表");
+		} catch (Exception e) {
+			// 表已存在,忽略错误
+		}
 	}
 }

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

@@ -4461,3 +4461,15 @@ CREATE TABLE IF NOT EXISTS survey_records (
     INDEX idx_member (member_id),
     INDEX idx_template (template_id)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='定期调研记录';
+
+-- 报告通用展示块(迁移211)
+CREATE TABLE IF NOT EXISTS report_blocks (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    report_type VARCHAR(32) NOT NULL COMMENT 'gut_flora/dan/physical_exam/tongue',
+    report_id   BIGINT NOT NULL COMMENT '各类型报告主键ID',
+    blocks      JSON NOT NULL COMMENT '块数组 [{type,title,items,extra}]',
+    version     INT DEFAULT 1,
+    created_at  DATETIME,
+    updated_at  DATETIME,
+    UNIQUE KEY uk_report_type_id (report_type, report_id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='报告通用展示块';