feat: replace tenants with organization management

This commit is contained in:
2026-07-10 21:27:26 +08:00
parent 8ed1682b90
commit 8f0991a51f
49 changed files with 1292 additions and 698 deletions

View File

@@ -9,7 +9,7 @@ import {
Index,
} from 'typeorm';
import { Classroom } from './classroom.entity';
import { Tenant } from './tenant.entity';
import { Organization } from './organization.entity';
@Entity('classroom_rentals')
@Index(['classroomId', 'startDate', 'endDate'])
@@ -24,12 +24,19 @@ export class ClassroomRental {
@JoinColumn({ name: 'classroom_id' })
classroom: Classroom;
@Column({ name: 'tenant_id' })
tenantId: number;
@Column({ name: 'lessor_organization_id', nullable: true })
lessorOrganizationId: number;
@ManyToOne(() => Tenant)
@JoinColumn({ name: 'tenant_id' })
tenant: Tenant;
@ManyToOne(() => Organization)
@JoinColumn({ name: 'lessor_organization_id' })
lessorOrganization: Organization;
@Column({ name: 'lessee_organization_id', nullable: true })
lesseeOrganizationId: number;
@ManyToOne(() => Organization)
@JoinColumn({ name: 'lessee_organization_id' })
lesseeOrganization: Organization;
@Column({ name: 'start_date', type: 'date' })
startDate: string;
@@ -64,5 +71,4 @@ export class ClassroomRental {
@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
}

View File

@@ -12,7 +12,7 @@ export { OperationLog } from './operation-log.entity';
export { Deposit } from './deposit.entity';
export { DepositInstallment } from './deposit-installment.entity';
export { Classroom } from './classroom.entity';
export { Tenant } from './tenant.entity';
export { Organization } from './organization.entity';
export { ClassroomRental } from './classroom-rental.entity';
export { Permission } from './permission.entity';
export { Role } from './role.entity';

View File

@@ -8,7 +8,7 @@ import {
} from 'typeorm';
import { Student } from './student.entity';
import { Room } from './room.entity';
import { Tenant } from './tenant.entity';
import { Organization } from './organization.entity';
import { Bed } from './bed.entity';
import { Locker } from './locker.entity';
@@ -55,15 +55,15 @@ export class Occupancy {
@JoinColumn({ name: 'locker_id' })
locker: Locker;
@Column({ name: 'rental_type', length: 10, default: 'short' })
rentalType: string;
@Column({ name: 'stay_type', length: 10, default: 'short' })
stayType: string;
@Column({ name: 'tenant_id', type: 'integer', nullable: true })
tenantId: number;
@Column({ name: 'responsible_organization_id', type: 'integer', nullable: true })
responsibleOrganizationId: number;
@ManyToOne(() => Tenant, { nullable: true })
@JoinColumn({ name: 'tenant_id' })
tenant: Tenant;
@ManyToOne(() => Organization, { nullable: true })
@JoinColumn({ name: 'responsible_organization_id' })
responsibleOrganization: Organization;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@@ -75,5 +75,4 @@ export class Occupancy {
@ManyToOne(() => Room, (r) => r.occupancies)
@JoinColumn({ name: 'room_id' })
room: Room;
}

View File

@@ -6,21 +6,29 @@ import {
UpdateDateColumn,
} from 'typeorm';
@Entity('tenants')
export class Tenant {
@Entity('organizations')
export class Organization {
@PrimaryGeneratedColumn()
id: number;
@Column({ name: 'public_id', type: 'varchar', length: 36, unique: true })
publicId: string;
@Column({ length: 50, unique: true })
code: string;
@Column({ length: 100 })
name: string;
@Column({ length: 50, nullable: true })
contact: string;
@Column({ name: 'is_host', default: false })
isHost: boolean;
@Column({ name: 'contact_name', length: 50, nullable: true })
contactName: string;
@Column({ length: 30, nullable: true })
phone: string;
// 可视化颜色hex为空时由后端自动分配
@Column({ length: 20, nullable: true })
color: string;
@@ -28,7 +36,7 @@ export class Tenant {
notes: string;
@Column({ type: 'varchar', length: 20, default: 'active' })
status: string; // active / archived
status: 'active' | 'archived';
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;

View File

@@ -12,7 +12,7 @@ import {
import { Occupancy } from './occupancy.entity';
import { PersonalExpense } from './personal-expense.entity';
import { Bill } from './bill.entity';
import { Tenant } from './tenant.entity';
import { Organization } from './organization.entity';
import { User } from './user.entity';
@Entity('students')
@@ -46,9 +46,6 @@ export class Student {
@Column({ type: 'varchar', length: 20, default: 'active' })
status: string;
@Column({ length: 100, nullable: true })
organization: string;
@Column({ length: 50, nullable: true })
supervisor: string;
@@ -68,17 +65,16 @@ export class Student {
@JoinColumn({ name: 'user_id' })
user: User;
@Column({ name: 'tenant_id', type: 'integer', nullable: true })
tenantId: number;
@Column({ name: 'organization_id', type: 'integer', nullable: true })
organizationId: number;
@ManyToOne(() => Tenant, { nullable: true })
@JoinColumn({ name: 'tenant_id' })
tenant: Tenant;
@ManyToOne(() => Organization, { nullable: true })
@JoinColumn({ name: 'organization_id' })
organization: Organization;
@OneToMany(() => PersonalExpense, (e) => e.student)
personalExpenses: PersonalExpense[];
@OneToMany(() => Bill, (b) => b.student)
bills: Bill[];
}