feat(课堂看板): 「这节课」写上是哪位老师布置的,别的老师改题也不换人
Deploy / deploy (push) Canceled after 0s

看板题号后面从「09:56 布置」变成「09:56 徐越 布置」,老师首页「今天的课」同样带上名字。
老师写真名(用户名 lwp0201、little 认不出是谁),没填真名的退回用户名。
「改」不再覆盖 created_by,和布置时间一样认第一次布置的人。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-20 09:56:46 +08:00
1 parent 3fa897bec1
commit df152f505d
5 files changed
+21 -4

No files matched your search

+1
View File
@@ -1431,6 +1431,7 @@ export const classLesson = pgTable(
* 没有它。写入侧在 PUT /classroom/lesson 按 lessonLanguageSchema 校验过 * 没有它。写入侧在 PUT /classroom/lesson 按 lessonLanguageSchema 校验过
*/ */
language: text().$type<LessonLanguage>(), language: text().$type<LessonLanguage>(),
/** 这天第一次布置的老师,别的老师「改」也不换(和 createdAt 一样)。看板上写「HH:mm 谁 布置」 */
createdBy: integer("created_by").notNull(), createdBy: integer("created_by").notNull(),
/** /**
* 这天第一次布置的时刻,之后「改」只动 updatedAt。清掉(删行)再布置算重新开始。 * 这天第一次布置的时刻,之后「改」只动 updatedAt。清掉(删行)再布置算重新开始。
+14 -2
View File
@@ -105,15 +105,21 @@ async function visibleProblems(ids: number[]) {
return new Map(rows.map((row) => [row.id, row])) return new Map(rows.map((row) => [row.id, row]))
} }
/** 老师给这个班今天布置的题(problem.id,按输入顺序)、选的语言和布置时刻;没布置为 null */ /**
* 老师给这个班今天布置的题(problem.id,按输入顺序)、选的语言、布置时刻和布置的老师;
* 没布置为 null。老师写真名:老师之间认的是名字,用户名(lwp0201、little)认不出是谁
*/
async function lessonPlan(className: string, day: string) { async function lessonPlan(className: string, day: string) {
const [row] = await db const [row] = await db
.select({ .select({
problemIds: schema.classLesson.problemIds, problemIds: schema.classLesson.problemIds,
language: schema.classLesson.language, language: schema.classLesson.language,
createdAt: schema.classLesson.createdAt, createdAt: schema.classLesson.createdAt,
createdBy: sql<string>`coalesce(nullif(${schema.userProfile.realName}, ''), ${schema.user.username})`,
}) })
.from(schema.classLesson) .from(schema.classLesson)
.innerJoin(schema.user, eq(schema.user.id, schema.classLesson.createdBy))
.leftJoin(schema.userProfile, eq(schema.userProfile.userId, schema.classLesson.createdBy))
.where(and(eq(schema.classLesson.className, className), eq(schema.classLesson.day, day))) .where(and(eq(schema.classLesson.className, className), eq(schema.classLesson.day, day)))
.limit(1) .limit(1)
return row?.problemIds.length ? row : null return row?.problemIds.length ? row : null
@@ -142,6 +148,7 @@ async function classLessonProblems(className: string, lookbackDays: number) {
day: today, day: today,
language: plan.language ?? null, language: plan.language ?? null,
assignedAt: plan.createdAt, assignedAt: plan.createdAt,
assignedBy: plan.createdBy,
problems: planned.flatMap((id) => { problems: planned.flatMap((id) => {
const problem = problems.get(id) const problem = problems.get(id)
if (!problem) return [] if (!problem) return []
@@ -174,6 +181,7 @@ async function classLessonProblems(className: string, lookbackDays: number) {
// 推断出来的课不知道老师要的是哪种语言,不限 // 推断出来的课不知道老师要的是哪种语言,不限
language: null, language: null,
assignedAt: null, assignedAt: null,
assignedBy: null,
problems: picked.flatMap((row) => { problems: picked.flatMap((row) => {
const problem = problems.get(row.problemId) const problem = problems.get(row.problemId)
return problem return problem
@@ -400,6 +408,7 @@ classroomRoutes.get("/classroom/board", requireTeacher, async (c) => {
source: null, source: null,
language: null, language: null,
assignedAt: null, assignedAt: null,
assignedBy: null,
lastLanguage: null, lastLanguage: null,
problems: [], problems: [],
students: [], students: [],
@@ -603,6 +612,7 @@ classroomRoutes.get("/classroom/board", requireTeacher, async (c) => {
source: lesson.source, source: lesson.source,
language: lesson.language, language: lesson.language,
assignedAt: lesson.assignedAt, assignedAt: lesson.assignedAt,
assignedBy: lesson.assignedBy,
lastLanguage: last?.language ?? null, lastLanguage: last?.language ?? null,
problems: lesson.problems.map((problem) => ({ problems: lesson.problems.map((problem) => ({
problemId: problem.id, problemId: problem.id,
@@ -742,6 +752,7 @@ classroomRoutes.get("/classroom/today", requireTeacher, async (c) => {
className, className,
source: lesson.source, source: lesson.source,
assignedAt: lesson.assignedAt, assignedAt: lesson.assignedAt,
assignedBy: lesson.assignedBy,
problems: lesson.problems.map((problem) => ({ problems: lesson.problems.map((problem) => ({
problemDisplayId: problem.displayId, problemDisplayId: problem.displayId,
title: problem.title, title: problem.title,
@@ -867,7 +878,8 @@ classroomRoutes.put("/classroom/lesson", requireTeacher, async (c) => {
}) })
.onConflictDoUpdate({ .onConflictDoUpdate({
target: [schema.classLesson.className, schema.classLesson.day], target: [schema.classLesson.className, schema.classLesson.day],
set: { problemIds, language, createdBy: user.id, updatedAt: now }, // 「改」不换布置的人,和 createdAt 一样认第一次
set: { problemIds, language, updatedAt: now },
}) })
return success(c, null) return success(c, null)
}) })
+1 -1
View File
@@ -465,7 +465,7 @@ function lastText(student: ClassBoardStudent) {
{{ problem.problemDisplayId }} {{ problem.problemDisplayId }}
</span> </span>
<span v-if="board.assignedAt" class="assigned"> <span v-if="board.assignedAt" class="assigned">
{{ parseTime(board.assignedAt, "HH:mm") }} 布置 {{ parseTime(board.assignedAt, "HH:mm") }} {{ board.assignedBy }} 布置
</span> </span>
<n-button text class="edit" @click="editing = true"> <n-button text class="edit" @click="editing = true">
<template #icon><Icon icon="ph:pencil-simple" /></template> <template #icon><Icon icon="ph:pencil-simple" /></template>
+1 -1
View File
@@ -53,7 +53,7 @@ function stateOf(row: ClassRow) {
function metaOf(row: ClassRow) { function metaOf(row: ClassRow) {
const parts = [ const parts = [
row.source === "teacher" && row.assignedAt row.source === "teacher" && row.assignedAt
? `${parseTime(row.assignedAt, "HH:mm")} 布置了 ${row.problems.length} 道` ? `${parseTime(row.assignedAt, "HH:mm")} ${row.assignedBy} 布置了 ${row.problems.length} 道`
: `做了 ${row.problems.length} 道`, : `做了 ${row.problems.length} 道`,
] ]
if (row.activeCount) parts.push(`${row.activeCount}/${row.rosterCount} 人交过`) if (row.activeCount) parts.push(`${row.activeCount}/${row.rosterCount} 人交过`)
+4
View File
@@ -172,6 +172,8 @@ export const classBoardSchema = z.object({
language: lessonLanguageSchema, language: lessonLanguageSchema,
/** 今天第一次布置的时刻,之后改题不变;推断出来的课为 null */ /** 今天第一次布置的时刻,之后改题不变;推断出来的课为 null */
assignedAt: z.string().nullable(), assignedAt: z.string().nullable(),
/** 第一次布置的老师(真名,没有真名用用户名);推断出来的课为 null */
assignedBy: z.string().nullable(),
/** 这个班最近一次布置选的语言(含今天),给语言下拉当默认值;从没选过为 null */ /** 这个班最近一次布置选的语言(含今天),给语言下拉当默认值;从没选过为 null */
lastLanguage: lessonLanguageSchema, lastLanguage: lessonLanguageSchema,
problems: z.array(classBoardProblemSchema), problems: z.array(classBoardProblemSchema),
@@ -210,6 +212,8 @@ export const classTodaySchema = z.object({
source: z.enum(["teacher", "inferred"]).nullable(), source: z.enum(["teacher", "inferred"]).nullable(),
/** 老师布置的时刻;推断出来的为 null */ /** 老师布置的时刻;推断出来的为 null */
assignedAt: z.string().nullable(), assignedAt: z.string().nullable(),
/** 布置的老师;推断出来的为 null */
assignedBy: z.string().nullable(),
problems: z.array( problems: z.array(
z.object({ z.object({
problemDisplayId: z.string(), problemDisplayId: z.string(),