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

@@ -182,7 +182,7 @@ export class ClassroomRentalsController {
userId: req.user?.id,
username: req.user?.username,
module: '教室租赁',
action: '删除租赁',
action: '归档租赁',
targetId: +id,
targetType: 'classroom-rental',
ipAddress,
@@ -249,7 +249,7 @@ export class ClassroomRentalsController {
userId: req.user?.id,
username: req.user?.username,
module: '教室租赁',
action: '除合同',
action: '除合同',
targetId: +id,
targetType: 'classroom-rental',
ipAddress,

View File

@@ -326,7 +326,7 @@ export class ClassroomRentalsService {
throw new BadRequestException('仅有效租赁可以取消');
}
await this.repo.update(id, { status: ClassroomRentalStatus.CANCELLED });
await this.scheduleRepo.delete({ rentalId: id, scheduleType: 'RENTAL' });
await this.scheduleRepo.update({ rentalId: id, scheduleType: 'RENTAL' }, { status: 'inactive' });
return this.findOne(id);
}
@@ -353,24 +353,12 @@ export class ClassroomRentalsService {
async remove(id: number) {
const rental = await this.findOne(id);
if (rental.effectiveStatus === ClassroomRentalStatus.ACTIVE) {
throw new BadRequestException('进行中的租赁请先取消或结束');
if (rental.status === ClassroomRentalStatus.CANCELLED) {
return { message: '租赁订单已归档' };
}
// 同步删除对应排课记录
await this.scheduleRepo.delete({ rentalId: id, scheduleType: 'RENTAL' });
// 同时删除合同文件
if (rental.contractPath) {
const full = path.join(this.uploadDir, rental.contractPath);
if (fs.existsSync(full)) {
try {
fs.unlinkSync(full);
} catch {
/* ignore */
}
}
}
await this.repo.delete(id);
return { message: '删除成功' };
await this.repo.update(id, { status: ClassroomRentalStatus.CANCELLED });
await this.scheduleRepo.update({ rentalId: id, scheduleType: 'RENTAL' }, { status: 'inactive' });
return { message: '租赁订单已归档(合同文件已保留)' };
}
private withEffectiveStatus(rental: ClassroomRental) {
@@ -442,7 +430,7 @@ export class ClassroomRentalsService {
const fullPath = path.join(this.uploadDir, filename);
// 路径遍历防护
if (!fullPath.startsWith(this.uploadDir)) throw new BadRequestException('路径非法');
// 删除旧文件
// 替换旧文件
if (rental.contractPath) {
const oldPath = path.join(this.uploadDir, rental.contractPath);
if (fs.existsSync(oldPath)) {
@@ -473,7 +461,7 @@ export class ClassroomRentalsService {
}
}
await this.repo.update(id, { contractPath: null as any, contractOriginalName: null as any });
return { message: '合同已除' };
return { message: '合同已除' };
}
/**