Просмотр исходного кода

feat(task): 一次性迁移——growth_task DAILY定义迁入admin_task_templates(旧表只读保留)

E2E Test Bot 2 недель назад
Родитель
Сommit
2295b84455

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

@@ -10455,5 +10455,22 @@ public class DatabaseInitializer implements CommandLineRunner {
         } catch (Exception e) {
             // 列已存在,忽略
         }
+
+        // 迁移297: 统一任务系统数据迁移——growth_task DAILY定义迁入admin_task_templates(仅执行一次,幂等)
+        try {
+            Integer migrated = jdbcTemplate.queryForObject(
+                    "SELECT COUNT(*) FROM sys_config WHERE config_key = 'TASK_UNIFY_GT_MIGRATED'", Integer.class);
+            if (migrated == null || migrated == 0) {
+                // DAILY 类型 → admin_task_templates(title 拼入 [task_key] 前缀,供 updateProgress 匹配)
+                jdbcTemplate.execute("INSERT INTO admin_task_templates (title, description, points, category, need_review, is_active, task_type, frequency, created_at, updated_at) " +
+                        "SELECT CONCAT('[', task_key, ']', title), description, reward_points, '成长', 0, enabled, 'recurring', 'daily', created_at, created_at " +
+                        "FROM growth_task WHERE type = 'DAILY' AND enabled = 1");
+                jdbcTemplate.update("INSERT INTO sys_config (config_key, config_value, description) VALUES ('TASK_UNIFY_GT_MIGRATED', '1', '统一任务系统: growth_task DAILY定义已迁入admin_task_templates')");
+                log.info("迁移297: growth_task DAILY定义已迁入admin_task_templates");
+            }
+        } catch (Exception e) {
+            log.warn("迁移297: growth_task迁移失败或已执行: {}", e.getMessage());
+        }
+        // 说明:growth_task_log 历史进度、onboarding_task 存量数据仅保留在旧表(只读备份),不回填 tasks(历史数据无法1:1映射到新模型)
     }
 }