import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, CreateDateColumn, UpdateDateColumn, OneToMany, ManyToOne, JoinColumn } from 'typeorm'; import { Role } from './role.entity'; import { DeleteStatus, DisabledStatus } from '@/share/types'; import { File } from '@/server/modules/files/file.entity'; import { DataScopeType } from '@/server/modules/departments/department.entity'; @Entity({ name: 'users' }) export class UserEntity { @PrimaryGeneratedColumn({ unsigned: true, comment: '用户ID' }) id!: number; @Column({ name: 'username', type: 'varchar', length: 255, unique: true, comment: '用户名' }) username!: string; @Column({ name: 'password', type: 'varchar', length: 255, comment: '密码' }) password!: string; @Column({ name: 'phone', type: 'varchar', length: 255, nullable: true, comment: '手机号' }) phone!: string | null; @Column({ name: 'email', type: 'varchar', length: 255, nullable: true, comment: '邮箱' }) email!: string | null; @Column({ name: 'nickname', type: 'varchar', length: 255, nullable: true, comment: '昵称' }) nickname!: string | null; @Column({ name: 'name', type: 'varchar', length: 255, nullable: true, comment: '真实姓名' }) name!: string | null; @Column({ name: 'avatar', type: 'varchar', length: 255, nullable: true, comment: '头像' }) avatar!: string | null; @Column({ name: 'is_disabled', type: 'int', default: DisabledStatus.ENABLED, comment: '是否禁用(0:启用,1:禁用)' }) isDisabled!: DisabledStatus; @Column({ name: 'is_deleted', type: 'int', default: DeleteStatus.NOT_DELETED, comment: '是否删除(0:未删除,1:已删除)' }) isDeleted!: DeleteStatus; @ManyToMany(() => Role) @JoinTable() roles!: Role[]; @OneToMany(() => File, file => file.uploadUser) uploadFiles!: File[]; @Column({ name: 'default_department_id', type: 'int', unsigned: true, nullable: true, comment: '默认部门ID' }) defaultDepartmentId?: number; @Column({ name: 'data_scope_type', type: 'enum', enum: DataScopeType, default: DataScopeType.PERSONAL, comment: '数据范围类型' }) dataScopeType!: DataScopeType; @CreateDateColumn({ name: 'created_at', type: 'timestamp' }) createdAt!: Date; @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' }) updatedAt!: Date; @Column({ name: 'created_by', type: 'int', nullable: true, comment: '创建用户ID' }) createdBy?: number; @Column({ name: 'updated_by', type: 'int', nullable: true, comment: '更新用户ID' }) updatedBy?: number; constructor(partial?: Partial) { Object.assign(this, partial); } }