refactor(server): remove Department/UserDepartment entities, CampusScope, and departmentId from all entities

- Delete department.entity.ts, user-department.entity.ts
- Remove Department/UserDepartment from entities/index.ts
- Remove departmentId column from 18 entities (AttendanceRecord, ArchiveAttachment, Bill, ClassSchedule, Classroom, ClassroomRental, Deposit, DepositInstallment, ExamScore, LearningRecord, Occupancy, PersonalExpense, ResultArchive, Room, RoomExpense, Student, StudentEnrollment, StudentProfile, StudentReport)
- Remove departments/ module entirely
- Delete campus-scope.ts, campus-scope.middleware.ts (request-utils.ts kept — it's just IP extraction)
- Simplify common.module.ts to empty module
- Remove CampusScopeMiddleware from app.module.ts
- Remove all CampusScope injections and filter calls across all services
- Remove departmentId from all DTOs and controllers
- Simplify dingtalk/wecom sync to only sync users (no dept table)
- Update seed module to remove department seeding
- Clean frontend compilation
This commit is contained in:
2026-07-09 17:51:32 +08:00
parent b0f7883f33
commit 6029d8e2fd
68 changed files with 220 additions and 1516 deletions

View File

@@ -44,8 +44,6 @@ export class CreateStudentDto {
@IsString()
supervisor?: string;
@IsOptional()
@IsInt()
departmentId?: number;
@IsOptional()
@IsInt()

View File

@@ -290,8 +290,7 @@ export class StudentsController {
}
}
}
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);
const result = await this.service.batchImport(rows);
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,

View File

@@ -39,11 +39,7 @@ export class StudentsService {
}
async create(dto: CreateStudentDto) {
const entity = this.repo.create(dto);
if (dto.departmentId) {
entity.departmentId = dto.departmentId;
}
return this.repo.save(entity);
return this.repo.save(this.repo.create(dto));
}
async update(id: number, dto: UpdateStudentDto) {
@@ -57,7 +53,6 @@ export class StudentsService {
if (student.status === 'archived') {
throw new BadRequestException('该学生已归档');
}
// 软删除:归档而非物理删除,保留历史数据
await this.repo.update(id, { status: 'archived' });
return { message: '已归档(数据已保留,可随时恢复)' };
}
@@ -110,7 +105,6 @@ export class StudentsService {
supervisor?: string;
tenantId?: number;
}[],
departmentId?: number,
) {
let imported = 0;
let skipped = 0;
@@ -136,7 +130,6 @@ export class StudentsService {
organization: row.organization || undefined,
supervisor: row.supervisor || undefined,
tenantId: row.tenantId || undefined,
departmentId: departmentId ?? undefined,
}),
);
imported++;
@@ -152,7 +145,6 @@ export class StudentsService {
const student = await this.repo.findOne({ where: { id: studentId } });
if (!student) throw new NotFoundException('学生不存在');
// Get all class enrollments for this student
const enrollments = await this.classStudentRepo.find({
where: { studentId },
relations: ['class'],
@@ -162,13 +154,11 @@ export class StudentsService {
return { student, enrollments: [] };
}
// For each enrollment, compute attendance stats
const classIds = enrollments.map((e) => e.classId);
const attendanceRecords = await this.attendanceRepo.find({
where: { studentId, classId: In(classIds) },
});
// Group attendance by class
const attendanceByClass = new Map<number, AttendanceRecord[]>();
for (const r of attendanceRecords) {
const list = attendanceByClass.get(r.classId) || [];