|
|
@@ -2940,6 +2940,62 @@ log.info("已添加template_id列到tasks表");
|
|
|
runLateMigrations();
|
|
|
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() {
|