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

feat(task): tasks表新增is_daily_progress/target_value字段,source_type扩展(统一任务系统)

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

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

@@ -10346,6 +10346,8 @@ public class DatabaseInitializer implements CommandLineRunner {
         ensureColumn("articles", "sort_order", "INT NOT NULL DEFAULT 0 COMMENT '推荐排序值(越小越靠前)'");
         log.info("已添加 articles.sort_order 列(迁移294)");
 
+        log.info("已添加 articles.sort_order 列(迁移294)");
+
         // 迁移295: task_plan_instances 补齐实体已含但 DB 缺失的审核/确认/激活列(review/activate 写字段报 Unknown column)
         ensureColumn("task_plan_instances", "source", "VARCHAR(20) DEFAULT NULL COMMENT '来源: manual/assessment/template'");
         ensureColumn("task_plan_instances", "source_result_id", "BIGINT DEFAULT NULL COMMENT '关联测评结果ID(source=assessment时)'");
@@ -10425,5 +10427,25 @@ public class DatabaseInitializer implements CommandLineRunner {
         // 3. promotion_tier.rate_percent:生产用旧模型(tier/team_size_1st/2nd/3rd/total_*),实体期望新模型,
         //    表 0 行。PromotionTier 服务广泛使用。候选。
         // 4. promotion_tier_config:实体已废弃,改用 cf_rate_tier(迁移279),保持现状。
+
+        // 迁移298: tasks表新增is_daily_progress/target_value字段 + source_type注释更新(统一任务系统)
+        try {
+            jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN is_daily_progress TINYINT DEFAULT 0 COMMENT '1=每日进度型任务(无deadline,每日重置)' AFTER source_id");
+            log.info("已添加is_daily_progress列到tasks表");
+        } catch (Exception e) {
+            // 列已存在,忽略
+        }
+        try {
+            jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN target_value INT DEFAULT NULL COMMENT '进度目标值(is_daily_progress=1时有效)' AFTER is_daily_progress");
+            log.info("已添加target_value列到tasks表");
+        } catch (Exception e) {
+            // 列已存在,忽略
+        }
+        try {
+            jdbcTemplate.execute("ALTER TABLE tasks MODIFY COLUMN source_type VARCHAR(32) DEFAULT NULL COMMENT '来源类型: self/assigned/plan/health_plan/training_plan/onboarding/ai/template/article/activity/purchase'");
+            log.info("已更新tasks.source_type注释");
+        } catch (Exception e) {
+            // 修改失败,忽略
+        }
     }
 }

+ 6 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/Task.java

@@ -101,6 +101,12 @@ private Date acceptDeadline;
 	    // 来源ID(如文章ID、活动ID)
 	    private Long sourceId;
 
+    /** 1=每日进度型任务(无 deadline,每日重置;原 growth_task DAILY) */
+    private Integer isDailyProgress;
+
+    /** 进度目标值(is_daily_progress=1 时有效;原 growth_task.targetValue) */
+    private Integer targetValue;
+
     /** 1=会员任务(方案/套餐生成, 执行需会员); 0=普通任务(自建可免费执行) */
     private Integer memberOnly;
 

+ 4 - 2
cfc-backend/src/main/resources/schema.sql

@@ -107,8 +107,10 @@ CREATE TABLE IF NOT EXISTS tasks (
     start_required TINYINT DEFAULT 0 COMMENT '1=需先开始再完成(两阶段)',
     start_count INT DEFAULT 0 COMMENT '已开始次数(累计)',
     min_duration_seconds INT DEFAULT 0 COMMENT '最短持续秒数(专注/游戏类,未达标不计完成)',
-    source_type VARCHAR(20) COMMENT '来源类型: manual/self/assigned/plan/health_plan/training_plan/onboarding/ai/template/article/activity/purchase',
-    source_id BIGINT COMMENT '来源ID(如 training_plans.id / task_plan_instances.id)',
+    source_type VARCHAR(32) DEFAULT NULL COMMENT '来源类型: self/assigned/plan/health_plan/training_plan/onboarding/ai/template/article/activity/purchase',
+    source_id BIGINT DEFAULT NULL COMMENT '来源ID(plan_instance_id/template_id/article_id等)',
+    is_daily_progress TINYINT DEFAULT 0 COMMENT '1=每日进度型任务(无deadline,每日重置)',
+    target_value INT DEFAULT NULL COMMENT '进度目标值(is_daily_progress=1时有效)',
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
     updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     INDEX idx_child_id_deadline (child_id, deadline),