diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index b941ad13..7705593b 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -695,7 +695,19 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { where: { orgRevisionId: orgRevisionPublish.id, }, - select: ["id", "current_holderId", "ancestorDNA"], + select: [ + "id", + "current_holderId", + "ancestorDNA", + "posMasterNo", + "posMasterNoPrefix", + "posMasterNoSuffix", + "orgRootId", + "orgChild1Id", + "orgChild2Id", + "orgChild3Id", + "orgChild4Id", + ], }); // Task #2160 ดึง posMasterAssign ของ revision เดิม @@ -861,7 +873,21 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { const newHolderId = item?.next_holderId; const isHolderChanged = oldHolderId !== newHolderId; - if (isHolderChanged) { + // เช็คว่า holder เดิม แต่ตำแหน่งเปลี่ยน + const isSameHolder = oldHolderId === newHolderId && oldHolderId != null && newHolderId != null; + const isPositionChanged = + isSameHolder && + oldPm && + (oldPm.posMasterNo !== item.posMasterNo || + oldPm.posMasterNoPrefix !== item.posMasterNoPrefix || + oldPm.posMasterNoSuffix !== item.posMasterNoSuffix || + oldPm.orgRootId !== item.orgRoot?.id || + oldPm.orgChild1Id !== item.orgChild1?.id || + oldPm.orgChild2Id !== item.orgChild2?.id || + oldPm.orgChild3Id !== item.orgChild3?.id || + oldPm.orgChild4Id !== item.orgChild4?.id); + + if (isHolderChanged || isPositionChanged) { const nextHolderProfile = item.next_holderId != null && item.next_holderId !== "" ? profilesMap.get(item.next_holderId)