feat: 为批量归档补充批量恢复
This commit is contained in:
@@ -306,6 +306,30 @@ export class RoomsService {
|
||||
return { message: '已恢复' };
|
||||
}
|
||||
|
||||
async batchRestore(ids: number[]) {
|
||||
const uniqueIds = [...new Set(ids || [])];
|
||||
if (uniqueIds.length === 0) throw new BadRequestException('请选择要恢复的宿舍');
|
||||
if (uniqueIds.some((id) => !Number.isInteger(id) || id <= 0)) {
|
||||
throw new BadRequestException('宿舍 ID 无效');
|
||||
}
|
||||
const rooms = await this.repo.find({ where: { id: In(uniqueIds) } });
|
||||
if (rooms.length !== uniqueIds.length) throw new NotFoundException('部分宿舍不存在');
|
||||
|
||||
const targetIds = rooms.filter((room) => room.status === 'archived').map((room) => room.id);
|
||||
const skipped = rooms.length - targetIds.length;
|
||||
let restored = 0;
|
||||
if (targetIds.length > 0) {
|
||||
const result = await this.repo
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({ status: 'available' })
|
||||
.where('id IN (:...ids)', { ids: targetIds })
|
||||
.execute();
|
||||
restored = result.affected || 0;
|
||||
}
|
||||
return { message: `已批量恢复 ${restored} 间宿舍`, restored, skipped };
|
||||
}
|
||||
|
||||
async getRoomVisual(asOf?: string) {
|
||||
// asOf 为空 = 实时(今天)。带 asOf = 还原该日期结束时的历史入住快照。
|
||||
const isHistorical = !!asOf;
|
||||
|
||||
Reference in New Issue
Block a user