Procházet zdrojové kódy

fix: 修复残疾人在职状态变更时 order_person.work_status 未同步的问题

- 添加 jobStatus 变化检测,自动同步 order_person.work_status
- jobStatus 0→1: 将待入职人员状态设为 working
- jobStatus 1→0: 将在职人员状态设为 resigned
- 修复户籍省份分布统计数据不准确的问题

Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname před 3 týdny
rodič
revize
3d53cc5666

+ 39 - 0
allin-packages/disability-module/src/services/aggregated.service.ts

@@ -9,6 +9,8 @@ import { DisabledPersonPhone } from '../entities/disabled-person-phone.entity';
 import { File } from '@d8d/file-module';
 import { CreateAggregatedDisabledPersonDto } from '../schemas/disabled-person.schema';
 import { DisabledPersonService } from './disabled-person.service';
+import { OrderPerson } from '@d8d/allin-order-module';
+import { WorkStatus } from '@d8d/allin-enums';
 
 export class AggregatedService {
   private readonly personRepository: Repository<DisabledPerson>;
@@ -19,6 +21,7 @@ export class AggregatedService {
   private readonly guardianPhoneRepository: Repository<DisabledPersonGuardianPhone>;
   private readonly personPhoneRepository: Repository<DisabledPersonPhone>;
   private readonly fileRepository: Repository<File>;
+  private readonly orderPersonRepository: Repository<OrderPerson>;
   private readonly disabledPersonService: DisabledPersonService;
 
   constructor(dataSource: DataSource) {
@@ -30,6 +33,7 @@ export class AggregatedService {
     this.guardianPhoneRepository = dataSource.getRepository(DisabledPersonGuardianPhone);
     this.personPhoneRepository = dataSource.getRepository(DisabledPersonPhone);
     this.fileRepository = dataSource.getRepository(File);
+    this.orderPersonRepository = dataSource.getRepository(OrderPerson);
     this.disabledPersonService = new DisabledPersonService(dataSource);
   }
 
@@ -253,8 +257,43 @@ export class AggregatedService {
         }
       }
 
+      // 检测 jobStatus 变化,同步 order_person.work_status
+      const oldJobStatus = existingPerson.jobStatus;
+      const newJobStatus = personInfo.jobStatus;
+
+      // 保存残疾人基本信息
       Object.assign(existingPerson, personInfo);
       await this.personRepository.save(existingPerson);
+
+      // 同步 order_person.work_status (确保类型一致,转换为数字比较)
+      const oldStatus = Number(oldJobStatus);
+      const newStatus = Number(newJobStatus);
+
+      // 调试日志
+      console.log('[同步检查] jobStatus 变更:', { oldStatus, newStatus, personId, hasJobStatusInUpdate: 'jobStatus' in personInfo });
+
+      if (newJobStatus !== undefined && newStatus !== oldStatus) {
+        console.log('[同步执行] 执行 work_status 同步');
+        // jobStatus 从 0 变为 1:将待入职的 order_person 的 work_status 设为 working
+        if (newStatus === 1 && oldStatus === 0) {
+          console.log('[同步执行] 0 -> 1: setting to WORKING');
+          await this.orderPersonRepository.update(
+            { personId: personId, workStatus: WorkStatus.PRE_WORKING },
+            { workStatus: WorkStatus.WORKING }
+          );
+        }
+        // jobStatus 从 1 变为 0:将所有在职的 order_person 的 work_status 设为 resigned
+        else if (newStatus === 0 && oldStatus === 1) {
+          console.log('[同步执行] 1 -> 0: setting to RESIGNED');
+          const result = await this.orderPersonRepository.update(
+            { personId: personId, workStatus: WorkStatus.WORKING },
+            { workStatus: WorkStatus.RESIGNED }
+          );
+          console.log('[同步执行] 更新结果:', result);
+        }
+      } else {
+        console.log('[同步检查] jobStatus 未变化或未定义');
+      }
     }
 
     // 更新银行卡信息(先删除旧的,再创建新的)