|
|
@@ -7960,5 +7960,153 @@ private void runMigration100() {
|
|
|
} catch (Exception e) {
|
|
|
log.warn("创建user_data_permissions表失败(可能已存在): " + e.getMessage());
|
|
|
}
|
|
|
+
|
|
|
+ // 迁移174: family_members 添加饮食相关字段(饮食模块需求)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN is_living_together TINYINT(1) DEFAULT 1 COMMENT '是否同住(0=不同住,不出现在食谱推荐中)'");
|
|
|
+ log.info("已添加is_living_together列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 is_living_together 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN meal_with_breakfast_weekday TINYINT(1) DEFAULT 0 COMMENT '工作日早餐同餐'");
|
|
|
+ log.info("已添加meal_with_breakfast_weekday列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 meal_with_breakfast_weekday 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN meal_with_lunch_weekday TINYINT(1) DEFAULT 0 COMMENT '工作日午餐同餐'");
|
|
|
+ log.info("已添加meal_with_lunch_weekday列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 meal_with_lunch_weekday 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN meal_with_dinner_weekday TINYINT(1) DEFAULT 0 COMMENT '工作日晚餐同餐'");
|
|
|
+ log.info("已添加meal_with_dinner_weekday列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 meal_with_dinner_weekday 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN meal_with_breakfast_weekend TINYINT(1) DEFAULT 0 COMMENT '周末早餐同餐'");
|
|
|
+ log.info("已添加meal_with_breakfast_weekend列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 meal_with_breakfast_weekend 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN meal_with_lunch_weekend TINYINT(1) DEFAULT 0 COMMENT '周末午餐同餐'");
|
|
|
+ log.info("已添加meal_with_lunch_weekend列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 meal_with_lunch_weekend 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("ALTER TABLE family_members ADD COLUMN meal_with_dinner_weekend TINYINT(1) DEFAULT 0 COMMENT '周末晚餐同餐'");
|
|
|
+ log.info("已添加meal_with_dinner_weekend列到family_members表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("family_members 添加 meal_with_dinner_weekend 列失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移175: 创建 diet_preferences 表(饮食偏好调研表)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS diet_preferences (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "family_member_id BIGINT NOT NULL COMMENT '绑定家庭成员', " +
|
|
|
+ "allergies JSON COMMENT '过敏原列表', " +
|
|
|
+ "absolute_avoid JSON COMMENT '绝对忌口列表', " +
|
|
|
+ "religious_diet VARCHAR(50) DEFAULT 'none' COMMENT '宗教饮食', " +
|
|
|
+ "spice_level TINYINT DEFAULT NULL COMMENT '辣度 0-5', " +
|
|
|
+ "flavor_pref JSON COMMENT '口味偏好', " +
|
|
|
+ "cuisine_pref JSON COMMENT '菜系偏好', " +
|
|
|
+ "cooking_methods JSON COMMENT '烹饪方式偏好', " +
|
|
|
+ "health_goals JSON COMMENT '健康目标', " +
|
|
|
+ "goal_source VARCHAR(20) DEFAULT NULL COMMENT 'manual/system_recommend', " +
|
|
|
+ "goal_confirmed TINYINT(1) DEFAULT 0 COMMENT '用户已确认', " +
|
|
|
+ "filled_at TIMESTAMP NULL COMMENT '首次填写时间', " +
|
|
|
+ "updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
+ "UNIQUE KEY uk_member (family_member_id), " +
|
|
|
+ "INDEX idx_updated (updated_at)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='饮食偏好调研表'");
|
|
|
+ log.info("已创建diet_preferences表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建 diet_preferences 表失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移176: 创建 meal_configs 表(共餐配置表)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS meal_configs (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "family_id BIGINT NOT NULL COMMENT '家庭ID', " +
|
|
|
+ "config_date_type VARCHAR(20) NOT NULL COMMENT '工作日/周末/节假日', " +
|
|
|
+ "meal_type VARCHAR(20) NOT NULL COMMENT 'breakfast/lunch/dinner', " +
|
|
|
+ "participant_member_ids JSON NOT NULL COMMENT '参与成员ID列表', " +
|
|
|
+ "notes VARCHAR(255) DEFAULT NULL COMMENT '备注', " +
|
|
|
+ "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
+ "updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
+ "UNIQUE KEY uk_config (family_id, config_date_type, meal_type), " +
|
|
|
+ "INDEX idx_family (family_id)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='共餐配置表'");
|
|
|
+ log.info("已创建meal_configs表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建 meal_configs 表失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移177: 创建 diet_recommendations 表(食谱推荐方案表)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS diet_recommendations (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "family_id BIGINT NOT NULL COMMENT '家庭ID', " +
|
|
|
+ "recommendation_date DATE NOT NULL COMMENT '推荐日期', " +
|
|
|
+ "meal_type VARCHAR(20) NOT NULL COMMENT 'breakfast/lunch/dinner', " +
|
|
|
+ "participant_member_ids JSON COMMENT '参与成员ID列表', " +
|
|
|
+ "menu_json MEDIUMTEXT NOT NULL COMMENT '菜品列表JSON', " +
|
|
|
+ "nutrition_summary JSON COMMENT '营养汇总', " +
|
|
|
+ "status VARCHAR(20) DEFAULT 'pending' COMMENT 'pending/accepted/adjusted/completed/skipped', " +
|
|
|
+ "version INT DEFAULT 1 COMMENT '版本号', " +
|
|
|
+ "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
+ "updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
+ "INDEX idx_family_date (family_id, recommendation_date), " +
|
|
|
+ "INDEX idx_meal (meal_type, recommendation_date)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='食谱推荐方案表'");
|
|
|
+ log.info("已创建diet_recommendations表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建 diet_recommendations 表失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移178: 创建 diet_records 表(饮食记录表)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS diet_records (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "family_id BIGINT NOT NULL COMMENT '家庭ID', " +
|
|
|
+ "member_id BIGINT NOT NULL COMMENT '吃的成员ID', " +
|
|
|
+ "meal_type VARCHAR(20) NOT NULL COMMENT 'breakfast/lunch/dinner/snack', " +
|
|
|
+ "record_date DATE NOT NULL COMMENT '记录日期', " +
|
|
|
+ "record_method VARCHAR(20) DEFAULT NULL COMMENT 'photo/manual/from_recommendation', " +
|
|
|
+ "image_url VARCHAR(500) DEFAULT NULL COMMENT '原图OSS路径', " +
|
|
|
+ "ai_recognized_foods JSON DEFAULT NULL COMMENT 'AI识别结果', " +
|
|
|
+ "user_confirmed_foods JSON NOT NULL COMMENT '用户最终确认食材', " +
|
|
|
+ "notes VARCHAR(500) DEFAULT NULL COMMENT '备注', " +
|
|
|
+ "created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
+ "INDEX idx_member_date (member_id, record_date), " +
|
|
|
+ "INDEX idx_family_date (family_id, record_date)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='饮食记录表'");
|
|
|
+ log.info("已创建diet_records表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建 diet_records 表失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 迁移179: 创建 diet_record_items 表(饮食记录食材明细表)
|
|
|
+ try {
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS diet_record_items (" +
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
+ "record_id BIGINT NOT NULL COMMENT 'diet_records.id', " +
|
|
|
+ "food_name VARCHAR(100) NOT NULL COMMENT '食材名称', " +
|
|
|
+ "food_id BIGINT DEFAULT NULL COMMENT '关联foods表ID', " +
|
|
|
+ "confidence DECIMAL(3,2) DEFAULT NULL COMMENT 'AI置信度0-1', " +
|
|
|
+ "source VARCHAR(20) DEFAULT NULL COMMENT 'ai_recognized/manual/from_recommendation', " +
|
|
|
+ "INDEX idx_record (record_id)" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='饮食记录食材明细表'");
|
|
|
+ log.info("已创建diet_record_items表");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("创建 diet_record_items 表失败(可能已存在): " + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|