From 277b564711b7a8962ee5925e5f0760bfc3f6a6fb Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 26 Mar 2025 16:54:16 +0700 Subject: [PATCH] =?UTF-8?q?API=20=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=20=E0=B8=81=E0=B8=81.=20=E0=B8=AA=E0=B8=81=E0=B8=88.?= =?UTF-8?q?=20=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B8=AB=E0=B8=B1=E0=B8=A7?= =?UTF-8?q?=E0=B8=AB=E0=B8=99=E0=B9=89=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 169 +++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 8f4418fa..35afa13e 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2583,6 +2583,175 @@ export class CommandController extends Controller { return new HttpSuccess(command.id); } + /** + * API ค้นหา กก. สกจ. และหัวหน้า + * + * @summary API ค้นหา กก. สกจ. และหัวหน้า + * + */ + @Post("find-higher") + async findHigher( + @Body() + requestBody: { + persons: { + profileId?: string | null; + }[]; + }, + @Request() request: RequestWithUser, + ) { + let _null:any = null; + let _data = new Array(); + const _posMasterCommission = await this.posMasterRepository.findOne({ + where: { + orgRoot: { + isCommission: true, + }, + isDirector: true, + orgChild1: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot", "positions"], + order: { posMasterOrder: "ASC" }, + }); + if(_posMasterCommission) { + _data.push({ + citizenId: _posMasterCommission?.current_holder.citizenId ?? _null, + fullName: `${_posMasterCommission?.current_holder.prefix ?? ""}${_posMasterCommission?.current_holder.firstName ?? ""} ${_posMasterCommission?.current_holder.lastName ?? ""}`, + organizationName: _posMasterCommission.orgRoot + ? _posMasterCommission.orgRoot.orgRootName + : _null, + positionName: _posMasterCommission?.current_holder.position ?? _null, + profileId: _posMasterCommission?.current_holder.id ?? _null + }); + } + + const _posMasterOfficer = await this.posMasterRepository.findOne({ + where: { + orgChild1: { + isOfficer: true, + }, + isDirector: true, + orgChild2: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot", "positions"], + order: { posMasterOrder: "ASC" }, + }); + if(_posMasterOfficer) { + _data.push({ + citizenId: _posMasterOfficer?.current_holder.citizenId ?? _null, + fullName: `${_posMasterOfficer?.current_holder.prefix ?? ""}${_posMasterOfficer?.current_holder.firstName ?? ""} ${_posMasterOfficer?.current_holder.lastName ?? ""}`, + organizationName: _posMasterOfficer.orgRoot + ? _posMasterOfficer.orgRoot.orgRootName + : _null, + positionName: _posMasterOfficer?.current_holder.position ?? _null, + profileId: _posMasterOfficer?.current_holder.id ?? _null + }); + } + + let _orgRoot: any = []; + let _orgChild1: any = []; + let _orgChild2: any = []; + let _orgChild3: any = []; + let _orgChild4: any = []; + + var posMasterOfficer = await this.posMasterRepository.find({ + where: { + current_holderId: In(requestBody.persons.map((x) => x.profileId)), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + select: ["orgRootId", "orgChild1Id", "orgChild2Id", "orgChild3Id", "orgChild4Id"], + }); + var posMasterEmployee = await this.employeePosMasterRepository.find({ + where: { + current_holderId: In(requestBody.persons.map((x) => x.profileId)), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + select: ["orgRootId", "orgChild1Id", "orgChild2Id", "orgChild3Id", "orgChild4Id"], + }); + + let posMaster = [...posMasterOfficer, ...posMasterEmployee]; + _orgRoot = posMaster + .filter((x) => x.orgRootId != null && x.orgRootId != "") + .map((x) => x.orgRootId); + _orgChild1 = posMaster + .filter((x) => x.orgChild1Id != null && x.orgChild1Id != "") + .map((x) => x.orgChild1Id); + _orgChild2 = posMaster + .filter((x) => x.orgChild2Id != null && x.orgChild2Id != "") + .map((x) => x.orgChild2Id); + _orgChild3 = posMaster + .filter((x) => x.orgChild3Id != null && x.orgChild3Id != "") + .map((x) => x.orgChild3Id); + _orgChild4 = posMaster + .filter((x) => x.orgChild4Id != null && x.orgChild4Id != "") + .map((x) => x.orgChild4Id); + + let _posMaster: any; + _posMaster = await this.posMasterRepository.find({ + where: [ + { + orgRootId: In(_orgRoot), + orgChild1: IsNull(), + orgChild2: IsNull(), + orgChild3: IsNull(), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + id: Not(In([_posMasterCommission?.id])) + }, + { + orgChild1: In(_orgChild1), + orgChild2: IsNull(), + orgChild3: IsNull(), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + id: Not(In([_posMasterOfficer?.id])) + }, + { + orgChild2: In(_orgChild2), + orgChild3: IsNull(), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + { + orgChild3: In(_orgChild3), + orgChild4: IsNull(), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + { + orgChild4: In(_orgChild4), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + ], + relations: ["current_holder", "orgRoot"], + }); + if (_posMaster.length > 0) { + _posMaster.forEach((x:any) => { + _data.push({ + citizenId: x?.current_holder.citizenId ?? _null, + fullName: `${x?.current_holder.prefix ?? ""}${x?.current_holder.firstName ?? ""} ${x?.current_holder.lastName ?? ""}`, + organizationName: x.orgRoot ? x.orgRoot.orgRootName : _null, + positionName: x?.current_holder.position ?? _null, + profileId: x?.current_holder.id ?? _null + }); + }); + } + + return new HttpSuccess(_data); + } + @Post("excexute/salary-current") public async newSalaryAndUpdateCurrent( @Request() req: RequestWithUser,