fix: F12 P2 follow-up — batch imports set departmentId, optimize getDescendantIds, enforce campus root invariant

This commit is contained in:
2026-07-06 01:06:11 +08:00
parent 6b0a21d266
commit 3bcb7d41c0
7 changed files with 36 additions and 11 deletions

View File

@@ -211,7 +211,8 @@ export class ClassroomsController {
supervisor: String(row.getCell(7).value || '') || undefined,
});
});
const result = await this.service.batchImport(rows);
const departmentId = req.headers?.['x-campus-id'] ? parseInt(String(req.headers['x-campus-id']), 10) || undefined : undefined;
const result = await this.service.batchImport(rows, departmentId);
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,

View File

@@ -66,6 +66,7 @@ export class ClassroomsService {
roomType?: string;
courseType?: string;
}[],
departmentId?: number,
) {
let imported = 0;
let skipped = 0;
@@ -74,7 +75,7 @@ export class ClassroomsService {
if (!row.name?.trim()) { skipped++; continue; }
const exists = await this.repo.findOne({ where: { name: row.name.trim() } });
if (exists) { errors.push(`教室 ${row.name} 已存在`); skipped++; continue; }
await this.repo.save(this.repo.create({ ...row, capacity: row.capacity || 30 }));
await this.repo.save(this.repo.create({ ...row, capacity: row.capacity || 30, departmentId: departmentId ?? undefined }));
imported++;
}
return { message: `成功导入 ${imported} 间教室,跳过 ${skipped}`, imported, skipped, errors: errors.length > 0 ? errors : undefined };