fix: 归档删除改为软删除

This commit is contained in:
2026-07-17 14:13:17 +08:00
parent 3131d2e141
commit f7328d670d
49 changed files with 520 additions and 354 deletions

View File

@@ -170,7 +170,7 @@ export class ClassesController {
userId: req.user?.id,
username: req.user?.username,
module: '班级管理',
action: '删除班级',
action: '归档班级',
targetId: +id,
targetType: 'class',
ipAddress,

View File

@@ -300,23 +300,9 @@ export class ClassesService {
return { success: true };
}
/** 物理删除班级(已归档的才能删除) */
/** 归档班级(兼容旧删除入口,不物理删除) */
async remove(id: number) {
const cls = await this.classRepo.findOne({ where: { id } });
if (!cls) throw new NotFoundException('班级不存在');
if (!cls.isArchived) throw new BadRequestException('请先归档再删除');
const sessionCount = await this.attendanceSessionRepo.count({
where: { classId: id },
});
if (sessionCount > 0) {
throw new ConflictException(
`无法删除已产生 ${sessionCount} 个考勤场次的班级。请先取消或停用班级以保护历史考勤数据。`,
);
}
await this.classRepo.remove(cls);
return { success: true };
return this.archive(id);
}
async getStudents(classId: number) {