Bladeren bron

fix(task-remind): 修复健康方案每日实例不发提醒 + 提醒称呼串号

1) RepeatTaskGenerator: 有 latest_end 的模板实例,deadline 对齐到 latest_end 当天时刻。
   原逻辑取模板 deadline(方案终点23:59),导致 after_timeout 提醒落到次日被候选查询排除、
   before_deadline 白天永不触发 —— 用户12/115 加模板重建后收不到微信提醒的根因。
2) TaskCheckinWebhookReminderTask.buildContent: 昵称按接收人 userId 查 users,
   原用 task.executor_id(family_members.id) 误查同 id 的无关用户(成员75→users.id=75「用户1139」)。
Xiaogang Liao 9 uur geleden
bovenliggende
commit
18211a5460

+ 16 - 4
cfc-backend/src/main/java/com/etotem/cfc/task/RepeatTaskGenerator.java

@@ -392,10 +392,22 @@ if (useNow) {
     newDeadline.setTime(new Date(targetDate.getTime() + dur * 60000L));
 } else {
     newDeadline.setTime(targetDate);
-    Calendar templateTime = Calendar.getInstance();
-    templateTime.setTime(template.getDeadline());
-    newDeadline.set(Calendar.HOUR_OF_DAY, templateTime.get(Calendar.HOUR_OF_DAY));
-    newDeadline.set(Calendar.MINUTE, templateTime.get(Calendar.MINUTE));
+    // 有执行时段(latest_end)的任务:deadline 对齐到 latest_end 当天时刻,
+    // 使打卡提醒(after_timeout/before_deadline 按 deadline 判断时机)能按时触发。
+    // 模板 deadline 常是方案终点(23:59),直接映射会让 after_timeout 提醒落到次日
+    // 被候选查询(deadline < 次日0点)排除、before_deadline 白天永不触发。
+    if (template.getLatestEnd() != null) {
+        Calendar winEnd = Calendar.getInstance(); winEnd.setTime(template.getLatestEnd());
+        newDeadline.set(Calendar.HOUR_OF_DAY, winEnd.get(Calendar.HOUR_OF_DAY));
+        newDeadline.set(Calendar.MINUTE, winEnd.get(Calendar.MINUTE));
+        newDeadline.set(Calendar.SECOND, 59);
+        newDeadline.set(Calendar.MILLISECOND, 0);
+    } else {
+        Calendar templateTime = Calendar.getInstance();
+        templateTime.setTime(template.getDeadline());
+        newDeadline.set(Calendar.HOUR_OF_DAY, templateTime.get(Calendar.HOUR_OF_DAY));
+        newDeadline.set(Calendar.MINUTE, templateTime.get(Calendar.MINUTE));
+    }
 }
 
 newTask.setDeadline(newDeadline.getTime());

+ 6 - 4
cfc-backend/src/main/java/com/etotem/cfc/task/TaskCheckinWebhookReminderTask.java

@@ -149,7 +149,7 @@ public class TaskCheckinWebhookReminderTask {
                         continue;
                     }
 
-                    String content = buildContent(task, reminderPhase, offset, timing);
+                    String content = buildContent(task, userId, reminderPhase, offset, timing);
                     NotificationMessage msg = new NotificationMessage(userId, NOTIFY_TYPE,
                             "任务打卡提醒", content, REF_TYPE, task.getId(), channels);
                     dispatch(msg);
@@ -198,11 +198,13 @@ public class TaskCheckinWebhookReminderTask {
     }
 
     /** 组装提醒文案(before=即将到期 / after=已超时) */
-    private String buildContent(Task task, String phase, int offsetMinutes, String timing) {
+    private String buildContent(Task task, Long userId, String phase, int offsetMinutes, String timing) {
         String name = "您";
         try {
-            if (task.getExecutorId() != null) {
-                User u = userMapper.selectById(task.getExecutorId());
+            // 昵称按接收人 userId 查(task.executor_id 是 family_members.id,
+            // 直接用它查 users 会命中同 id 的无关用户,如成员75误取users.id=75「用户1139」)
+            if (userId != null) {
+                User u = userMapper.selectById(userId);
                 if (u != null && u.getNickname() != null && !u.getNickname().isEmpty()) {
                     name = u.getNickname();
                 }