order-person.entity.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, Index } from 'typeorm';
  2. import type { EmploymentOrder } from './employment-order.entity';
  3. import type { DisabledPerson } from '@d8d/allin-disability-module/entities';
  4. import { WorkStatus } from '@d8d/allin-enums';
  5. @Entity('order_person', { comment: '订单人员关联表' })
  6. @Index(['personId', 'workStatus']) // 人才工作历史查询优化
  7. @Index(['orderId']) // 通过订单查询优化
  8. @Index(['joinDate']) // 近期分配人才查询优化
  9. @Index(['orderId', 'joinDate']) // 订单关联查询优化
  10. @Index(['personId', 'orderId']) // 企业人才查询优化
  11. @Index(['personId', 'joinDate', 'workStatus']) // 优化最新状态查询
  12. export class OrderPerson {
  13. @PrimaryGeneratedColumn({
  14. name: 'op_id',
  15. type: 'int',
  16. unsigned: true,
  17. comment: '关联ID'
  18. })
  19. id!: number;
  20. @Column({
  21. name: 'order_id',
  22. type: 'int',
  23. nullable: false,
  24. comment: '订单ID'
  25. })
  26. orderId!: number;
  27. @Column({
  28. name: 'person_id',
  29. type: 'int',
  30. nullable: false,
  31. comment: '残疾人ID'
  32. })
  33. personId!: number;
  34. @Column({
  35. name: 'join_date',
  36. type: 'date',
  37. nullable: false,
  38. comment: '入职日期'
  39. })
  40. joinDate!: Date;
  41. @Column({
  42. name: 'actual_start_date',
  43. type: 'date',
  44. nullable: true,
  45. comment: '实际入职日期'
  46. })
  47. actualStartDate?: Date;
  48. @Column({
  49. name: 'leave_date',
  50. type: 'date',
  51. nullable: true,
  52. comment: '离职日期'
  53. })
  54. leaveDate?: Date;
  55. @Column({
  56. name: 'work_status',
  57. type: 'enum',
  58. enum: WorkStatus,
  59. default: WorkStatus.NOT_WORKING,
  60. comment: '工作状态:not_working-未就业, pre_working-待就业, working-已就业, resigned-已离职'
  61. })
  62. workStatus!: WorkStatus;
  63. @Column({
  64. name: 'salary_detail',
  65. type: 'decimal',
  66. precision: 10,
  67. scale: 2,
  68. nullable: false,
  69. comment: '个人薪资'
  70. })
  71. salaryDetail!: number;
  72. // 关系定义 - 与订单的关联
  73. @ManyToOne('EmploymentOrder', 'orderPersons', { onDelete: 'CASCADE' })
  74. @JoinColumn({ name: 'order_id' })
  75. order!: EmploymentOrder;
  76. // 与残疾人员的关联(使用字符串语法避免循环依赖)
  77. @ManyToOne('DisabledPerson', { onDelete: 'CASCADE' })
  78. @JoinColumn({ name: 'person_id' })
  79. person!: DisabledPerson;
  80. constructor(partial?: Partial<OrderPerson>) {
  81. Object.assign(this, partial);
  82. }
  83. }