From edb23dd1fee9e3b494629c52baa72de3a8176ef6 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 12 Jun 2026 10:51:56 +0700 Subject: [PATCH] =?UTF-8?q?fix=20=E0=B8=81=E0=B8=A3=E0=B8=93=E0=B8=B5?= =?UTF-8?q?=E0=B8=99=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B8=97=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B8=95=E0=B9=89=E0=B8=AD=E0=B8=87=E0=B8=9B=E0=B8=B1=E0=B9=8A?= =?UTF-8?q?=E0=B8=A1=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88?= =?UTF-8?q?=E0=B8=87=E0=B8=95=E0=B8=B4=E0=B8=94=E0=B8=95=E0=B8=B1=E0=B8=A7?= =?UTF-8?q?=E0=B8=A5=E0=B8=87=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=84=E0=B8=99=E0=B8=84=E0=B8=A3=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=20(=E0=B9=80=E0=B8=9C=E0=B8=A2=E0=B9=81=E0=B8=9E=E0=B8=A3?= =?UTF-8?q?=E0=B9=88=E0=B9=83=E0=B8=AB=E0=B8=8D=E0=B9=88)=20#2564?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/rabbitmq.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index a56d4f9f..c3ef8f3f 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -782,8 +782,9 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { // 2. Batch load profiles ทั้งหมดในครั้งเดียว (แก้ปัญหา N+1 Query) const profilesMap = new Map(); 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 { 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 { 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,