Parcourir la source

feat(task-source): 认知训练方案任务补设source_type=training_plan可溯源

iwt il y a 2 semaines
Parent
commit
019e5e886a

+ 6 - 0
cfc-backend/src/main/java/com/etotem/cfc/dto/CreateTaskDTO.java

@@ -71,4 +71,10 @@ public class CreateTaskDTO {
 
     // TASK-SYS-248: 最短持续秒数(专注/游戏类,未达标不计完成)
     private Integer minDurationSeconds;
+
+    // 来源类型: self/assigned/plan/health_plan/training_plan/onboarding/ai/template/article/activity/purchase
+    private String sourceType;
+
+    // 来源ID(如 training_plans.id / task_plan_instances.id)
+    private Long sourceId;
 }

+ 3 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/TaskService.java

@@ -287,6 +287,9 @@ task.setReviewByCategory(dto.getReviewByCategory() != null ? dto.getReviewByCate
         task.setStartCount(0);
         task.setMinDurationSeconds(dto.getMinDurationSeconds() != null ? dto.getMinDurationSeconds() : 0);
 
+        task.setSourceType(dto.getSourceType());
+        task.setSourceId(dto.getSourceId());
+
         return task;
     }
 

+ 2 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/TrainingPlanService.java

@@ -147,6 +147,8 @@ public class TrainingPlanService {
 
         for (TrainingPlanItem item : items) {
             com.etotem.cfc.dto.CreateTaskDTO dto = new com.etotem.cfc.dto.CreateTaskDTO();
+            dto.setSourceType("training_plan");
+            dto.setSourceId(planId);
             dto.setTitle(item.getTaskTitle());
             dto.setDescription(item.getTaskDesc());
             dto.setMemberId(plan.getChildId());

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

@@ -104,6 +104,8 @@ 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/training_plan/onboarding/ai/template/article/activity/purchase',
+    source_id BIGINT COMMENT '来源ID(如 training_plans.id / task_plan_instances.id)',
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
     updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     INDEX idx_child_id_deadline (child_id, deadline),