feat: 新增备课模块并修复全模块 P0/P1/P2 缺陷
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled

主要变更:

- 新增 lesson-preparation 模块: 备课编辑器、节点编辑、AI 建议、知识点选择、版本历史、作业发布

- 新增 shared 通用组件: charts/question-bank-filters/schedule-list/ui (chip-nav/filter-bar/page-header/stat-card/stat-item)

- 新增 student/admin 端 loading.tsx 与 error.tsx, 优化加载与错误态体验

- 新增 teacher/lesson-plans 页面 (列表/新建/编辑)

- 新增 drizzle 迁移 0002_tiny_lionheart 及 snapshot

- 新增 textbooks/schema.ts 与 exams/utils/normalize-structure.ts

- 修复 Tiptap v3 SSR hydration 崩溃 (rich-text-block immediatelyRender: false)

- 重构多模块 data-access/actions/组件, 修复权限校验与类型规范

- 同步架构文档 004/005 反映新增模块、导出、依赖关系

- 归档 bugs/* 测试报告与 e2e 测试脚本 (admin/parent/student/teacher web_test)
This commit is contained in:
SpecialX
2026-06-22 01:06:16 +08:00
parent d8962aba96
commit 978d9a8309
327 changed files with 34070 additions and 5642 deletions

View File

@@ -2,16 +2,13 @@ import "server-only"
import { cache } from "react"
import { createId } from "@paralleldrive/cuid2"
import { and, asc, desc, eq, inArray, sql, type SQL } from "drizzle-orm"
import { and, desc, eq, inArray, sql, type SQL } from "drizzle-orm"
import { db } from "@/shared/db"
import {
electiveCourses,
grades,
subjects,
users,
} from "@/shared/db/schema"
import { electiveCourses } from "@/shared/db/schema"
import type { DataScope } from "@/shared/types/permissions"
import { getGradeOptions, getSubjectOptions } from "@/modules/school/data-access"
import { getUserNamesByIds } from "@/modules/users/data-access"
import type {
ElectiveCourseWithDetails,
@@ -43,12 +40,13 @@ const buildScopeFilter = (scope: DataScope, userId?: string): SQL | null => {
return sql`1=0`
}
const mapCourseRow = (
r: typeof electiveCourses.$inferSelect & {
teacherName: string | null
subjectName: string | null
gradeName: string | null
}
export type CourseCoreRow = typeof electiveCourses.$inferSelect
export const mapCourseRow = (
r: CourseCoreRow,
teacherNames: Map<string, string | null>,
subjectNames: Map<string, string>,
gradeNames: Map<string, string>
): ElectiveCourseWithDetails => ({
id: r.id,
name: r.name,
@@ -69,12 +67,12 @@ const mapCourseRow = (
credit: String(r.credit),
createdAt: toIsoRequired(r.createdAt),
updatedAt: toIsoRequired(r.updatedAt),
teacherName: r.teacherName,
subjectName: r.subjectName,
gradeName: r.gradeName,
teacherName: r.teacherId ? (teacherNames.get(r.teacherId) ?? null) : null,
subjectName: r.subjectId ? (subjectNames.get(r.subjectId) ?? null) : null,
gradeName: r.gradeId ? (gradeNames.get(r.gradeId) ?? null) : null,
})
const buildCourseSelect = () =>
export const buildCourseSelect = () =>
db
.select({
id: electiveCourses.id,
@@ -96,14 +94,32 @@ const buildCourseSelect = () =>
credit: electiveCourses.credit,
createdAt: electiveCourses.createdAt,
updatedAt: electiveCourses.updatedAt,
teacherName: users.name,
subjectName: subjects.name,
gradeName: grades.name,
})
.from(electiveCourses)
.leftJoin(users, eq(users.id, electiveCourses.teacherId))
.leftJoin(subjects, eq(subjects.id, electiveCourses.subjectId))
.leftJoin(grades, eq(grades.id, electiveCourses.gradeId))
export const resolveCourseDisplayNames = async (rows: CourseCoreRow[]): Promise<{
teacherNames: Map<string, string | null>
subjectNames: Map<string, string>
gradeNames: Map<string, string>
}> => {
const teacherIds = Array.from(new Set(rows.map((r) => r.teacherId).filter((v): v is string => typeof v === "string" && v.length > 0)))
const [userMap, subjects, grades] = await Promise.all([
getUserNamesByIds(teacherIds),
getSubjectOptions(),
getGradeOptions(),
])
const teacherNames = new Map<string, string | null>()
for (const [id, user] of userMap.entries()) {
teacherNames.set(id, user.name)
}
const subjectNames = new Map<string, string>()
for (const s of subjects) subjectNames.set(s.id, s.name)
const gradeNames = new Map<string, string>()
for (const g of grades) gradeNames.set(g.id, g.name)
return { teacherNames, subjectNames, gradeNames }
}
export const getElectiveCourses = cache(
async (
@@ -131,7 +147,9 @@ export const getElectiveCourses = cache(
: query
).orderBy(desc(electiveCourses.createdAt))
return rows.map(mapCourseRow)
if (rows.length === 0) return []
const displayMaps = await resolveCourseDisplayNames(rows)
return rows.map((r) => mapCourseRow(r, displayMaps.teacherNames, displayMaps.subjectNames, displayMaps.gradeNames))
} catch (error) {
console.error("getElectiveCourses failed:", error)
return []
@@ -146,7 +164,8 @@ export const getElectiveCourseById = cache(
.where(eq(electiveCourses.id, id))
.limit(1)
if (!row) return null
return mapCourseRow(row)
const displayMaps = await resolveCourseDisplayNames([row])
return mapCourseRow(row, displayMaps.teacherNames, displayMaps.subjectNames, displayMaps.gradeNames)
} catch (error) {
console.error("getElectiveCourseById failed:", error)
return null
@@ -228,17 +247,4 @@ export async function closeSelection(courseId: string): Promise<void> {
.where(eq(electiveCourses.id, courseId))
}
export async function getSubjectOptions(): Promise<{ id: string; name: string }[]> {
try {
const rows = await db
.select({ id: subjects.id, name: subjects.name })
.from(subjects)
.orderBy(asc(subjects.order), asc(subjects.name))
return rows.map((r) => ({ id: r.id, name: r.name }))
} catch (error) {
console.error("getSubjectOptions failed:", error)
return []
}
}
export type { ElectiveCourseWithDetails }