|
@@ -8116,5 +8116,74 @@ private void runMigration100() {
|
|
|
|
|
|
|
|
// 迁移181: health_report_drafts 添加备注字段(代上传说明文字)
|
|
// 迁移181: health_report_drafts 添加备注字段(代上传说明文字)
|
|
|
ensureColumn("health_report_drafts", "remark", "VARCHAR(500) DEFAULT NULL COMMENT '备注(如代上传时的说明文字)'");
|
|
ensureColumn("health_report_drafts", "remark", "VARCHAR(500) DEFAULT NULL COMMENT '备注(如代上传时的说明文字)'");
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移182: 创建 family_challenge_participant 表(挑战参与成员,任意成员发起/可选参与)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS family_challenge_participant (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "challenge_id BIGINT NOT NULL COMMENT '挑战ID', " +
|
|
|
|
|
+ "member_id BIGINT NOT NULL COMMENT '家庭成员ID', " +
|
|
|
|
|
+ "status VARCHAR(20) NOT NULL COMMENT 'pending/agreed/rejected', " +
|
|
|
|
|
+ "agreed_at DATETIME NULL COMMENT '同意/拒绝时间', " +
|
|
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "UNIQUE KEY uk_challenge_member (challenge_id, member_id), " +
|
|
|
|
|
+ "INDEX idx_member (member_id)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='家庭挑战参与成员'");
|
|
|
|
|
+ log.info("已创建family_challenge_participant表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建 family_challenge_participant 表失败(可能已存在): " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移183: 创建 family_relationship_scores 表(方向性关系分数,A对B ≠ B对A)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS family_relationship_scores (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "family_id BIGINT NOT NULL COMMENT '家庭ID', " +
|
|
|
|
|
+ "from_member_id BIGINT NOT NULL COMMENT '分数持有方(A对B的行)', " +
|
|
|
|
|
+ "to_member_id BIGINT NOT NULL COMMENT '分数对象方', " +
|
|
|
|
|
+ "trust_score DECIMAL(5,2) DEFAULT 0 COMMENT 'A对B的信任', " +
|
|
|
|
|
+ "intimacy_score DECIMAL(5,2) DEFAULT 0 COMMENT 'A对B的亲近', " +
|
|
|
|
|
+ "communication_score DECIMAL(5,2) DEFAULT 0 COMMENT 'A对B的沟通', " +
|
|
|
|
|
+ "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "UNIQUE KEY uk_from_to (from_member_id, to_member_id), " +
|
|
|
|
|
+ "INDEX idx_family (family_id)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='方向性关系分数'");
|
|
|
|
|
+ log.info("已创建family_relationship_scores表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建 family_relationship_scores 表失败(可能已存在): " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移184: 创建 family_challenge_score_config 表(挑战评分配置,后台可配置)+ 默认数据
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS family_challenge_score_config (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "action VARCHAR(20) NOT NULL COMMENT 'initiate/agree/reject', " +
|
|
|
|
|
+ "score_type VARCHAR(20) NOT NULL COMMENT 'energy/trust/intimacy/communication', " +
|
|
|
|
|
+ "value INT NOT NULL DEFAULT 0 COMMENT '增减值(可正可负,默认±1)', " +
|
|
|
|
|
+ "enabled TINYINT DEFAULT 1, " +
|
|
|
|
|
+ "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
|
|
+ "UNIQUE KEY uk_action_type (action, score_type)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='家庭挑战评分配置'");
|
|
|
|
|
+ jdbcTemplate.execute("INSERT IGNORE INTO family_challenge_score_config (action, score_type, value, enabled) VALUES " +
|
|
|
|
|
+ "('initiate','energy',1,1),('initiate','trust',0,1),('initiate','intimacy',1,1),('initiate','communication',1,1)," +
|
|
|
|
|
+ "('agree','energy',1,1),('agree','trust',1,1),('agree','intimacy',1,1),('agree','communication',1,1)," +
|
|
|
|
|
+ "('reject','energy',-1,1),('reject','trust',-1,1),('reject','intimacy',-1,1),('reject','communication',1,1)");
|
|
|
|
|
+ log.info("已创建family_challenge_score_config表并写入默认配置");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建 family_challenge_score_config 表失败(可能已存在): " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移185: 存量挑战补全 participant 行(全员 agreed,兼容旧数据,不破坏)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("INSERT IGNORE INTO family_challenge_participant (challenge_id, member_id, status, agreed_at) " +
|
|
|
|
|
+ "SELECT fc.id, fm.id, 'agreed', NOW() FROM family_challenge fc " +
|
|
|
|
|
+ "JOIN family_members fm ON fm.family_id = fc.family_id " +
|
|
|
|
|
+ "WHERE NOT EXISTS (SELECT 1 FROM family_challenge_participant fcp WHERE fcp.challenge_id = fc.id)");
|
|
|
|
|
+ log.info("已为存量挑战补全participant行");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("存量挑战补全participant失败(可能已处理): " + e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|