order-person.entity.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, Index } from 'typeorm';
  2. import { EmploymentOrder } from './employment-order.entity';
  3. import { 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. export class OrderPerson {
  9. @PrimaryGeneratedColumn({
  10. name: 'op_id',
  11. type: 'int',
  12. unsigned: true,
  13. comment: '关联ID'
  14. })
  15. id!: number;
  16. @Column({
  17. name: 'order_id',
  18. type: 'int',
  19. nullable: false,
  20. comment: '订单ID'
  21. })
  22. orderId!: number;
  23. @Column({
  24. name: 'person_id',
  25. type: 'int',
  26. nullable: false,
  27. comment: '残疾人ID'
  28. })
  29. personId!: number;
  30. @Column({
  31. name: 'join_date',
  32. type: 'date',
  33. nullable: false,
  34. comment: '入职日期'
  35. })
  36. joinDate!: Date;
  37. @Column({
  38. name: 'actual_start_date',
  39. type: 'date',
  40. nullable: true,
  41. comment: '实际入职日期'
  42. })
  43. actualStartDate?: Date;
  44. @Column({
  45. name: 'leave_date',
  46. type: 'date',
  47. nullable: true,
  48. comment: '离职日期'
  49. })
  50. leaveDate?: Date;
  51. @Column({
  52. name: 'work_status',
  53. type: 'enum',
  54. enum: WorkStatus,
  55. default: WorkStatus.NOT_WORKING,
  56. comment: '工作状态:not_working-未就业, pre_working-待就业, working-已就业, resigned-已离职'
  57. })
  58. workStatus!: WorkStatus;
  59. @Column({
  60. name: 'salary_detail',
  61. type: 'decimal',
  62. precision: 10,
  63. scale: 2,
  64. nullable: false,
  65. comment: '个人薪资'
  66. })
  67. salaryDetail!: number;
  68. // 关系定义 - 与订单的关联
  69. @ManyToOne(() => EmploymentOrder, (order) => order.orderPersons, { onDelete: 'CASCADE' })
  70. @JoinColumn({ name: 'order_id' })
  71. order!: EmploymentOrder;
  72. // 与残疾人员的关联
  73. @ManyToOne(() => DisabledPerson, { onDelete: 'CASCADE' })
  74. @JoinColumn({ name: 'person_id' })
  75. person!: DisabledPerson;
  76. constructor(partial?: Partial<OrderPerson>) {
  77. Object.assign(this, partial);
  78. }
  79. }