location.entity.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
  2. import { AreaEntity } from '../areas/area.entity';
  3. import { DeleteStatus, DisabledStatus } from '../../share/types';
  4. @Entity({ name: 'locations' })
  5. export class LocationEntity {
  6. @PrimaryGeneratedColumn({ unsigned: true, comment: '地点ID' })
  7. id!: number;
  8. @Column({ name: 'name', type: 'varchar', length: 255, comment: '地点名称' })
  9. name!: string;
  10. @Column({ name: 'province_id', type: 'int', unsigned: true, comment: '省份ID' })
  11. provinceId!: number;
  12. @Column({ name: 'city_id', type: 'int', unsigned: true, comment: '城市ID' })
  13. cityId!: number;
  14. @Column({ name: 'district_id', type: 'int', unsigned: true, comment: '区县ID' })
  15. districtId!: number;
  16. @Column({ name: 'address', type: 'varchar', length: 500, comment: '详细地址' })
  17. address!: string;
  18. @Column({ name: 'latitude', type: 'decimal', precision: 10, scale: 6, nullable: true, comment: '纬度' })
  19. latitude!: number | null;
  20. @Column({ name: 'longitude', type: 'decimal', precision: 10, scale: 6, nullable: true, comment: '经度' })
  21. longitude!: number | null;
  22. // 关联关系 - 省份
  23. @ManyToOne(() => AreaEntity, { nullable: false })
  24. @JoinColumn({ name: 'province_id', referencedColumnName: 'id' })
  25. province!: AreaEntity;
  26. // 关联关系 - 城市
  27. @ManyToOne(() => AreaEntity, { nullable: false })
  28. @JoinColumn({ name: 'city_id', referencedColumnName: 'id' })
  29. city!: AreaEntity;
  30. // 关联关系 - 区县
  31. @ManyToOne(() => AreaEntity, { nullable: false })
  32. @JoinColumn({ name: 'district_id', referencedColumnName: 'id' })
  33. district!: AreaEntity;
  34. @Column({ name: 'is_disabled', type: 'int', default: DisabledStatus.ENABLED, comment: '是否禁用(0:启用,1:禁用)' })
  35. isDisabled!: DisabledStatus;
  36. @Column({ name: 'is_deleted', type: 'int', default: DeleteStatus.NOT_DELETED, comment: '是否删除(0:未删除,1:已删除)' })
  37. isDeleted!: DeleteStatus;
  38. @Column({ name: 'created_by', type: 'int', nullable: true, comment: '创建人ID' })
  39. createdBy!: number | null;
  40. @Column({ name: 'updated_by', type: 'int', nullable: true, comment: '更新人ID' })
  41. updatedBy!: number | null;
  42. @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  43. createdAt!: Date;
  44. @UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
  45. updatedAt!: Date;
  46. constructor(partial?: Partial<LocationEntity>) {
  47. Object.assign(this, partial);
  48. }
  49. }