feat: 增加宿舍查寝功能

This commit is contained in:
2026-07-22 10:55:48 +08:00
parent c888dce065
commit 54e283b687
19 changed files with 923 additions and 18 deletions

View File

@@ -9,6 +9,8 @@ export { Bill } from './bill.entity';
export { BillItem } from './bill-item.entity';
export { User } from './user.entity';
export { OperationLog } from './operation-log.entity';
export { RoomInspection } from './room-inspection.entity';
export { RoomInspectionDetail } from './room-inspection-detail.entity';
export { Deposit } from './deposit.entity';
export { DepositInstallment } from './deposit-installment.entity';
export { Classroom, ClassroomStatus } from './classroom.entity';

View File

@@ -0,0 +1,58 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
Unique,
} from 'typeorm';
import { RoomInspection } from './room-inspection.entity';
import { Occupancy } from './occupancy.entity';
import { Student } from './student.entity';
import { Bed } from './bed.entity';
export type RoomInspectionStatus = 'present' | 'absent';
@Entity('room_inspection_details')
@Unique('uq_room_inspection_details_occupancy', ['inspectionId', 'occupancyId'])
export class RoomInspectionDetail {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'inspection_id' })
inspectionId: number;
@ManyToOne(() => RoomInspection, (inspection) => inspection.details, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'inspection_id' })
inspection: RoomInspection;
@Column({ name: 'occupancy_id' })
occupancyId: number;
@ManyToOne(() => Occupancy, { onDelete: 'RESTRICT' })
@JoinColumn({ name: 'occupancy_id' })
occupancy: Occupancy;
@Column({ name: 'student_id' })
studentId: number;
@ManyToOne(() => Student, { onDelete: 'RESTRICT' })
@JoinColumn({ name: 'student_id' })
student: Student;
@Column({ name: 'bed_id', type: 'integer', nullable: true })
bedId: number | null;
@ManyToOne(() => Bed, { nullable: true, onDelete: 'SET NULL' })
@JoinColumn({ name: 'bed_id' })
bed: Bed | null;
@Column({ type: 'varchar', length: 20 })
status: RoomInspectionStatus;
@Column({ name: 'student_name_snapshot', length: 100 })
studentNameSnapshot: string;
@Column({ name: 'bed_number_snapshot', type: 'varchar', length: 20, nullable: true })
bedNumberSnapshot: string | null;
}

View File

@@ -0,0 +1,58 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
Unique,
UpdateDateColumn,
} from 'typeorm';
import { Room } from './room.entity';
import { User } from './user.entity';
import { RoomInspectionDetail } from './room-inspection-detail.entity';
export type RoomInspectionSource = 'manual' | 'automatic';
@Entity('room_inspections')
@Unique('uq_room_inspections_date_room', ['inspectionDate', 'roomId'])
export class RoomInspection {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'inspection_date', type: 'date' })
inspectionDate: string;
@Column({ name: 'room_id' })
roomId: number;
@ManyToOne(() => Room, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'room_id' })
room: Room;
@Column({ name: 'inspector_id', type: 'integer', nullable: true })
inspectorId: number | null;
@ManyToOne(() => User, { nullable: true, onDelete: 'SET NULL' })
@JoinColumn({ name: 'inspector_id' })
inspector: User | null;
@Column({ name: 'inspector_name', length: 50 })
inspectorName: string;
@Column({ type: 'varchar', length: 20, default: 'manual' })
source: RoomInspectionSource;
@Column({ name: 'submitted_at', type: 'datetime' })
submittedAt: Date;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
@OneToMany(() => RoomInspectionDetail, (detail) => detail.inspection)
details: RoomInspectionDetail[];
}