|
|
@@ -2965,62 +2965,7 @@ log.info("已添加template_id列到tasks表");
|
|
|
migration102();
|
|
|
seedFullRegionData();
|
|
|
|
|
|
- // 迁移229: 创建 ai_q_scene / ai_q_session / ai_q_profile 表(AI 动态问卷引擎)
|
|
|
- try {
|
|
|
- jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS ai_q_scene (" +
|
|
|
- "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
- "scene_key VARCHAR(50) NOT NULL, " +
|
|
|
- "scene_name VARCHAR(100) NOT NULL, " +
|
|
|
- "description VARCHAR(500), " +
|
|
|
- "opening_prompt TEXT, " +
|
|
|
- "dimensions_json JSON, " +
|
|
|
- "kb_scope VARCHAR(200) DEFAULT 'microbiome', " +
|
|
|
- "max_questions INT DEFAULT 12, " +
|
|
|
- "system_prompt TEXT, " +
|
|
|
- "enabled TINYINT DEFAULT 1, " +
|
|
|
- "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
- "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
- "UNIQUE KEY uk_scene_key (scene_key)" +
|
|
|
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI 动态问卷-场景配置'");
|
|
|
- jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS ai_q_session (" +
|
|
|
- "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
- "scene_id BIGINT NOT NULL, " +
|
|
|
- "user_id BIGINT NOT NULL, " +
|
|
|
- "member_id BIGINT NOT NULL, " +
|
|
|
- "family_id BIGINT, " +
|
|
|
- "status VARCHAR(16) DEFAULT 'running', " +
|
|
|
- "history_json JSON, " +
|
|
|
- "current_question_json JSON, " +
|
|
|
- "question_count INT DEFAULT 0, " +
|
|
|
- "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
- "finished_at DATETIME, " +
|
|
|
- "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
- "INDEX idx_member_status (member_id, status), " +
|
|
|
- "INDEX idx_scene (scene_id)" +
|
|
|
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI 动态问卷-会话'");
|
|
|
- jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS ai_q_profile (" +
|
|
|
- "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
- "session_id BIGINT NOT NULL, " +
|
|
|
- "scene_id BIGINT NOT NULL, " +
|
|
|
- "member_id BIGINT NOT NULL, " +
|
|
|
- "user_profile_json JSON, " +
|
|
|
- "need_profile_json JSON, " +
|
|
|
- "raw_result TEXT, " +
|
|
|
- "kb_used TINYINT DEFAULT 0, " +
|
|
|
- "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
- "UNIQUE KEY uk_session (session_id), " +
|
|
|
- "INDEX idx_member (member_id)" +
|
|
|
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI 动态问卷-画像结果'");
|
|
|
- jdbcTemplate.execute("INSERT IGNORE INTO ai_q_scene (scene_key, scene_name, description, opening_prompt, dimensions_json, kb_scope, max_questions, enabled) " +
|
|
|
- "VALUES ('microbiome', '菌群健康评估', '通过动态问答评估肠道菌群健康状况并生成营养需求画像', " +
|
|
|
- "'我将通过几个问题了解您的肠道健康状况,请如实回答。', " +
|
|
|
- "'{\"user\": [\"肠道菌群状态\", \"饮食习惯\", \"生活方式\"], \"need\": [\"营养需求\", \"菌群调理建议\"]}', " +
|
|
|
- "'microbiome,dan_knowledge', 12, 1)");
|
|
|
- log.info("已创建 ai_q_scene/ai_q_session/ai_q_profile 表并初始化 microbiome 场景");
|
|
|
- } catch (Exception e) {
|
|
|
- // 表已存在,忽略错误
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
private void migrateHealthDimensionsTable() {
|
|
|
try {
|
|
|
@@ -8873,30 +8818,7 @@ private void runMigration100() {
|
|
|
log.warn("插入GROWTH_COACH权益种子数据失败: {}", ex.getMessage());
|
|
|
}
|
|
|
|
|
|
- // 迁移231: 画像驱动推荐 - member_profile_dimension 表
|
|
|
- try {
|
|
|
- jdbcTemplate.execute(
|
|
|
- "CREATE TABLE IF NOT EXISTS member_profile_dimension (" +
|
|
|
- "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
- "member_id BIGINT NOT NULL COMMENT '家庭成员ID', " +
|
|
|
- "session_id BIGINT NOT NULL COMMENT '来源会话ID', " +
|
|
|
- "scene_id BIGINT COMMENT '来源场景ID', " +
|
|
|
- "dimension_code VARCHAR(50) NOT NULL COMMENT '五维编码: body/mind/wisdom/action/wealth', " +
|
|
|
- "score INT NOT NULL COMMENT '得分 0-100', " +
|
|
|
- "description VARCHAR(500) COMMENT '维度描述', " +
|
|
|
- "evidence JSON COMMENT '证据列表', " +
|
|
|
- "profile_type VARCHAR(10) NOT NULL DEFAULT 'user' COMMENT 'user/need', " +
|
|
|
- "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
- "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
- "INDEX idx_member_dim (member_id, dimension_code), " +
|
|
|
- "INDEX idx_member_type (member_id, profile_type), " +
|
|
|
- "INDEX idx_session (session_id)" +
|
|
|
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='成员画像维度得分'"
|
|
|
- );
|
|
|
- log.info("已创建member_profile_dimension表");
|
|
|
- } catch (Exception ex) {
|
|
|
- log.warn("创建member_profile_dimension表失败: {}", ex.getMessage());
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 迁移232: recommendation_logs 追加 recommend_type 字段
|
|
|
ensureColumn("recommendation_logs", "recommend_type", "VARCHAR(20) DEFAULT 'tag' COMMENT '推荐方式: profile/dimension/tag'");
|