fix script update retire of 2569

This commit is contained in:
Warunee Tamkoo 2025-10-01 13:01:54 +07:00
parent aff6958149
commit 08af004d4a

View file

@ -56,7 +56,6 @@ export class OrganizationController extends Controller {
private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg);
private profileSalaryRepository = AppDataSource.getRepository(ProfileSalary);
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
/**
* API
@ -7939,14 +7938,18 @@ export class OrganizationController extends Controller {
},
});
let check = 0;
await Promise.all(
posMasters.map(async (posMaster) => {
posMaster.current_holderId = null;
await this.posMasterRepository.save(posMaster);
check += 1;
}),
);
return new HttpSuccess();
// จำนวนคนที่ถูกลบออกจากโครงสร้าง
const total = posMasters.length;
return new HttpSuccess({ total, successAmount: check });
}
/**
@ -7962,75 +7965,64 @@ export class OrganizationController extends Controller {
isLeave: true,
leaveType: "RETIRE",
},
relations: [
"posType",
"posLevel",
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
"current_holders.positions",
"current_holders.positions.posExecutive",
],
});
const batchSize = 1000;
for (let i = 0; i < profileLeave.length; i += batchSize) {
const batch = profileLeave.slice(i, i + batchSize);
await Promise.all(
batch.map(async (profile: any) => {
const dest_item = await this.profileSalaryRepository.findOne({
where: { profileId: profile.id },
order: { order: "DESC" },
});
const data: any = {
order: dest_item == null ? 1 : dest_item.order + 1,
amount: null,
positionSalaryAmount: null,
mouthSalaryAmount: null,
profileId: profile.id,
posNo: "-",
positionExecutive: "-",
positionType: "-",
positionLevel: "-",
amountSpecial: null,
orgRoot: null,
orgChild1: null,
orgChild2: null,
orgChild3: null,
orgChild4: null,
commandYear: new Date().getFullYear() + 543,
commandDateAffect: profile.dateLeave,
commandCode: "16",
commandName: "พ้นจากราชการ",
posNoAbb: "-",
isEntry: false,
positionName: "เกษียณอายุราชการ",
createdUserId: request.user.sub,
createdFullName: request.user.name,
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
remark: "ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. 31 มี.ค. 68", // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง
isGovernment: false,
};
let check: number = 0;
await Promise.all(
profileLeave.map(async (profile: any) => {
const dest_item = await this.profileSalaryRepository.findOne({
where: { profileId: profile.id },
order: { order: "DESC" },
});
const data: any = {
order: dest_item == null ? 1 : dest_item.order + 1,
amount: null,
positionSalaryAmount: null,
mouthSalaryAmount: null,
profileId: profile.id,
posNo: null,
positionExecutive: null,
positionType: null,
positionLevel: null,
amountSpecial: null,
orgRoot: null,
orgChild1: null,
orgChild2: null,
orgChild3: null,
orgChild4: null,
commandYear: new Date().getFullYear() + 543,
commandDateAffect: profile.dateLeave,
commandCode: "16",
commandName: "พ้นจากราชการ",
posNoAbb: null,
isEntry: false,
positionName: "เกษียณอายุราชการ",
createdUserId: request.user.sub,
createdFullName: request.user.name,
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
remark: "ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. 31 มี.ค. 68", // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง
isGovernment: false,
};
delete data.id;
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
data.dateGovernment = profile.dateLeave;
const savedData = await this.profileSalaryRepository.save(data);
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
data.dateGovernment = profile.dateLeave;
await this.profileSalaryRepository.save(data);
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history);
}),
);
}
history.profileSalaryId = savedData.id;
await this.salaryHistoryRepo.save(history);
return new HttpSuccess();
check += 1;
}),
);
// จำนวนคนที่บันทึกลงประวัติตำแหน่ง
const total = profileLeave.length;
// จำนวนคนที่ถูกบันทึกลงประวัติตำแหน่งสำเร็จ
return new HttpSuccess({ total, successAmount: check });
}
/**
@ -8048,23 +8040,27 @@ export class OrganizationController extends Controller {
},
});
const batchSize = 1000;
for (let i = 0; i < profileLeave.length; i += batchSize) {
const batch = profileLeave.slice(i, i + batchSize);
await Promise.all(
batch.map(async (profile) => {
let check: number = 0;
await Promise.all(
profileLeave.map(async (profile) => {
profile.leaveReason = "เกษียณอายุราชการ";
profile.isActive = false;
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.leaveReason = "เกษียณอายุราชการ";
profile.keycloak = "";
profile.isActive = false;
profile.roleKeycloaks = [];
await this.profileRepo.save(profile);
check += 1;
}
}),
);
}
}
return new HttpSuccess();
await this.profileRepo.save(profile);
}),
);
// จำนวนคนที่ถูกแก้ไขเหตุผลการลาออก
const total = profileLeave.length;
return new HttpSuccess({ total, successAmount: check });
}
}