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

@@ -142,7 +142,7 @@ export class ArchiveController {
userId: req.user?.id,
username: req.user?.username,
module: '学生档案',
action: '删除报名记录',
action: '归档报名记录',
targetId: id,
targetType: 'student_enrollment',
ipAddress,
@@ -206,7 +206,7 @@ export class ArchiveController {
userId: req.user?.id,
username: req.user?.username,
module: '学生档案',
action: '删除考试成绩',
action: '归档考试成绩',
targetId: id,
targetType: 'exam_score',
ipAddress,
@@ -270,7 +270,7 @@ export class ArchiveController {
userId: req.user?.id,
username: req.user?.username,
module: '学生档案',
action: '删除学习记录',
action: '归档学习记录',
targetId: id,
targetType: 'learning_record',
ipAddress,
@@ -353,7 +353,7 @@ export class ArchiveController {
userId: req.user?.id,
username: req.user?.username,
module: '学生档案',
action: '删除附件',
action: '归档附件',
targetId: id,
targetType: 'archive_attachment',
ipAddress,

View File

@@ -71,11 +71,11 @@ export class ArchiveService {
attendances,
] = await Promise.all([
this.profileRepo.findOne({ where: { studentId } }),
this.enrollmentRepo.find({ where: { studentId }, order: { createdAt: 'DESC' } }),
this.examScoreRepo.find({ where: { studentId }, order: { examDate: 'DESC' } }),
this.learningRecordRepo.find({ where: { studentId }, order: { recordDate: 'DESC' } }),
this.enrollmentRepo.find({ where: { studentId, status: 'active' }, order: { createdAt: 'DESC' } }),
this.examScoreRepo.find({ where: { studentId, status: 'active' }, order: { examDate: 'DESC' } }),
this.learningRecordRepo.find({ where: { studentId, status: 'active' }, order: { recordDate: 'DESC' } }),
this.resultRepo.findOne({ where: { studentId } }),
this.attachmentRepo.find({ where: { studentId }, order: { createdAt: 'DESC' } }),
this.attachmentRepo.find({ where: { studentId, status: 'active' }, order: { createdAt: 'DESC' } }),
this.attendanceRepo.find({
where: { studentId },
relations: ['schedule', 'class'],
@@ -126,8 +126,9 @@ export class ArchiveService {
async deleteEnrollment(id: number) {
const entity = await this.enrollmentRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('报名记录不存在');
await this.enrollmentRepo.remove(entity);
return { message: '已删除' };
if (entity.status === 'archived') throw new BadRequestException('报名记录已归档');
await this.enrollmentRepo.update(id, { status: 'archived' });
return { message: '已归档' };
}
private async assertEnrollmentBelongsToStudent(studentId: number, enrollmentId?: number) {
@@ -158,8 +159,9 @@ export class ArchiveService {
async deleteExamScore(id: number) {
const entity = await this.examScoreRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('考试成绩不存在');
await this.examScoreRepo.remove(entity);
return { message: '已删除' };
if (entity.status === 'archived') throw new BadRequestException('考试成绩已归档');
await this.examScoreRepo.update(id, { status: 'archived' });
return { message: '已归档' };
}
async addLearningRecord(studentId: number, dto: CreateLearningRecordDto) {
@@ -180,8 +182,9 @@ export class ArchiveService {
async deleteLearningRecord(id: number) {
const entity = await this.learningRecordRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('学习记录不存在');
await this.learningRecordRepo.remove(entity);
return { message: '已删除' };
if (entity.status === 'archived') throw new BadRequestException('学习记录已归档');
await this.learningRecordRepo.update(id, { status: 'archived' });
return { message: '已归档' };
}
async upsertResult(studentId: number, dto: UpsertResultDto) {
@@ -241,13 +244,8 @@ export class ArchiveService {
async deleteAttachment(id: number) {
const entity = await this.attachmentRepo.findOne({ where: { id } });
if (!entity) throw new NotFoundException('附件不存在');
const absPath = this.resolveAttachmentPath(entity.filePath);
if (fs.existsSync(absPath)) {
fs.unlinkSync(absPath);
}
await this.attachmentRepo.remove(entity);
return { message: '已删除' };
if (entity.status === 'archived') throw new BadRequestException('附件已归档');
await this.attachmentRepo.update(id, { status: 'archived' });
return { message: '已归档' };
}
}