|
|
@@ -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 未变化或未定义');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 更新银行卡信息(先删除旧的,再创建新的)
|