fix: 归档删除改为软删除
This commit is contained in:
@@ -166,7 +166,7 @@ export class OccupanciesController {
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '入住管理',
|
||||
action: '删除入住记录',
|
||||
action: '归档入住记录',
|
||||
targetId: +id,
|
||||
targetType: 'occupancy',
|
||||
ipAddress,
|
||||
@@ -184,7 +184,7 @@ export class OccupanciesController {
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '入住管理',
|
||||
action: '批量删除入住记录',
|
||||
action: '批量归档入住记录',
|
||||
detail: `IDs: ${(body.ids || []).join(',')}`,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
|
||||
@@ -39,6 +39,7 @@ export class OccupanciesService {
|
||||
.leftJoinAndSelect('o.room', 'room')
|
||||
.leftJoinAndSelect('o.bed', 'bed')
|
||||
.leftJoinAndSelect('o.locker', 'locker')
|
||||
.where('o.status = :status', { status: 'active' })
|
||||
.orderBy('o.checkInDate', 'DESC');
|
||||
if (query?.roomId) qb.andWhere('o.roomId = :roomId', { roomId: query.roomId });
|
||||
if (query?.studentId) qb.andWhere('o.studentId = :studentId', { studentId: query.studentId });
|
||||
@@ -287,13 +288,14 @@ export class OccupanciesService {
|
||||
async remove(id: number) {
|
||||
const occ = await this.repo.findOne({ where: { id } });
|
||||
if (!occ) throw new NotFoundException('入住记录不存在');
|
||||
if (!occ.checkOutDate) throw new BadRequestException('在住记录不能删除,请先办理退宿');
|
||||
await this.repo.delete(id);
|
||||
return { message: '删除成功' };
|
||||
if (!occ.checkOutDate) throw new BadRequestException('在住记录不能归档,请先办理退宿');
|
||||
if (occ.status === 'archived') throw new BadRequestException('入住记录已归档');
|
||||
await this.repo.update(id, { status: 'archived' });
|
||||
return { message: '已归档' };
|
||||
}
|
||||
|
||||
async batchRemove(ids: number[]) {
|
||||
if (!ids || ids.length === 0) throw new BadRequestException('请选择要删除的记录');
|
||||
if (!ids || ids.length === 0) throw new BadRequestException('请选择要归档的记录');
|
||||
const records = await this.repo.find({ where: { id: In(ids) }, relations: ['student'] });
|
||||
const skipped: string[] = [];
|
||||
const deletableIds: number[] = [];
|
||||
@@ -304,20 +306,21 @@ export class OccupanciesService {
|
||||
deletableIds.push(occ.id);
|
||||
}
|
||||
}
|
||||
let deleted = 0;
|
||||
let archived = 0;
|
||||
if (deletableIds.length > 0) {
|
||||
const result = await this.repo
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.update()
|
||||
.set({ status: 'archived' })
|
||||
.where('id IN (:...ids)', { ids: deletableIds })
|
||||
.execute();
|
||||
deleted = result.affected || 0;
|
||||
archived = result.affected || 0;
|
||||
}
|
||||
const message =
|
||||
skipped.length > 0
|
||||
? `成功删除 ${deleted} 条;${skipped.length} 条在住记录被跳过(${skipped.slice(0, 5).join('、')}${skipped.length > 5 ? '…' : ''}),请先办理退宿`
|
||||
: `批量删除成功,共 ${deleted} 条`;
|
||||
return { message, deleted, skipped: skipped.length };
|
||||
? `成功归档 ${archived} 条;${skipped.length} 条在住记录被跳过(${skipped.slice(0, 5).join('、')}${skipped.length > 5 ? '…' : ''}),请先办理退宿`
|
||||
: `批量归档成功,共 ${archived} 条`;
|
||||
return { message, archived, skipped: skipped.length };
|
||||
}
|
||||
|
||||
async batchCheckOut(dto: {
|
||||
|
||||
Reference in New Issue
Block a user