fix กรณีนั่งทับต้องปั๊มตำแหน่งติดตัวลงรายการประวัติคนครอง (เผยแพร่ใหญ่) #2564
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m4s

This commit is contained in:
harid 2026-06-12 10:51:56 +07:00
parent 1b1a234bfb
commit edb23dd1fe

View file

@ -782,8 +782,9 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
// 2. Batch load profiles ทั้งหมดในครั้งเดียว (แก้ปัญหา N+1 Query)
const profilesMap = new Map<string, Profile>();
if (profileIds.length > 0) {
const profiles = await repoProfile.findBy({
id: In(profileIds),
const profiles = await repoProfile.find({
where: { id: In(profileIds) },
relations: ["posType", "posLevel"],
});
profiles.forEach((p) => profilesMap.set(p.id, p));
}
@ -878,6 +879,18 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
item.orgRoot?.orgRootShortName,
].find((name) => typeof name === "string" && name.trim().length > 0) ?? _null;
// ถ้าเป็นตำแหน่งนั่งทับ (isSit = true) และมีคนครอง ใช้ตำแหน่งจาก profile แทน
let positionName = selectedPosition?.positionName ?? _null;
let posTypeName = selectedPosition?.posType?.posTypeName ?? _null;
let posLevelName = selectedPosition?.posLevel?.posLevelName ?? _null;
let posExecutiveName = selectedPosition?.posExecutive?.posExecutiveName ?? _null;
if (item.isSit && nextHolderProfile) {
positionName = nextHolderProfile.position ?? _null;
posTypeName = nextHolderProfile.posType?.posTypeName ?? _null;
posLevelName = nextHolderProfile.posLevel?.posLevelName ?? _null;
posExecutiveName = nextHolderProfile.posExecutive ?? _null;
}
historyRowsToSave.push({
ancestorDNA: item.ancestorDNA ? item.ancestorDNA : _null,
prefix: nextHolderProfile?.prefix || _null,
@ -887,10 +900,10 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
posMasterNoPrefix: item.posMasterNoPrefix ?? _null,
posMasterNo: item.posMasterNo ?? _null,
posMasterNoSuffix: item.posMasterNoSuffix ?? _null,
position: selectedPosition?.positionName ?? _null,
posType: selectedPosition?.posType?.posTypeName ?? _null,
posLevel: selectedPosition?.posLevel?.posLevelName ?? _null,
posExecutive: selectedPosition?.posExecutive?.posExecutiveName ?? _null,
position: positionName,
posType: posTypeName,
posLevel: posLevelName,
posExecutive: posExecutiveName,
profileId: _null,
rootDnaId: item.orgRoot?.ancestorDNA || _null,
child1DnaId: item.orgChild1?.ancestorDNA || _null,