refactor(grades,diagnostic): 完成成绩和学情诊断模块审计 P1+P2 改进项

P1-1: 抽取 stats-service.ts,将 8 个统计计算纯函数从 data-access 层分离
P1-5: 创建 WidgetBoundary 组件 + 补齐 teacher 路由 loading.tsx/error.tsx (14 文件)
P1-6: 同步架构图文档 004/005,新增 stats-service 与 widget-boundary 节点
P2-1: 补充 a11y ARIA 属性(5 图表 role=img + aria-label,2 表格 caption,3 列表 role=list,3 按钮 aria-label)
P2-3: 修复班级报告 studentId 字段语义错误(schema 改为可空 + 迁移 + 代码适配)
P2-4: 修复 grade_managed scope 返回空数据(改为子查询 classes 表按 gradeId 过滤)
P2-5: 新增 /parent/diagnostic/ 页面(多子女学情诊断聚合 + loading + error)
P2-6: 统一 SearchParams 工具(student/grades 和 management/grade/insights 改用 @/shared/lib/search-params)
This commit is contained in:
SpecialX
2026-06-22 17:07:32 +08:00
parent e997abaf5e
commit 5f3a1a4662
41 changed files with 9043 additions and 381 deletions

View File

@@ -2,7 +2,8 @@ import "server-only"
import { eq, inArray, sql, type SQL } from "drizzle-orm"
import { gradeRecords } from "@/shared/db/schema"
import { db } from "@/shared/db"
import { classes, gradeRecords } from "@/shared/db/schema"
import type { DataScope } from "@/shared/types/permissions"
/**
@@ -39,7 +40,16 @@ export const buildScopeClassFilter = (scope: DataScope): SQL | null => {
? inArray(gradeRecords.classId, scope.classIds)
: sql`1=0`
}
if (scope.type === "grade_managed") return sql`1=0`
if (scope.type === "grade_managed") {
// P2-4 修复grade_managed scope 应返回所管年级的班级成绩记录
// 通过子查询过滤 classId IN (SELECT id FROM classes WHERE grade_id IN (...))
return scope.gradeIds.length > 0
? inArray(
gradeRecords.classId,
db.select({ id: classes.id }).from(classes).where(inArray(classes.gradeId, scope.gradeIds))
)
: sql`1=0`
}
if (scope.type === "class_members") return null
if (scope.type === "children") {
return scope.childrenIds.length > 0