feat: 完善课表档案、课件归档、提醒与客户端更新并发布 1.4.1
- 重写课表档案工作区并合并时间表、课表与完整档案导入导出 - 修复课前/上下课提醒遮罩与通知收回冲突 - 增加课件文件夹分类、教师归档路径和客户端本机归档 - 打通客户端下载/安装/完成状态上报并在管理端展示更新过程 - 修复侧栏折叠裁切、课时多选与上传控件样式 - 统一版本到 1.4.1
This commit is contained in:
1 parent
2612a912ef
commit
6347d1e5aa
59 files changed
+2251
-584
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { importProfile } from './profile-import.service.js';
|
||||
import { exportProfile } from './profile-export.service.js';
|
||||
import { Router } from 'express';
|
||||
import { z } from 'zod';
|
||||
import { prisma } from '../../lib/db.js';
|
||||
@@ -82,6 +83,9 @@ layouts.delete(
|
||||
|
||||
const plans = Router();
|
||||
plans.use(authenticate());
|
||||
plans.get('/profile', validate({ query: z.object({ classId: z.string().min(1) }) }), async (req, res) =>
|
||||
sendOk(res, await exportProfile(getAuthUser(req), validatedQuery<{ classId: string }>(req).classId)),
|
||||
);
|
||||
plans.post(
|
||||
'/import/profile',
|
||||
requirePermission('schedule:write'),
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import { prisma } from '../../lib/db.js';
|
||||
import { assertClassAccess } from '../../lib/access.js';
|
||||
import type { TokenPayload } from '../../lib/jwt.js';
|
||||
|
||||
/** 按时间点外键生成完整档案,空课、停用课程与非上课时间点均保留。 */
|
||||
export async function exportProfile(user: TokenPayload, classId: string) {
|
||||
await assertClassAccess(user, classId);
|
||||
const [cls, layouts, plans, subjects, groups, scheduled, setting] = await Promise.all([
|
||||
prisma.class.findUniqueOrThrow({ where: { id: classId } }),
|
||||
prisma.timeLayout.findMany({
|
||||
where: { OR: [{ classId }, { classId: null }] },
|
||||
include: { points: { orderBy: { position: 'asc' } } },
|
||||
}),
|
||||
prisma.classPlan.findMany({ where: { classId }, include: { entries: true } }),
|
||||
prisma.course.findMany({ where: { classId } }),
|
||||
prisma.classPlanGroup.findMany({ where: { classId } }),
|
||||
prisma.scheduledClassPlan.findMany({ where: { classId } }),
|
||||
prisma.appSetting.findUnique({ where: { key: `schedule.group.${classId}` } }),
|
||||
]);
|
||||
let selection: {
|
||||
selected?: string;
|
||||
temporary?: string;
|
||||
expireTime?: string;
|
||||
temporaryPlan?: string;
|
||||
temporaryPlanDate?: string;
|
||||
} = {};
|
||||
try {
|
||||
selection = JSON.parse(setting?.value || '{}');
|
||||
} catch {
|
||||
/* 使用默认群组 */
|
||||
}
|
||||
const types = ['LESSON', 'BREAK', 'DIVIDER', 'ACTION'];
|
||||
const actions = (value: string) => {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
return {
|
||||
Name: cls.name,
|
||||
Subjects: Object.fromEntries(
|
||||
subjects.map((s) => [s.id, { Name: s.name, Initial: s.initial, IsOutDoor: s.isOutDoor }]),
|
||||
),
|
||||
TimeLayouts: Object.fromEntries(
|
||||
layouts.map((l) => [
|
||||
l.id,
|
||||
{
|
||||
Name: l.name,
|
||||
IsOverlay: l.isOverlay,
|
||||
OverlaySourceId: l.overlaySourceId,
|
||||
Layouts: l.points.map((p) => ({
|
||||
Name: p.name,
|
||||
StartTime: p.startTime,
|
||||
EndTime: p.endTime,
|
||||
TimeType: types.indexOf(p.timeType),
|
||||
IsHideDefault: p.isHideDefault,
|
||||
DefaultClassId: p.defaultClassId,
|
||||
BreakName: p.breakName,
|
||||
ActionSet: actions(p.actionSet),
|
||||
})),
|
||||
},
|
||||
]),
|
||||
),
|
||||
ClassPlans: Object.fromEntries(
|
||||
plans.map((p) => [
|
||||
p.id,
|
||||
{
|
||||
Name: p.name,
|
||||
TimeLayoutId: p.timeLayoutId,
|
||||
AssociatedGroup: p.associatedGroup,
|
||||
TimeRule: {
|
||||
WeekDay: p.weekday,
|
||||
WeekCountDiv: p.weekCountDiv,
|
||||
WeekCountDivTotal: p.weekCountDivTotal,
|
||||
},
|
||||
WeekStart: p.weekStart,
|
||||
WeekEnd: p.weekEnd,
|
||||
IsEnabled: p.isEnabled,
|
||||
IsOverlay: p.isOverlay,
|
||||
OverlaySourceId: p.overlaySourceId,
|
||||
OverlayDate: p.overlayDate,
|
||||
Classes: (layouts.find((l) => l.id === p.timeLayoutId)?.points || [])
|
||||
.filter((point) => point.timeType === 'LESSON')
|
||||
.map((point) => {
|
||||
const e = p.entries.find((entry) => entry.timeLayoutItemId === point.id);
|
||||
return {
|
||||
SubjectId: e?.courseId || '',
|
||||
IsEnabled: e?.isEnabled ?? true,
|
||||
IsChangedClass: e?.isChangedClass ?? false,
|
||||
Location: e?.location || '',
|
||||
};
|
||||
}),
|
||||
},
|
||||
]),
|
||||
),
|
||||
ClassPlanGroups: Object.fromEntries(groups.map((g) => [g.id, { Name: g.name, IsGlobal: g.isGlobal }])),
|
||||
SelectedClassPlanGroupId: selection.selected || groups.find((g) => g.isDefault)?.id || '',
|
||||
TempClassPlanGroupId: selection.temporary || '',
|
||||
IsTempClassPlanGroupEnabled: !!selection.temporary,
|
||||
TempClassPlanGroupExpireTime: selection.expireTime,
|
||||
TempClassPlanId: selection.temporaryPlan,
|
||||
TempClassPlanSetupTime: selection.temporaryPlanDate,
|
||||
OrderedSchedules: Object.fromEntries(scheduled.map((s) => [s.date, { ClassPlanId: s.classPlanId }])),
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { assertCanManageSchedule } from '../../lib/access.js';
|
||||
import { ApiError } from '../../lib/http.js';
|
||||
import type { TokenPayload } from '../../lib/jwt.js';
|
||||
import { notifyScheduleChanged } from './class-plans.service.js';
|
||||
import { getMaxTermWeeks } from '../../lib/term.js';
|
||||
const record = z.record(z.string(), z.unknown());
|
||||
function object(value: unknown): Record<string, unknown> {
|
||||
const parsed = record.safeParse(value);
|
||||
@@ -39,6 +40,7 @@ export async function importProfile(user: TokenPayload, classId: string, payload
|
||||
if (Object.keys(plans).length > 500 || Object.keys(layouts).length > 100)
|
||||
throw ApiError.badRequest('导入课表过多');
|
||||
const cls = await prisma.class.findUniqueOrThrow({ where: { id: classId } });
|
||||
const maxWeeks = await getMaxTermWeeks();
|
||||
const warnings: string[] = [];
|
||||
const stable = (kind: string, id: string) =>
|
||||
`profile-${kind}-${createHash('sha256')
|
||||
@@ -183,6 +185,14 @@ export async function importProfile(user: TokenPayload, classId: string, payload
|
||||
)
|
||||
throw ApiError.badRequest('导入启用规则不合法(支持1–9周轮换)');
|
||||
const previous = await tx.classPlan.findUnique({ where: { id: stable('plan', id) } });
|
||||
const range = z
|
||||
.object({
|
||||
start: z.number().int().min(1).max(maxWeeks),
|
||||
end: z.number().int().min(1).max(maxWeeks),
|
||||
})
|
||||
.refine((r) => r.start <= r.end)
|
||||
.safeParse({ start: p.WeekStart ?? 1, end: Math.min(Number(p.WeekEnd ?? maxWeeks), maxWeeks) });
|
||||
if (!range.success) throw ApiError.badRequest('导入课表生效周次无效');
|
||||
const data = {
|
||||
classId,
|
||||
name: String(p.Name || '导入课表').slice(0, 64),
|
||||
@@ -191,8 +201,11 @@ export async function importProfile(user: TokenPayload, classId: string, payload
|
||||
weekday,
|
||||
weekCountDiv,
|
||||
weekCountDivTotal,
|
||||
weekStart: range.data.start,
|
||||
weekEnd: range.data.end,
|
||||
isEnabled: p.IsEnabled !== false,
|
||||
isOverlay: p.IsOverlay === true,
|
||||
overlayDate: typeof p.OverlayDate === 'string' && isDayKey(p.OverlayDate) ? p.OverlayDate : null,
|
||||
};
|
||||
const plan = await tx.classPlan.upsert({
|
||||
where: { id: stable('plan', id) },
|
||||
|
||||
Reference in new issue
Block a user