user.entity.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
  2. import { Role } from './role.entity';
  3. import { File } from '@/server/modules/files/file.entity';
  4. import { DeleteStatus, DisabledStatus } from '@/share/types';
  5. @Entity({ name: 'users' })
  6. export class UserEntity {
  7. @PrimaryGeneratedColumn({ unsigned: true, comment: '用户ID' })
  8. id!: number;
  9. @Column({ name: 'username', type: 'varchar', length: 255, unique: true, comment: '用户名' })
  10. username!: string;
  11. @Column({ name: 'password', type: 'varchar', length: 255, comment: '密码' })
  12. password!: string;
  13. @Column({ name: 'phone', type: 'varchar', length: 255, nullable: true, comment: '手机号' })
  14. phone!: string | null;
  15. @Column({ name: 'email', type: 'varchar', length: 255, nullable: true, comment: '邮箱' })
  16. email!: string | null;
  17. @Column({ name: 'nickname', type: 'varchar', length: 255, nullable: true, comment: '昵称' })
  18. nickname!: string | null;
  19. @Column({ name: 'name', type: 'varchar', length: 255, nullable: true, comment: '真实姓名' })
  20. name!: string | null;
  21. @Column({ name: 'avatar_file_id', type: 'int', unsigned: true, nullable: true, comment: '头像文件ID' })
  22. avatarFileId!: number | null;
  23. @ManyToOne(() => File, { nullable: true })
  24. @JoinColumn({ name: 'avatar_file_id', referencedColumnName: 'id' })
  25. avatarFile!: File | null;
  26. @Column({ name: 'is_disabled', type: 'int', default: DisabledStatus.ENABLED, comment: '是否禁用(0:启用,1:禁用)' })
  27. isDisabled!: DisabledStatus;
  28. @Column({ name: 'is_deleted', type: 'int', default: DeleteStatus.NOT_DELETED, comment: '是否删除(0:未删除,1:已删除)' })
  29. isDeleted!: DeleteStatus;
  30. @Column({ name: 'user_type', type: 'varchar', length: 20, default: 'basic', comment: '用户类型: basic, premium' })
  31. userType!: string;
  32. @Column({ name: 'remaining_count', type: 'int', default: 5, comment: '剩余文档处理次数' })
  33. remainingCount!: number;
  34. @Column({ name: 'total_usage', type: 'int', default: 0, comment: '总使用次数' })
  35. totalUsage!: number;
  36. @Column({ name: 'monthly_usage', type: 'int', default: 0, comment: '本月使用次数' })
  37. monthlyUsage!: number;
  38. @Column({ name: 'expire_at', type: 'timestamp', nullable: true, comment: '会员有效期' })
  39. expireAt!: Date | null;
  40. @Column({ name: 'last_used_at', type: 'timestamp', nullable: true, comment: '最后使用时间' })
  41. lastUsedAt!: Date | null;
  42. @ManyToMany(() => Role)
  43. @JoinTable()
  44. roles!: Role[];
  45. @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  46. createdAt!: Date;
  47. @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  48. updatedAt!: Date;
  49. constructor(partial?: Partial<UserEntity>) {
  50. Object.assign(this, partial);
  51. }
  52. }