From 77e3248a3a7842bf7203157cb46870a206884418 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 20 May 2024 15:23:26 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=84=E0=B8=A3=E0=B8=AD=E0=B8=87?= =?UTF-8?q?=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= =?UTF-8?q?=20=E0=B8=82=E0=B8=A3=E0=B8=81./=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 68 ++++++++++++++++++++ src/controllers/ProfileEmployeeController.ts | 65 +++++++++++++++++++ src/entities/ProfileEmployee.ts | 2 +- src/entities/ProfileSalary.ts | 2 +- 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 0d393db9..4fb2a65e 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -815,6 +815,74 @@ export class ProfileController extends Controller { return new HttpSuccess({ data: data, total }); } + /** + * API ค้นหาประวัติการครองตำแหน่ง ข้าราชการ + * + * @summary ค้นหาประวัติการครองตำแหน่ง ข้าราชการ + * + */ + @Post("search/history/oc") + async searchHistoryOC( + @Body() + requestBody: { + posNo?: string; + position?: string; + }, + ) { + const profiles = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.profileSalary", "profileSalary") + .select([ + "profile.id", + "profile.prefix", + "profile.firstName", + "profile.lastName", + "profile.citizenId", + "profileSalary.position", + "profileSalary.posNo", + "profileSalary.date" + ]) + .andWhere( + requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined + ? "profileSalary.position LIKE :position" + : "1=2", + { + position: `%${requestBody.position}%`, + }, + ) + .orWhere( + requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined + ? "profileSalary.posNo LIKE :posNo" + : "1=2", + { + posNo: `%${requestBody.posNo}%`, + }, + ) + .getMany(); + + const mapData = profiles.map(profile => { + let profileSalary; + if (profile.profileSalary && profile.profileSalary.length > 0) { + profileSalary = profile.profileSalary.reduce((latest, current) => { + return new Date(current.date) > new Date(latest.date) ? current : latest; + }); + } + return { + id: profile.id, + // prefix: profile.prefix, + // firstName: profile.firstName, + // lastName: profile.lastName, + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + citizenId: profile.citizenId, + position: profileSalary ? profileSalary.position : null, + posNo: profileSalary ? profileSalary.posNo : null, + date: profileSalary ? profileSalary.date : null + }; + }); + + return new HttpSuccess(mapData); + } + /** * API ข้อมูลทะเบียนประวัติตาม keycloak * diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 96f26e7f..2498e0ee 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -526,6 +526,71 @@ export class ProfileEmployeeController extends Controller { return new HttpSuccess({ data: data, total }); } + /** + * API ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง + * + * @summary ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง + * + */ + @Post("search/history/oc") + async searchHistoryOC( + @Body() + requestBody: { + posNo?: string; + position?: string; + }, + ) { + const profiles = await this.profileRepo + .createQueryBuilder("profileEmployee") + .leftJoinAndSelect("profileEmployee.profileSalarys", "profileSalarys") + .select([ + "profileEmployee.id", + "profileEmployee.prefix", + "profileEmployee.firstName", + "profileEmployee.lastName", + "profileEmployee.citizenId", + "profileSalarys.position", + "profileSalarys.posNo", + "profileSalarys.date" + ]) + .andWhere( + requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined + ? "profileSalarys.position LIKE :position" + : "1=2", + { + position: `%${requestBody.position}%`, + }, + ) + .orWhere( + requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined + ? "profileSalarys.posNo LIKE :posNo" + : "1=2", + { + posNo: `%${requestBody.posNo}%`, + }, + ) + .getMany(); + + const mapData = profiles.map(profile => { + let profileSalary; + if (profile.profileSalarys && profile.profileSalarys.length > 0) { + profileSalary = profile.profileSalarys.reduce((latest, current) => { + return new Date(current.date) > new Date(latest.date) ? current : latest; + }); + } + return { + id: profile.id, + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + citizenId: profile.citizenId, + position: profileSalary ? profileSalary.position : null, + posNo: profileSalary ? profileSalary.posNo : null, + date: profileSalary ? profileSalary.date : null + }; + }); + + return new HttpSuccess(mapData); + } + /** * API ข้อมูลทะเบียนประวัติตาม keycloak * diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index c291722e..930e7c8a 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -282,7 +282,7 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => EmployeePosMaster, (v) => v.next_holder) next_holders: EmployeePosMaster[]; - @OneToMany(() => ProfileSalary, (v) => v.profile) + @OneToMany(() => ProfileSalary, (v) => v.profileEmployee) profileSalarys: ProfileSalary[]; @OneToMany(() => ProfileCertificate, (v) => v.profileEmployee) diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index 5fe67df9..a6261eee 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -149,7 +149,7 @@ export class ProfileSalary extends EntityBase { @JoinColumn({ name: "profileId" }) profile: Profile; - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileSalarys) + @ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.profileSalarys) @JoinColumn({ name: "profileEmployeeId" }) profileEmployee: ProfileEmployee; }