refactor(rooms): remove dorm gender restrictions

This commit is contained in:
2026-07-13 15:19:09 +08:00
parent aa1ed7db56
commit f98c0ccaa8
12 changed files with 61 additions and 166 deletions

View File

@@ -300,8 +300,7 @@ export class OccupanciesController {
helpWs.addRow(['4. 已存在的学生(按姓名匹配)会自动补充缺失信息(性别、民族等)']);
helpWs.addRow(['5. 已有在住记录的学生会自动跳过,不会重复入住']);
helpWs.addRow(['6. 填了离宿时间的记录会直接标记为已退宿(用于导入历史数据)']);
helpWs.addRow(['7. 性别约束:同一宿舍只能住同性别学生,首位入住者确定宿舍性别']);
helpWs.addRow(['8. 床位号仅做标识参考,不影响入住逻辑']);
helpWs.addRow(['7. 床位号仅做标识参考,不影响入住逻辑']);
helpWs.getRow(1).font = { bold: true, size: 14 };
res.setHeader(
'Content-Type',

View File

@@ -16,7 +16,7 @@ describe('OccupanciesService — responsible organization', () => {
save: jest.fn(async (value) => ({ ...value, id: 10 })),
} as any as Repository<Occupancy>;
const roomRepo = {
findOne: jest.fn().mockResolvedValue({ id: 2, capacity: 4, gender: null }),
findOne: jest.fn().mockResolvedValue({ id: 2, capacity: 4 }),
update: jest.fn(),
} as any as Repository<Room>;
const studentRepo = {

View File

@@ -61,14 +61,8 @@ export class OccupanciesService {
const count = await this.repo.count({ where: { roomId: dto.roomId, checkOutDate: IsNull() } });
if (count >= room.capacity) throw new BadRequestException('宿舍已满');
// 房间级别性别约束
const student = await this.studentRepo.findOne({ where: { id: dto.studentId } });
if (!student) throw new NotFoundException('学生不存在');
if (student.gender && room.gender && student.gender !== room.gender) {
throw new BadRequestException(
`该宿舍当前为${room.gender}生寝室,${student.gender}生无法入住`,
);
}
// 床位校验
if (dto.bedId) {
@@ -107,11 +101,6 @@ export class OccupanciesService {
await this.lockerRepo.update(dto.lockerId, { status: 'occupied' });
}
// 首位入住者确定房间性别
if ((student.gender === '男' || student.gender === '女') && !room.gender) {
await this.roomRepo.update(room.id, { gender: student.gender });
}
// 更新宿舍状态
if (count + 1 >= room.capacity) {
await this.roomRepo.update(room.id, { status: 'full' });
@@ -173,12 +162,6 @@ export class OccupanciesService {
});
if (count >= newRoom.capacity) throw new BadRequestException('目标宿舍已满');
// 换房性别约束检查
const student = await runner.manager.findOne(Student, { where: { id: oldOcc.studentId } });
if (student?.gender && newRoom.gender && student.gender !== newRoom.gender) {
throw new BadRequestException(`目标宿舍为${newRoom.gender}生寝室,无法换入`);
}
// 新床位校验
if (dto.newBedId) {
const newBed = await runner.manager.findOne(Bed, {
@@ -223,11 +206,6 @@ export class OccupanciesService {
await runner.manager.update(Locker, dto.newLockerId, { status: 'occupied' });
}
// 首位入住者确定新房性别
if ((student?.gender === '男' || student?.gender === '女') && !newRoom.gender) {
await runner.manager.update(Room, newRoom.id, { gender: student.gender });
}
if (count + 1 >= newRoom.capacity) {
await runner.manager.update(Room, newRoom.id, { status: 'full' });
}
@@ -472,15 +450,6 @@ export class OccupanciesService {
continue;
}
// 5. 房间级别性别约束
if (student.gender && room.gender && student.gender !== room.gender) {
errors.push(
`${rowNum}行: 宿舍 ${row.roomNumber}${room.gender}生寝室,${row.name}(${student.gender})无法入住,跳过`,
);
skipped++;
continue;
}
// 6. 创建入住记录
const checkInDate = row.checkInDate?.trim() || new Date().toISOString().split('T')[0];
const occData: any = {
@@ -497,16 +466,6 @@ export class OccupanciesService {
}
await this.repo.save(this.repo.create(occData));
// 7. 首位入住者确定房间性别
if (
!row.checkOutDate?.trim() &&
(student.gender === '男' || student.gender === '女') &&
!room.gender
) {
await this.roomRepo.update(room.id, { gender: student.gender });
room.gender = student.gender;
}
// 8. 更新宿舍状态
if (!row.checkOutDate?.trim() && count + 1 >= room.capacity) {
await this.roomRepo.update(room.id, { status: 'full' });