From 168abb1255a64c868ffa9478a0012850a8f130f9 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 21 May 2026 11:26:29 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20format=20?= =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A7=20posMasterNo=20(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 20 +++++------ src/controllers/ProfileController.ts | 49 ++++++++++++++------------- src/utils/org-formatting.ts | 4 +-- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 7973f794..efcd1497 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2154,11 +2154,11 @@ export class PositionController extends Controller { let checkChildConditions: any = {}; let keywordAsInt: any; let searchShortName = "1=1"; - let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo)`; - let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo)`; - let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo)`; - let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo)`; - let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo)`; + let searchShortName0 = `CONCAT_WS(" ",orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; + let searchShortName1 = `CONCAT_WS(" ",orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; + let searchShortName2 = `CONCAT_WS(" ",orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; + let searchShortName3 = `CONCAT_WS(" ",orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; + let searchShortName4 = `CONCAT_WS(" ",orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let _data = await new permission().PermissionOrgList(request, "SYS_ORG"); if (body.type === 0) { typeCondition = { @@ -2168,7 +2168,7 @@ export class PositionController extends Controller { checkChildConditions = { orgChild1Id: IsNull(), }; - searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; + searchShortName = `CONCAT_WS(" ",orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; } } else if (body.type === 1) { typeCondition = { @@ -2178,7 +2178,7 @@ export class PositionController extends Controller { checkChildConditions = { orgChild2Id: IsNull(), }; - searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; + searchShortName = `CONCAT_WS(" ",orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; } } else if (body.type === 2) { typeCondition = { @@ -2188,7 +2188,7 @@ export class PositionController extends Controller { checkChildConditions = { orgChild3Id: IsNull(), }; - searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; + searchShortName = `CONCAT_WS(" ",orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; } } else if (body.type === 3) { typeCondition = { @@ -2198,13 +2198,13 @@ export class PositionController extends Controller { checkChildConditions = { orgChild4Id: IsNull(), }; - searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; + searchShortName = `CONCAT_WS(" ",orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; } } else if (body.type === 4) { typeCondition = { orgChild4Id: body.id, }; - searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; + searchShortName = `CONCAT_WS(" ",orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; } let findPosition: any; let masterId = new Array(); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 3c514b6b..14dc725f 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -6025,12 +6025,12 @@ export class ProfileController extends Controller { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { queryLike = ` - CASE - WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, " ", current_holders.posMasterNo) - ELSE CONCAT(orgRoot.orgRootShortName, " ", current_holders.posMasterNo) + CASE + WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT_WS(" ", orgChild4.orgChild4ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT_WS(" ", orgChild3.orgChild3ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT_WS(" ", orgChild2.orgChild2ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT_WS(" ", orgChild1.orgChild1ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + ELSE CONCAT_WS(" ", orgRoot.orgRootShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) END LIKE :keyword `; } @@ -6615,12 +6615,12 @@ export class ProfileController extends Controller { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { queryLike = ` - CASE - WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, " ", current_holders.posMasterNo) - ELSE CONCAT(orgRoot.orgRootShortName, " ", current_holders.posMasterNo) + CASE + WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT_WS(" ", orgChild4.orgChild4ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT_WS(" ", orgChild3.orgChild3ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT_WS(" ", orgChild2.orgChild2ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT_WS(" ", orgChild1.orgChild1ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + ELSE CONCAT_WS(" ", orgRoot.orgRootShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) END LIKE :keyword `; } @@ -6803,18 +6803,19 @@ export class ProfileController extends Controller { .filter(Boolean) .join("\n"); + const numPart = holder ? [holder.posMasterNoPrefix, holder.posMasterNo, holder.posMasterNoSuffix].filter((p) => p !== null && p !== undefined && p !== '').join(' ') : ''; const shortName = !holder ? null : holder.orgChild4 != null - ? `${holder.orgChild4.orgChild4ShortName} ${holder.posMasterNo}` + ? `${holder.orgChild4.orgChild4ShortName} ${numPart}` : holder.orgChild3 != null - ? `${holder.orgChild3.orgChild3ShortName} ${holder.posMasterNo}` + ? `${holder.orgChild3.orgChild3ShortName} ${numPart}` : holder.orgChild2 != null - ? `${holder.orgChild2.orgChild2ShortName} ${holder.posMasterNo}` + ? `${holder.orgChild2.orgChild2ShortName} ${numPart}` : holder.orgChild1 != null - ? `${holder.orgChild1.orgChild1ShortName} ${holder.posMasterNo}` + ? `${holder.orgChild1.orgChild1ShortName} ${numPart}` : holder.orgRoot != null - ? `${holder.orgRoot.orgRootShortName} ${holder.posMasterNo}` + ? `${holder.orgRoot.orgRootShortName} ${numPart}` : null; return { @@ -7008,12 +7009,12 @@ export class ProfileController extends Controller { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { queryLike = ` - CASE - WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, " ", current_holders.posMasterNo) - WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, " ", current_holders.posMasterNo) - ELSE CONCAT(orgRoot.orgRootShortName, " ", current_holders.posMasterNo) + CASE + WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT_WS(" ", orgChild4.orgChild4ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT_WS(" ", orgChild3.orgChild3ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT_WS(" ", orgChild2.orgChild2ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT_WS(" ", orgChild1.orgChild1ShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) + ELSE CONCAT_WS(" ", orgRoot.orgRootShortName, current_holders.posMasterNoPrefix, current_holders.posMasterNo, current_holders.posMasterNoSuffix) END LIKE :keyword `; } @@ -7190,7 +7191,7 @@ export class ProfileController extends Controller { .filter(Boolean) .join("\n"); - const numPart = holder ? `${holder.posMasterNoPrefix ?? ''}${holder.posMasterNo ?? ''}${holder.posMasterNoSuffix ?? ''}` : ''; + const numPart = holder ? [holder.posMasterNoPrefix, holder.posMasterNo, holder.posMasterNoSuffix].filter((p) => p !== null && p !== undefined && p !== '').join(' ') : ''; const shortName = !holder ? null diff --git a/src/utils/org-formatting.ts b/src/utils/org-formatting.ts index fd61f33b..eb4b7a9d 100644 --- a/src/utils/org-formatting.ts +++ b/src/utils/org-formatting.ts @@ -101,7 +101,7 @@ export function getOrgFullName(posMaster: PosMaster): string { } /** - * สร้างเลขที่ตำแหน่ง เช่น "กทม. กบ.1234ช" + * สร้างเลขที่ตำแหน่ง เช่น "กทม. กบ. 1234 ช" */ export function getPosMasterNo(posMaster: PosMaster): string { const orgShortName = getOrgShortName(posMaster); @@ -110,5 +110,5 @@ export function getPosMasterNo(posMaster: PosMaster): string { posMaster.posMasterNo, posMaster.posMasterNoSuffix, ].filter((part) => part !== null && part !== undefined); - return `${orgShortName} ${parts.join('')}`; + return `${orgShortName} ${parts.join(' ')}`; }