From 51c6d8f615d1357cf9293ae9143964344c059215 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 25 Dec 2024 01:10:49 +0700 Subject: [PATCH] search probation --- src/controllers/ProfileController.ts | 21 ++- src/controllers/ProfileEmployeeController.ts | 164 +++++++++--------- .../ProfileEmployeeTempController.ts | 10 +- 3 files changed, 99 insertions(+), 96 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index d799681e..a26979ad 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -4622,7 +4622,7 @@ export class ProfileController extends Controller { citizenId: profile.citizenId, posNo: shortNames[index], positionName: positionName, - date: holder.createdAt + date: holder.createdAt, }; }); }) @@ -6728,15 +6728,18 @@ export class ProfileController extends Controller { ) .andWhere( new Brackets((qb) => { - qb.orWhere(`profile.prefix LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) - .orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, { + qb.orWhere( + `CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword and profile.isProbation = ${isProbation}`, + { keyword: `%${body.keyword}%`, - }) - .orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, { - keyword: `%${body.keyword}%`, - }) + }, + ) + // .orWhere(`profile.firstName LIKE :keyword and profile.isProbation = ${isProbation}`, { + // keyword: `%${body.keyword}%`, + // }) + // .orWhere(`profile.lastName LIKE :keyword and profile.isProbation = ${isProbation}`, { + // keyword: `%${body.keyword}%`, + // }) .orWhere(`profile.position LIKE :keyword and profile.isProbation = ${isProbation}`, { keyword: `%${body.keyword}%`, }) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 8c290b3f..60f75640 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1454,14 +1454,9 @@ export class ProfileEmployeeController extends Controller { .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .where( - node && nodeId - ? "current_holders.orgRevisionId = :orgRevisionId" - : "1=1", - { - orgRevisionId: node && nodeId ? findRevision.id : undefined, - } - ) + .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", { + orgRevisionId: node && nodeId ? findRevision.id : undefined, + }) .andWhere( _data.root != undefined && _data.root != null ? _data.root[0] != null @@ -1920,21 +1915,21 @@ export class ProfileEmployeeController extends Controller { // return new HttpSuccess(mapData); // } - /** + /** * API ค้นหาประวัติการครองตำแหน่ง ข้าราชการ * * @summary ค้นหาประวัติการครองตำแหน่ง ข้าราชการ * */ - @Post("search/history/oc") - async searchOC( - @Body() - requestBody: { - posNo?: string; - position?: string; - }, - ) { - let queryLike = ` + @Post("search/history/oc") + async searchOC( + @Body() + requestBody: { + posNo?: string; + position?: string; + }, + ) { + let 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) @@ -1943,67 +1938,67 @@ export class ProfileEmployeeController extends Controller { ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo) END LIKE :keyword `; - - const profiles = await this.profileRepo - .createQueryBuilder("profileEmployee") - .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") - .leftJoinAndSelect("current_holders.positions", "positions") - .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") - .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") - .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") - .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") - .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .where("positions.positionIsSelected = :posIsSelected", { posIsSelected: true }) - .andWhere( - new Brackets((qb) => { - qb.orWhere( - requestBody.posNo != undefined && requestBody.posNo != null && requestBody.posNo != "" - ? queryLike - : "1=1", - { - keyword: `%${requestBody.posNo}%`, - }, - ); - }), - ) - .andWhere( - requestBody.position != null && requestBody.position !== "" - ? "positions.positionName LIKE :positionName" - : "1=1", - { positionName: `${requestBody.position}` }, - ) - .getMany(); - - const mapData = profiles - .map((profile) => { - const shortNames = profile.current_holders.map((holder) => { - const shortName = - holder.orgChild4?.orgChild4ShortName || - holder.orgChild3?.orgChild3ShortName || - holder.orgChild2?.orgChild2ShortName || - holder.orgChild1?.orgChild1ShortName || - holder.orgRoot?.orgRootShortName; - return `${shortName || ""}${holder.posMasterNo || ""}`; - }); - return profile.current_holders.map((holder, index) => { - const position = holder.positions.find((position) => position.posMasterId === holder.id); - const positionName = position ? position.positionName : null; - - return { - id: profile.id, - posMasterId: holder.id, - fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, - citizenId: profile.citizenId, - posNo: shortNames[index], - positionName: positionName, - date: holder.createdAt - }; - }); - }) - .flat(); - - return new HttpSuccess(mapData); - } + + const profiles = await this.profileRepo + .createQueryBuilder("profileEmployee") + .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.positions", "positions") + .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") + .where("positions.positionIsSelected = :posIsSelected", { posIsSelected: true }) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + requestBody.posNo != undefined && requestBody.posNo != null && requestBody.posNo != "" + ? queryLike + : "1=1", + { + keyword: `%${requestBody.posNo}%`, + }, + ); + }), + ) + .andWhere( + requestBody.position != null && requestBody.position !== "" + ? "positions.positionName LIKE :positionName" + : "1=1", + { positionName: `${requestBody.position}` }, + ) + .getMany(); + + const mapData = profiles + .map((profile) => { + const shortNames = profile.current_holders.map((holder) => { + const shortName = + holder.orgChild4?.orgChild4ShortName || + holder.orgChild3?.orgChild3ShortName || + holder.orgChild2?.orgChild2ShortName || + holder.orgChild1?.orgChild1ShortName || + holder.orgRoot?.orgRootShortName; + return `${shortName || ""}${holder.posMasterNo || ""}`; + }); + return profile.current_holders.map((holder, index) => { + const position = holder.positions.find((position) => position.posMasterId === holder.id); + const positionName = position ? position.positionName : null; + + return { + id: profile.id, + posMasterId: holder.id, + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + citizenId: profile.citizenId, + posNo: shortNames[index], + positionName: positionName, + date: holder.createdAt, + }; + }); + }) + .flat(); + + return new HttpSuccess(mapData); + } /** * API ข้อมูลทะเบียนประวัติตาม keycloak @@ -2157,7 +2152,7 @@ export class ProfileEmployeeController extends Controller { node: null, nodeId: null, salary: profile ? profile.amount : null, - amountSpecial: profile ? profile.amountSpecial : null + amountSpecial: profile ? profile.amountSpecial : null, }; return new HttpSuccess(_profile); } @@ -2972,9 +2967,12 @@ export class ProfileEmployeeController extends Controller { ) .andWhere( new Brackets((qb) => { - qb.orWhere("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) + qb.orWhere( + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", + { keyword: `%${body.keyword}%` }, + ) + // .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) + // .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }); }), diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 52bed431..293e1a14 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1867,7 +1867,7 @@ export class ProfileEmployeeTempController extends Controller { : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 .orgChild4Name, salary: profile ? profile.amount : null, - amountSpecial: profile ? profile.amountSpecial : null + amountSpecial: profile ? profile.amountSpecial : null, }; return new HttpSuccess(_profile); } @@ -2472,9 +2472,11 @@ export class ProfileEmployeeTempController extends Controller { .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .where("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) - .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) + .where("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { + keyword: `%${body.keyword}%`, + }) + // .orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` }) + // .orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` }) .orWhere("posLevel.posLevelName LIKE :keyword", { keyword: `%${body.keyword}%` }) .orderBy("profile.citizenId", "ASC")