From 04c200027f9dea0dc42f07aa37cadc0294b0c852 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 3 Dec 2024 17:37:54 +0700 Subject: [PATCH] fix posNo --- src/controllers/PermissionOrgController.ts | 22 +++++++------------- src/controllers/ProfileController.ts | 22 +++++++------------- src/controllers/ProfileEmployeeController.ts | 22 +++++++------------- 3 files changed, 21 insertions(+), 45 deletions(-) diff --git a/src/controllers/PermissionOrgController.ts b/src/controllers/PermissionOrgController.ts index 76f28b20..a281dbc7 100644 --- a/src/controllers/PermissionOrgController.ts +++ b/src/controllers/PermissionOrgController.ts @@ -107,21 +107,13 @@ export class PermissionOrgController extends Controller { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { 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 + 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) + END LIKE :keyword `; } const findRevision = await this.orgRevisionRepository.findOne({ diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 7c249dae..f284fb11 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -3758,21 +3758,13 @@ export class ProfileController extends Controller { queryLike = "profile.position LIKE :keyword"; } else if (searchField == "posNo") { 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 + 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) + END LIKE :keyword `; } let nodeCondition = "1=1"; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index bc9a247c..b742dfd3 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1386,21 +1386,13 @@ export class ProfileEmployeeController extends Controller { queryLike = "profileEmployee.position LIKE :keyword"; } else if (searchField == "posNo") { 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 + 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) + END LIKE :keyword `; } let nodeCondition = "1=1";