jiapu hai 2 meses
pai
achega
c3f57a9b8d

+ 7 - 1
cfc-backend/src/main/java/com/etotem/cfc/service/GrowthTaskService.java

@@ -10,6 +10,7 @@ import com.etotem.cfc.mapper.GrowthTaskLogMapper;
 import com.etotem.cfc.mapper.GrowthTaskMapper;
 import com.etotem.cfc.mapper.GrowthTaskMapper;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -106,9 +107,14 @@ item.put("dimension", task.getDimension());
 
 
     /**
     /**
      * Update progress for a task. Auto-marks completed when progress >= targetValue.
      * Update progress for a task. Auto-marks completed when progress >= targetValue.
+     * Uses REQUIRES_NEW so failures never mark the caller transaction rollback-only.
      */
      */
-    @Transactional
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
     public void updateProgress(Long userId, String taskKey, int increment) {
     public void updateProgress(Long userId, String taskKey, int increment) {
+        if (userId == null) {
+            // 未绑定登录账号的家庭成员(如仅建档的孩子)无成长任务进度
+            return;
+        }
         GrowthTask task = growthTaskMapper.selectOne(
         GrowthTask task = growthTaskMapper.selectOne(
                 new LambdaQueryWrapper<GrowthTask>()
                 new LambdaQueryWrapper<GrowthTask>()
                         .eq(GrowthTask::getTaskKey, taskKey)
                         .eq(GrowthTask::getTaskKey, taskKey)

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

@@ -891,7 +891,9 @@ public List<Task> getTodayTasks(Long memberId, String dimensionCode) {
         }
         }
 
 
         try {
         try {
-            growthTaskService.updateProgress(child.getUserId(), "DAILY_TASK", 1);
+            if (child.getUserId() != null) {
+                growthTaskService.updateProgress(child.getUserId(), "DAILY_TASK", 1);
+            }
         } catch (Exception e) {
         } catch (Exception e) {
             log.warn("成长任务进度更新失败: memberId={}, error={}", memberId, e.getMessage());
             log.warn("成长任务进度更新失败: memberId={}, error={}", memberId, e.getMessage());
         }
         }