From abf540be98240a816910db6fd797bd6909f3bd86 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 16 Dec 2024 16:00:50 +0700 Subject: [PATCH 1/2] fix issue #866 --- src/entities/Profile.ts | 1 + src/entities/ProfileEmployee.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 3b3818e3..24d9f8ba 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -812,6 +812,7 @@ export type UpdateProfile = { gender?: string | null; relationship?: string | null; bloodGroup?: string | null; + prefixMain?: string | null; }; export type UpdateProfileReqEdit = { rank?: string | null; diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 4706f399..fc18b72b 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -901,6 +901,7 @@ export type UpdateProfileEmployee = { phone?: string | null; salaryLevel?: number | null; employeeClass?: string | null; + prefixMain?: string | null; }; export type UpdateProfileAddressEmployee = { From cbb4862debc209b2b4ad9f6906564ec74e49ec29 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 16 Dec 2024 16:45:53 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=E0=B8=8A=E0=B8=B7=E0=B9=88=E0=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileChangeNameController.ts | 2 + .../ProfileChangeNameEmployeeController.ts | 2 + ...ProfileChangeNameEmployeeTempController.ts | 2 + src/controllers/ProfileEmployeeController.ts | 156 +++++++++++++++++- 4 files changed, 155 insertions(+), 7 deletions(-) diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index 60deb04f..92ce5350 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -111,6 +111,7 @@ export class ProfileChangeNameController extends Controller { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; + profile.prefixMain = profile.rank ?? profile.prefix; await this.profileRepository.save(profile, { data: req }); setLogDataDiff(req, { before, after: profile }); @@ -174,6 +175,7 @@ export class ProfileChangeNameController extends Controller { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; + profile.prefixMain = profile.rank ?? profile.prefix; await this.profileRepository.save(profile, { data: req }); setLogDataDiff(req, { before: before_profile, after: profile }); } diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 6aaa011d..51ff0b8e 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -117,6 +117,7 @@ export class ProfileChangeNameEmployeeController extends Controller { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; + profile.prefixMain = profile.rank ?? profile.prefix; await this.profileEmployeeRepo.save(profile, { data: req }); setLogDataDiff(req, { before, after: profile }); @@ -181,6 +182,7 @@ export class ProfileChangeNameEmployeeController extends Controller { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; + profile.prefixMain = profile.rank ?? profile.prefix; await this.profileEmployeeRepo.save(profile); } diff --git a/src/controllers/ProfileChangeNameEmployeeTempController.ts b/src/controllers/ProfileChangeNameEmployeeTempController.ts index 9b78073e..152279d6 100644 --- a/src/controllers/ProfileChangeNameEmployeeTempController.ts +++ b/src/controllers/ProfileChangeNameEmployeeTempController.ts @@ -109,6 +109,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; + profile.prefixMain = profile.rank ?? profile.prefix; await this.profileEmployeeRepo.save(profile, { data: req }); setLogDataDiff(req, { before, after: profile }); @@ -173,6 +174,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; + profile.prefixMain = profile.rank ?? profile.prefix; await this.profileEmployeeRepo.save(profile); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a22ba4d1..b8c3916d 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2087,12 +2087,35 @@ export class ProfileEmployeeController extends Controller { ) { let findProfile: any; let total: any; + let revision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }); const skip = (page - 1) * pageSize; const take = pageSize; + let 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`; + switch (body.fieldName) { case "citizenId": [findProfile, total] = await this.profileRepo.findAndCount({ - where: { citizenId: Like(`%${body.keyword}%`) }, + where: { + citizenId: Like(`%${body.keyword}%`), + current_holders: { + orgRevisionId: revision?.id, + }, + }, relations: [ "posType", "posLevel", @@ -2109,9 +2132,35 @@ export class ProfileEmployeeController extends Controller { }); break; - case "firstname": + case "fullName": + [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .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("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) + .andWhere( + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", + { keyword: `%${body.keyword}%` }, + ) + .skip(skip) + .take(take) + .getManyAndCount(); + break; + + case "position": [findProfile, total] = await this.profileRepo.findAndCount({ - where: { firstName: Like(`%${body.keyword}%`) }, + where: { + position: Like(`%${body.keyword}%`), + current_holders: { + orgRevisionId: revision?.id, + }, + }, relations: [ "posType", "posLevel", @@ -2128,9 +2177,97 @@ export class ProfileEmployeeController extends Controller { }); break; - case "lastname": + case "posNo": + [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .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("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) + .andWhere( + new Brackets((qb) => { + qb.orWhere( + body.keyword != undefined && body.keyword != null && body.keyword != "" + ? queryLike + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ); + }), + ) + .skip(skip) + .take(take) + .getManyAndCount(); + break; + + case "posType": [findProfile, total] = await this.profileRepo.findAndCount({ - where: { lastName: Like(`%${body.keyword}%`) }, + where: { + posType: { + posTypeName: Like(`%${body.keyword}%`), + }, + current_holders: { + orgRevisionId: revision?.id, + }, + }, + relations: [ + "posType", + "posLevel", + "current_holders", + "profileSalary", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + skip, + take, + }); + break; + + // case "posLevel": + // [findProfile, total] = await this.profileRepo.findAndCount({ + // where: { + // posLevel: { + // posLevelName: Like(`%${body.keyword}%`), + // }, + // current_holders: { + // orgRevisionId: revision?.id, + // }, + // }, + // relations: [ + // "posType", + // "posLevel", + // "current_holders", + // "profileSalary", + // "current_holders.orgRoot", + // "current_holders.orgChild1", + // "current_holders.orgChild2", + // "current_holders.orgChild3", + // "current_holders.orgChild4", + // ], + // skip, + // take, + // }); + // break; + + case "organization": + [findProfile, total] = await this.profileRepo.findAndCount({ + where: { + current_holders: { + orgRevisionId: revision?.id, + orgRoot: { + orgRootName: Like(`%${body.keyword}%`), + }, + }, + }, relations: [ "posType", "posLevel", @@ -2149,6 +2286,11 @@ export class ProfileEmployeeController extends Controller { default: [findProfile, total] = await this.profileRepo.findAndCount({ + where: { + current_holders: { + orgRevisionId: revision?.id, + }, + }, relations: [ "posType", "posLevel", @@ -2175,7 +2317,7 @@ export class ProfileEmployeeController extends Controller { const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { - const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; + const fullName = `${item.prefix}${item.firstName} ${item.lastName}`; const shortName = item.current_holders.length == 0 ? null @@ -2261,7 +2403,7 @@ export class ProfileEmployeeController extends Controller { positionType: item.posTypeId, positionTypeName: item.posType?.posTypeName, posNo: shortName, - organization: root == null ? null : root.orgRootShortName, + organization: root == null ? null : root.orgRootName, salary: salary == "" ? "" : salary.amount, root: rootHolder?.orgRootName ?? null, rootId: rootHolder?.id ?? null,