From bbcd0a5341475ea761ca77d2a9017f6124e0805c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 3 Dec 2024 13:53:03 +0700 Subject: [PATCH] fix search posNo --- src/controllers/PermissionOrgController.ts | 33 +++++----- src/controllers/ProfileController.ts | 66 ++++++++++---------- src/controllers/ProfileEmployeeController.ts | 33 +++++----- 3 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/controllers/PermissionOrgController.ts b/src/controllers/PermissionOrgController.ts index a1fb62c5..76f28b20 100644 --- a/src/controllers/PermissionOrgController.ts +++ b/src/controllers/PermissionOrgController.ts @@ -106,22 +106,23 @@ export class PermissionOrgController extends Controller { } else if (searchField == "position") { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { - queryLike = `CONCAT( - IFNULL(orgChild4.orgChild4ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild3.orgChild3ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild2.orgChild2ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild1.orgChild1ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgRoot.orgRootShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword`; + queryLike = ` + IF(current_holders.orgChild4Id IS NOT NULL, + CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild3Id IS NOT NULL, + CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild2Id IS NOT NULL, + CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NOT NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword + `; } const findRevision = await this.orgRevisionRepository.findOne({ where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index bb1cab52..f377303c 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -3757,22 +3757,23 @@ export class ProfileController extends Controller { } else if (searchField == "position") { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { - queryLike = `CONCAT( - IFNULL(orgChild4.orgChild4ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild3.orgChild3ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild2.orgChild2ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild1.orgChild1ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgRoot.orgRootShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword`; + queryLike = ` + IF(current_holders.orgChild4Id IS NOT NULL, + CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild3Id IS NOT NULL, + CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild2Id IS NOT NULL, + CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NOT NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword + `; } let nodeCondition = "1=1"; let nodeAll = ""; @@ -4116,22 +4117,23 @@ export class ProfileController extends Controller { } else if (searchField == "position") { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { - queryLike = `CONCAT( - IFNULL(orgChild4.orgChild4ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild3.orgChild3ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild2.orgChild2ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild1.orgChild1ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgRoot.orgRootShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword`; + queryLike = ` + IF(current_holders.orgChild4Id IS NOT NULL, + CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild3Id IS NOT NULL, + CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild2Id IS NOT NULL, + CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NOT NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword + `; } let nodeCondition = "1=1"; let nodeAll = ""; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 1ea3919e..bc9a247c 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1385,22 +1385,23 @@ export class ProfileEmployeeController extends Controller { } else if (searchField == "position") { queryLike = "profileEmployee.position LIKE :keyword"; } else if (searchField == "posNo") { - queryLike = `CONCAT( - IFNULL(orgChild4.orgChild4ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild3.orgChild3ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild2.orgChild2ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild1.orgChild1ShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgRoot.orgRootShortName, ''), - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword`; + queryLike = ` + IF(current_holders.orgChild4Id IS NOT NULL, + CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild3Id IS NOT NULL, + CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild2Id IS NOT NULL, + CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NOT NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword OR + IF(current_holders.orgChild1Id IS NULL, + CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo), '' + ) LIKE :keyword + `; } let nodeCondition = "1=1"; let nodeAll = "";