From 0ac11ba05c0cac6e59ed010243b14c2f4aeb10cf Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 17 Jun 2025 13:37:17 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=82=E0=B8=A3=E0=B8=81.+=E0=B8=A5?= =?UTF-8?q?=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3=20=E0=B8=95=E0=B8=B2?= =?UTF-8?q?=E0=B8=A1=E0=B8=AA=E0=B8=B4=E0=B8=97=E0=B8=98=E0=B8=B4=E0=B9=8C?= =?UTF-8?q?=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationDotnetController.ts | 364 ++++++++++++++++++ 1 file changed, 364 insertions(+) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 18ae5a70..8f1dc9c0 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -4010,6 +4010,188 @@ export class OrganizationDotnetController extends Controller { return new HttpSuccess(profile_); } + /** + * รายชื่อขรก. ตามสิทธิ์ admin + * + * @summary รายชื่อขรก. ตามสิทธิ์ admin + * + */ + @Post("officer-by-admin-role") + async GetOfficersByAdminRole( + @Request() req: RequestWithUser, + @Body() + body: { + node: number; + nodeId: string; + role: string; + isRetirement?: boolean; + revisionId?: string; + }, + ) { + let typeCondition: any = {}; + const node = body.role === "OWNER" ? null : body.node; + if (body.role === "OWNER" || body.role === "CHILD") { + switch (node) { + case 0: + typeCondition = { orgRootId: body.nodeId }; + break; + case 1: + typeCondition = { orgChild1Id: body.nodeId }; + break; + case 2: + typeCondition = { orgChild2Id: body.nodeId }; + break; + case 3: + typeCondition = { orgChild3Id: body.nodeId }; + break; + case 4: + typeCondition = { orgChild4Id: body.nodeId }; + break; + case null: + typeCondition = {}; + break; + default: + typeCondition = {}; + break; + } + } else if (body.role === "ROOT") { + typeCondition = { + orgRootId: body.nodeId + }; + } else if (body.role === "NORMAL") { + switch (node) { + case 0: + typeCondition = { + orgRootId: body.nodeId, + orgChild1Id: IsNull(), + }; + break; + case 1: + typeCondition = { + orgChild1Id: body.nodeId, + orgChild2Id: IsNull(), + }; + break; + case 2: + typeCondition = { + orgChild2Id: body.nodeId, + orgChild3Id: IsNull(), + }; + break; + case 3: + typeCondition = { + orgChild3Id: body.nodeId, + orgChild4Id: IsNull(), + }; + break; + default: + typeCondition = {}; + break; + } + } + + let profile = await this.profileRepo.find({ + where: { isLeave: false, isRetirement: false, current_holders: typeCondition }, + relations: [ + "posType", + "posLevel", + "current_holders", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + }); + if (body.isRetirement) { + profile = await this.profileRepo.find({ + where: { + isLeave: false, + current_holders: typeCondition, + isRetirement: true, + }, + relations: [ + "posType", + "posLevel", + "current_holders", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + }); + } + let findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + + if (body.revisionId) { + findRevision = await this.orgRevisionRepo.findOne({ + where: { id: body.revisionId }, + }); + } + + const profile_ = await Promise.all( + profile.map((item: Profile) => { + const shortName = + item.current_holders.length == 0 + ? null + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : null; + const Oc = + item.current_holders.length == 0 + ? null + : body.node == 4 && item.current_holders[0].orgChild4 != null + ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 3 && item.current_holders[0].orgChild3 != null + ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 2 && item.current_holders[0].orgChild2 != null + ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 1 && item.current_holders[0].orgChild1 != null + ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 0 && item.current_holders[0].orgRoot != null + ? `${item.current_holders[0].orgRoot.orgRootName}` + : null; + return { + id: item.id, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + citizenId: item.citizenId, + keycloak: item.keycloak, + posNo: shortName, + position: item.position, + positionLevel: item.posLevel?.posLevelName ?? null, + positionType: item.posType?.posTypeName ?? null, + oc: Oc, + }; + }), + ); + + return new HttpSuccess(profile_); + } + /** * 5. เอารายชื่อคนที่มีการ ,map keycloak id แล้ว * @@ -4318,6 +4500,188 @@ export class OrganizationDotnetController extends Controller { return new HttpSuccess(profile_); } + /** + * รายชื่อลูกจ้างประจำ ตามสิทธิ์ admin + * + * @summary รายชื่อลูกจ้างประจำ ตามสิทธิ์ admin + * + */ + @Post("employee-by-admin-role") + async GetEmployeesByAdminRole( + @Request() req: RequestWithUser, + @Body() + body: { + node: number; + nodeId: string; + role: string; + isRetirement?: boolean; + revisionId?: string; + }, + ) { + let typeCondition: any = {}; + const node = body.role === "OWNER" ? null : body.node; + if (body.role === "OWNER" || body.role === "CHILD") { + switch (node) { + case 0: + typeCondition = { orgRootId: body.nodeId }; + break; + case 1: + typeCondition = { orgChild1Id: body.nodeId }; + break; + case 2: + typeCondition = { orgChild2Id: body.nodeId }; + break; + case 3: + typeCondition = { orgChild3Id: body.nodeId }; + break; + case 4: + typeCondition = { orgChild4Id: body.nodeId }; + break; + case null: + typeCondition = {}; + break; + default: + typeCondition = {}; + break; + } + } else if (body.role === "ROOT") { + typeCondition = { + orgRootId: body.nodeId + }; + } else if (body.role === "NORMAL") { + switch (node) { + case 0: + typeCondition = { + orgRootId: body.nodeId, + orgChild1Id: IsNull(), + }; + break; + case 1: + typeCondition = { + orgChild1Id: body.nodeId, + orgChild2Id: IsNull(), + }; + break; + case 2: + typeCondition = { + orgChild2Id: body.nodeId, + orgChild3Id: IsNull(), + }; + break; + case 3: + typeCondition = { + orgChild3Id: body.nodeId, + orgChild4Id: IsNull(), + }; + break; + default: + typeCondition = {}; + break; + } + } + + let profile = await this.profileEmpRepo.find({ + where: { isLeave: false, isRetirement: false, current_holders: typeCondition }, + relations: [ + "posType", + "posLevel", + "current_holders", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + }); + if (body.isRetirement) { + profile = await this.profileEmpRepo.find({ + where: { + isLeave: false, + current_holders: typeCondition, + isRetirement: true, + }, + relations: [ + "posType", + "posLevel", + "current_holders", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + ], + }); + } + let findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + + if (body.revisionId) { + findRevision = await this.orgRevisionRepo.findOne({ + where: { id: body.revisionId }, + }); + } + + const profile_ = await Promise.all( + profile.map((item: ProfileEmployee) => { + const shortName = + item.current_holders.length == 0 + ? null + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` + : null; + const Oc = + item.current_holders.length == 0 + ? null + : body.node == 4 && item.current_holders[0].orgChild4 != null + ? `${item.current_holders[0].orgChild4.orgChild4Name}/${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 3 && item.current_holders[0].orgChild3 != null + ? `${item.current_holders[0].orgChild3.orgChild3Name}/${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 2 && item.current_holders[0].orgChild2 != null + ? `${item.current_holders[0].orgChild2.orgChild2Name}/${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 1 && item.current_holders[0].orgChild1 != null + ? `${item.current_holders[0].orgChild1.orgChild1Name}/${item.current_holders[0].orgRoot.orgRootName}` + : body.node == 0 && item.current_holders[0].orgRoot != null + ? `${item.current_holders[0].orgRoot.orgRootName}` + : null; + return { + id: item.id, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + citizenId: item.citizenId, + keycloak: item.keycloak, + posNo: shortName, + position: item.position, + positionLevel: item.posLevel?.posLevelName ?? null, + positionType: item.posType?.posTypeName ?? null, + oc: Oc, + }; + }), + ); + + return new HttpSuccess(profile_); + } + /** * 4. API Update รอบการลงเวลา ในตาราง profile *