From 920e64bfb1a9724bc8598ffaa37c43872fd12637 Mon Sep 17 00:00:00 2001 From: jacobxu666 Date: Tue, 4 Aug 2026 23:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E6=9D=BF=E4=B8=8E?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=8D=E4=B8=80=E8=87=B4:=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=A8=A1=E6=9D=BF=E5=90=8E=E7=AB=8B=E5=8D=B3=E5=AF=B9?= =?UTF-8?q?=E8=B4=A6=E5=BD=93=E5=A4=A9=E5=BF=AB=E7=85=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除/新增模板后调用 ensureDay 对账当天,孩子端未完成的残留任务 立即同步移除,避免"孩子有任务但任务管理没有" - 已清理历史残留:来源模板已删除的未完成快照 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/app/parent/actions.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/parent/actions.ts b/src/app/parent/actions.ts index 3f1179b..a2510dd 100644 --- a/src/app/parent/actions.ts +++ b/src/app/parent/actions.ts @@ -8,6 +8,7 @@ import { db } from "@/db"; import { activationCodes, sessions, taskInstances, taskTemplates, users } from "@/db/schema"; import { SUBJECT_VALUES } from "@/db/schema"; import { todayStr } from "@/lib/dates"; +import { ensureDay } from "@/lib/tasks"; import { getSessionUser } from "@/lib/auth"; function hashCode(code: string) { @@ -128,21 +129,23 @@ export async function addTemplate(formData: FormData) { requiresPhoto: parsed.data.requiresPhoto, sortOrder: maxRow.maxSort + 1, }); + await ensureDay(parsed.data.childId, todayStr()); revalidatePath("/parent"); } -// 删除模板任务(同样不影响已生成的历史任务) +// 删除模板任务:删除后立即对账当天,孩子端未完成的对应任务会同步移除 export async function deleteTemplate(templateId: number) { const parent = await getSessionUser(); if (!parent || parent.role !== "parent") throw new Error("请先以家长身份登录"); const [row] = await db - .select({ id: taskTemplates.id }) + .select({ id: taskTemplates.id, childUserId: taskTemplates.childUserId }) .from(taskTemplates) .innerJoin(users, eq(users.id, taskTemplates.childUserId)) .where(and(eq(taskTemplates.id, templateId), eq(users.familyId, parent.familyId))) .limit(1); if (!row) throw new Error("任务不存在"); await db.delete(taskTemplates).where(eq(taskTemplates.id, templateId)); + await ensureDay(row.childUserId, todayStr()); revalidatePath("/parent"); }