From 78778e0eb03fdfade34577218259980fc4fb2103 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 23 Jan 2026 17:32:11 +0700 Subject: [PATCH] =?UTF-8?q?test=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B1=E0=B8=87=E0=B8=81=E0=B9=8C=E0=B8=8A?= =?UTF-8?q?=E0=B8=B1=E0=B9=88=E0=B8=99=E0=B9=83=E0=B8=AB=E0=B9=89=E0=B8=A2?= =?UTF-8?q?=E0=B8=B4=E0=B8=87=E0=B9=84=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=9A?= =?UTF-8?q?=E0=B8=9A=20exprofile=20#2190?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 534 +++++++++++++----- src/controllers/ProfileController.ts | 39 +- src/controllers/ProfileEmployeeController.ts | 38 +- .../ProfileEmployeeTempController.ts | 36 ++ src/interfaces/utils.ts | 13 +- src/services/rabbitmq.ts | 2 +- 6 files changed, 510 insertions(+), 152 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index a682932d..905c77ea 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -97,6 +97,7 @@ import { CreatePosMasterHistoryEmployeeTemp, CreatePosMasterHistoryOfficer, } from "../services/PositionService"; +import { PostRetireToExprofile } from "./ExRetirementController"; @Route("api/v1/org/command") @Tags("Command") @Security("bearerAuth") @@ -3798,7 +3799,12 @@ export class CommandController extends Controller { body.data.map(async (item) => { const profile = await this.profileRepository.findOne({ where: { id: item.profileId }, - relations: ["roleKeycloaks"], + // relations: ["roleKeycloaks"], + relations: { + roleKeycloaks: true, + posType: true , + posLevel: true + } }); if (!profile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); @@ -3866,14 +3872,30 @@ export class CommandController extends Controller { const curRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, }); - + let orgRootRef = null; + let orgChild1Ref = null; + let orgChild2Ref = null; + let orgChild3Ref = null; + let orgChild4Ref = null; if (curRevision) { const curPosMaster = await this.posMasterRepository.findOne({ where: { current_holderId: profile.id, orgRevisionId: curRevision.id, }, + relations:{ + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + } }); + orgRootRef = curPosMaster?.orgRoot ?? null; + orgChild1Ref = curPosMaster?.orgChild1 ?? null; + orgChild2Ref = curPosMaster?.orgChild2 ?? null; + orgChild3Ref = curPosMaster?.orgChild3 ?? null; + orgChild4Ref = curPosMaster?.orgChild4 ?? null; if (curPosMaster && clearProfile.LeaveType != "RETIRE_OUT_EMP") { await CreatePosMasterHistoryOfficer(curPosMaster.id, req, "DELETE"); } @@ -4045,6 +4067,44 @@ export class CommandController extends Controller { profile.isActive = true; } await this.profileRepository.save(profile); + // Task #2190 + if (code && ["C-PM-17", "C-PM-18"].includes(code)) { + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // item.commandDateAffect?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // profile.posLevel?.posLevelName ?? "", + // item.commandDateAffect ?? new Date(), + // organizeName, + // clearProfile.retireTypeName ?? "", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); + } }), ); @@ -4138,7 +4198,12 @@ export class CommandController extends Controller { body.data.map(async (item) => { const profile = await this.profileEmployeeRepository.findOne({ where: { id: item.profileId }, - relations: ["roleKeycloaks"], + // relations: ["roleKeycloaks"], + relations: { + roleKeycloaks: true, + posType: true , + posLevel: true + } }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); @@ -4204,6 +4269,35 @@ export class CommandController extends Controller { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } const clearProfile = await checkCommandType(String(item.commandId)); + const curRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }); + let orgRootRef = null; + let orgChild1Ref = null; + let orgChild2Ref = null; + let orgChild3Ref = null; + let orgChild4Ref = null; + if (curRevision) { + const curPosMaster = await this.employeePosMasterRepository.findOne({ + where: { + current_holderId: profile.id, + orgRevisionId: curRevision.id, + }, + relations:{ + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + } + }); + orgRootRef = curPosMaster?.orgRoot ?? null; + orgChild1Ref = curPosMaster?.orgChild1 ?? null; + orgChild2Ref = curPosMaster?.orgChild2 ?? null; + orgChild3Ref = curPosMaster?.orgChild3 ?? null; + orgChild4Ref = curPosMaster?.orgChild4 ?? null; + } + if (clearProfile.status) { if (profile.keycloak != null) { const delUserKeycloak = await deleteUser(profile.keycloak); @@ -4224,6 +4318,44 @@ export class CommandController extends Controller { // profile.posLevelId = _null; } await this.profileEmployeeRepository.save(profile); + // Task #2190 + if (code && ["C-PM-23", "C-PM-43"].includes(code)) { + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // item.commandDateAffect?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`, + // item.commandDateAffect ?? new Date(), + // organizeName, + // clearProfile.retireTypeName ?? "", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); + } }), ); @@ -4320,7 +4452,12 @@ export class CommandController extends Controller { body.data.map(async (item) => { const profile: any = await this.profileRepository.findOne({ where: { id: item.profileId }, - relations: ["roleKeycloaks"], + // relations: ["roleKeycloaks"], + relations: { + roleKeycloaks: true, + posType: true, + posLevel: true + } }); if (!profile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); @@ -4333,10 +4470,22 @@ export class CommandController extends Controller { orgRevisionIsDraft: false, }, }, - relations: ["orgRevision"], + relations: { + orgRevision: true, + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + }, }); const orgRevisionRef = posMaster ? posMaster.id : null; + const orgRootRef = orgRevisionRef?.orgRoot ?? null; + const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; + const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; + const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; + const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; //ลบตำแหน่งที่รักษาการแทน const code = _command?.commandType?.code; @@ -4405,15 +4554,14 @@ export class CommandController extends Controller { history.profileSalaryId = data.id; await this.salaryHistoryRepo.save(history, { data: req }); - if (item.commandId) { + if (_command) { + /* const command = await this.commandRepository.findOne({ where: { id: item.commandId }, relations: ["commandType"], }); - if ( - command != null && - (command.commandType.code == "C-PM-15" || command.commandType.code == "C-PM-16") - ) { + */ + if (["C-PM-15", "C-PM-16"].includes(_command.commandType.code)) { // ประวัติคำสั่งให้ช่วยราชการ const dataAssis = new ProfileAssistance(); @@ -4433,7 +4581,7 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - status: command.commandType.code == "C-PM-15" ? "PENDING" : "DONE", + status: _command.commandType.code == "C-PM-15" ? "PENDING" : "DONE", }; Object.assign(dataAssis, metaAssis); @@ -4444,6 +4592,44 @@ export class CommandController extends Controller { historyAssis.profileAssistanceId = dataAssis.id; await this.assistanceHistoryRepository.save(historyAssis); } + // Task #2190 + else if (_command.commandType.code == "C-PM-13") { + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // item.commandDateAffect?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // profile.posLevel?.posLevelName ?? "", + // item.commandDateAffect ?? new Date(), + // organizeName, + // clearProfile.retireTypeName ?? "", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); + } } }), ); @@ -4656,10 +4842,25 @@ export class CommandController extends Controller { if (item.commandYear) { _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; } + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + }); + let orgRootRef = null; + let orgChild1Ref = null; + let orgChild2Ref = null; + let orgChild3Ref = null; + let orgChild4Ref = null; + let profile; + let isEmployee:boolean = false; + let retireTypeName:string = ""; + // ขรก. if (item.profileType && item.profileType.trim().toUpperCase() == "OFFICER") { - const profile = await this.profileRepository.findOne({ + profile = await this.profileRepository.findOne({ relations: [ - "profileSalary", + // "profileSalary", "posLevel", "posType", "current_holders", @@ -4673,63 +4874,35 @@ export class CommandController extends Controller { "roleKeycloaks", ], where: { id: item.profileId }, - order: { - profileSalary: { - order: "DESC", - }, - }, + // order: { + // profileSalary: { + // order: "DESC", + // }, + // }, }); if (!profile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); } - + const lastSalary = await this.salaryRepo.findOne({ + where: { profileId: item.profileId }, + select: ["order"], + order: { order: "DESC" }, + }); + const nextOrder = lastSalary ? lastSalary.order + 1 : 1; //ลบตำแหน่งที่รักษาการแทน const code = _command?.commandType?.code; if (code && ["C-PM-19", "C-PM-20"].includes(code)) { removePostMasterAct(profile.id); } - const orgRevision = await this.orgRevisionRepo.findOne({ - where: { - orgRevisionIsCurrent: true, - orgRevisionIsDraft: false, - }, - }); const orgRevisionRef = profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null; - // const orgRootRef = orgRevisionRef?.orgRoot ?? null; - // const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; - // const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; - // const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; - // const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; - // const shortName = - // !profile.current_holders || profile.current_holders.length == 0 - // ? null - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild4 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild3 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - // null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild2 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - // null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild1 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - // null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgRoot != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` - // : null; - // const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; + orgRootRef = orgRevisionRef?.orgRoot ?? null; + orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; + orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; + orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; + orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; + let position = profile.current_holders .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -4750,12 +4923,13 @@ export class CommandController extends Controller { positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, amountSpecial: item.amountSpecial ? item.amountSpecial : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, - order: - profile.profileSalary.length >= 0 - ? profile.profileSalary.length > 0 - ? profile.profileSalary[0].order + 1 - : 1 - : null, + // order: + // profile.profileSalary.length >= 0 + // ? profile.profileSalary.length > 0 + // ? profile.profileSalary[0].order + 1 + // : 1 + // : null, + order: nextOrder, orgRoot: item.orgRoot, orgChild1: item.orgChild1, orgChild2: item.orgChild2, @@ -4845,6 +5019,7 @@ export class CommandController extends Controller { } const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { + retireTypeName = clearProfile.retireTypeName ?? ""; if (_profile.keycloak != null) { const delUserKeycloak = await deleteUser(_profile.keycloak); if (delUserKeycloak) { @@ -4865,10 +5040,13 @@ export class CommandController extends Controller { } await this.profileRepository.save(_profile); } - } else { - const profile = await this.profileEmployeeRepository.findOne({ + } + // ลูกจ้าง + else { + isEmployee = true; + profile = await this.profileEmployeeRepository.findOne({ relations: [ - "profileSalary", + // "profileSalary", "posLevel", "posType", "current_holders", @@ -4880,60 +5058,29 @@ export class CommandController extends Controller { "roleKeycloaks", ], where: { id: item.profileId }, - order: { - profileSalary: { - order: "DESC", - }, - }, + // order: { + // profileSalary: { + // order: "DESC", + // }, + // }, }); if (!profile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); } - // const orgRevision = await this.orgRevisionRepo.findOne({ - // where: { - // orgRevisionIsCurrent: true, - // orgRevisionIsDraft: false, - // }, - // }); - // const orgRevisionRef = - // profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null; - // const orgRootRef = orgRevisionRef?.orgRoot ?? null; - // const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; - // const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; - // const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; - // const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; - // const shortName = - // !profile.current_holders || profile.current_holders.length == 0 - // ? null - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild4 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild3 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - // null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild2 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - // null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgChild1 != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}` - // : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != - // null && - // profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) - // ?.orgRoot != null - // ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` - // : null; - // const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; - // let position = - // profile.current_holders - // .filter((x) => x.orgRevisionId == orgRevision?.id)[0] - // ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; + const lastSalary = await this.salaryRepo.findOne({ + where: { profileEmployeeId: item.profileId }, + select: ["order"], + order: { order: "DESC" }, + }); + const nextOrder = lastSalary ? lastSalary.order + 1 : 1; + const orgRevisionRef = + profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null; + orgRootRef = orgRevisionRef?.orgRoot ?? null; + orgChild1Ref = orgRevisionRef?.orgChild1 ?? null; + orgChild2Ref = orgRevisionRef?.orgChild2 ?? null; + orgChild3Ref = orgRevisionRef?.orgChild3 ?? null; + orgChild4Ref = orgRevisionRef?.orgChild4 ?? null; + // ประวัติตำแหน่ง const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; @@ -4951,12 +5098,13 @@ export class CommandController extends Controller { amount: item.amount ? item.amount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, - order: - profile.profileSalary.length >= 0 - ? profile.profileSalary.length > 0 - ? profile.profileSalary[0].order + 1 - : 1 - : null, + // order: + // profile.profileSalary.length >= 0 + // ? profile.profileSalary.length > 0 + // ? profile.profileSalary[0].order + 1 + // : 1 + // : null, + order: nextOrder, orgRoot: item.orgRoot, orgChild1: item.orgChild1, orgChild2: item.orgChild2, @@ -5048,6 +5196,7 @@ export class CommandController extends Controller { } const clearProfile = await checkCommandType(String(item.commandId)); if (clearProfile.status) { + retireTypeName = clearProfile.retireTypeName ?? ""; if (_profile.keycloak != null) { const delUserKeycloak = await deleteUser(_profile.keycloak); if (delUserKeycloak) { @@ -5069,6 +5218,47 @@ export class CommandController extends Controller { await this.profileEmployeeRepository.save(_profile); } } + // Task #2190 + if (_command && ["C-PM-19", "C-PM-20"].includes(_command.commandType.code)) { + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + let _posLevelName: string = !isEmployee + ? `${profile.posLevel?.posLevelName}` + : `${profile.posType?.posTypeName} ${profile.posLevel?.posLevelName}`; + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // item.commandDateAffect?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // _posLevelName, + // item.commandDateAffect ?? new Date(), + // organizeName, + // retireTypeName, + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); + } }), ); @@ -5158,7 +5348,7 @@ export class CommandController extends Controller { body.data.map(async (item) => { const profile = await this.profileEmployeeRepository.findOne({ relations: [ - "profileSalary", + // "profileSalary", "posLevel", "posType", "current_holders", @@ -5170,15 +5360,21 @@ export class CommandController extends Controller { "roleKeycloaks", ], where: { id: item.profileId }, - order: { - profileSalary: { - order: "DESC", - }, - }, + // order: { + // profileSalary: { + // order: "DESC", + // }, + // }, }); if (!profile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); } + const lastSalary = await this.salaryRepo.findOne({ + where: { profileEmployeeId: item.profileId }, + select: ["order"], + order: { order: "DESC" }, + }); + const nextOrder = lastSalary ? lastSalary.order + 1 : 1; let _commandYear = item.commandYear; if (item.commandYear) { _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; @@ -5244,12 +5440,13 @@ export class CommandController extends Controller { amountSpecial: item.amountSpecial ? item.amountSpecial : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, - order: - profile.profileSalary.length >= 0 - ? profile.profileSalary.length > 0 - ? profile.profileSalary[0].order + 1 - : 1 - : null, + // order: + // profile.profileSalary.length >= 0 + // ? profile.profileSalary.length > 0 + // ? profile.profileSalary[0].order + 1 + // : 1 + // : null, + order: nextOrder, orgRoot: item.orgRoot, orgChild1: item.orgChild1, orgChild2: item.orgChild2, @@ -5643,7 +5840,7 @@ export class CommandController extends Controller { body.data.map(async (item) => { const profile = await this.profileRepository.findOne({ relations: [ - "profileSalary", + // "profileSalary", "posType", "posLevel", "current_holders", @@ -5656,15 +5853,21 @@ export class CommandController extends Controller { "current_holders.positions.posExecutive", ], where: { id: item.profileId }, - order: { - profileSalary: { - order: "DESC", - }, - }, + // order: { + // profileSalary: { + // order: "DESC", + // }, + // }, }); if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } + const lastSalary = await this.salaryRepo.findOne({ + where: { profileId: item.profileId }, + select: ["order"], + order: { order: "DESC" }, + }); + const nextOrder = lastSalary ? lastSalary.order + 1 : 1; let _commandYear = item.commandYear; if (item.commandYear) { _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; @@ -5740,12 +5943,13 @@ export class CommandController extends Controller { amountSpecial: item.amountSpecial ? item.amountSpecial : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, - order: - profile.profileSalary.length >= 0 - ? profile.profileSalary.length > 0 - ? profile.profileSalary[0].order + 1 - : 1 - : null, + // order: + // profile.profileSalary.length >= 0 + // ? profile.profileSalary.length > 0 + // ? profile.profileSalary[0].order + 1 + // : 1 + // : null, + order: nextOrder, orgRoot: orgRootRef?.orgRootName ?? null, orgChild1: orgChild1Ref?.orgChild1Name ?? null, orgChild2: orgChild2Ref?.orgChild2Name ?? null, @@ -5804,6 +6008,42 @@ export class CommandController extends Controller { Object.assign(history, { ...profileSalary, id: undefined }); history.profileSalaryId = profileSalary.id; await this.salaryHistoryRepo.save(history); + // Task #2190 + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // item.commandDateAffect?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // profile.posLevel?.posLevelName ?? "", + // item.commandDateAffect ?? new Date(), + // organizeName, + // clearProfile.retireTypeName ?? "", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); }), ); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 18a74e5c..15ae7694 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -89,7 +89,7 @@ import { CommandRecive } from "../entities/CommandRecive"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService"; import { ProfileLeaveService } from "../services/ProfileLeaveService"; - +import { PostRetireToExprofile } from "./ExRetirementController"; @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -8194,7 +8194,7 @@ export class ProfileController extends Controller { "current_holders.orgChild2", "current_holders.orgChild3", "current_holders.orgChild4", - "profileSalary", + // "profileSalary", "profileEducations", "profileActpositions", ], @@ -10858,6 +10858,41 @@ export class ProfileController extends Controller { } await removeProfileInOrganize(profile.id, "OFFICER"); } + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // requestBody.dateLeave?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // profile.posLevel?.posLevelName ?? "", + // requestBody.dateLeave ?? new Date(), + // organizeName, + // "ถึงแก่กรรม", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); return new HttpSuccess(); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index b37e115f..ed993152 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -82,6 +82,7 @@ import { ProfileChildren } from "../entities/ProfileChildren"; import { ProfileDuty } from "../entities/ProfileDuty"; import { getTopDegrees } from "../services/PositionService"; import { ProfileLeaveService } from "../services/ProfileLeaveService"; +import { PostRetireToExprofile } from "./ExRetirementController"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -5333,6 +5334,41 @@ export class ProfileEmployeeController extends Controller { if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // requestBody.dateLeave?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`, + // requestBody.dateLeave ?? new Date(), + // organizeName, + // "ถึงแก่กรรม", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); return new HttpSuccess(); } @@ -5936,7 +5972,7 @@ export class ProfileEmployeeController extends Controller { "current_holders.orgChild2", "current_holders.orgChild3", "current_holders.orgChild4", - "profileSalary", + // "profileSalary", "profileEducations", ], order: { diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index ce66c221..9fdfd581 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -70,6 +70,7 @@ import { deleteUser } from "../keycloak"; import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { getTopDegrees } from "../services/PositionService"; import HttpStatusCode from "../interfaces/http-status"; +import { PostRetireToExprofile } from "./ExRetirementController"; @Route("api/v1/org/profile-temp") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -3547,6 +3548,41 @@ export class ProfileEmployeeTempController extends Controller { if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + let organizeName = ""; + if (orgRootRef) { + const names = [ + orgChild4Ref?.orgChild4Name, + orgChild3Ref?.orgChild3Name, + orgChild2Ref?.orgChild2Name, + orgChild1Ref?.orgChild1Name, + orgRootRef?.orgRootName, + ].filter(Boolean); + organizeName = names.join(" "); + } + await PostRetireToExprofile( + // profile.citizenId ?? "", + // profile.prefix ?? "", + // profile.firstName ?? "", + // profile.lastName ?? "", + // requestBody.dateLeave?.getFullYear().toString() ?? "", + // profile.position, + // profile.posType?.posTypeName ?? "", + // `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`, + // requestBody.dateLeave ?? new Date(), + // organizeName, + // "ถึงแก่กรรม", + "310190004095X", + "จ.ส.อ.", + "dev", + "hrms", + "2026", + "เจ้าหน้าที่จัดเก็บรายได้", + "อื่นๆ", + "C 3", + new Date(2026, 0, 1), + "สำนักงานเขตบางกอกใหญ่", + "เกษียณ" + ); return new HttpSuccess(); } diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 12636a36..abe4bd4a 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -453,7 +453,7 @@ export async function checkCommandType(commandId: string) { ].includes(String(_type?.commandType.code)) ) { // return false; - return { status: false, LeaveType: null, leaveRemark: null }; + return { status: false, LeaveType: null, leaveRemark: null, retireTypeName: null }; } // return true; const _commandRecive = await commandReciveRepository.findOne({ @@ -461,47 +461,58 @@ export async function checkCommandType(commandId: string) { }); let _leaveType: string = ""; + let _retireTypeName: string = ""; //อิงตามเหตุผลการพ้นจากราชการ ข้อมูลทะเบียนประวัติผู้พ้นจากราชการ switch (String(_type?.commandType.code)) { case "C-PM-12": { _leaveType = "PROBATION_REPORT"; + _retireTypeName = "ผลการทดลองฯ ต่ำกว่ามาตรฐานที่กำหนด" break; } case "C-PM-13": { _leaveType = "PLACEMENT_TRANSFER"; + _retireTypeName = "โอนออก"; break; } case "C-PM-17": { _leaveType = "RETIRE_RESIGN"; + _retireTypeName = "ลาออกจากราชการ"; break; } case "C-PM-18": { _leaveType = "RETIRE_OUT"; + _retireTypeName = "ให้ออกจากราชการ"; break; } case "C-PM-19": { _leaveType = "DISCIPLINE_RESULT_REMOVE"; + _retireTypeName = "ปลดออกจากราชการ"; break; } case "C-PM-20": { _leaveType = "DISCIPLINE_RESULT_DISMISS"; + _retireTypeName = "ไล่ออกจากราชการ"; break; } case "C-PM-23": { _leaveType = "RETIRE_RESIGN_EMP"; + _retireTypeName = "ลาออกจากราชการ"; break; } case "C-PM-43": { _leaveType = "RETIRE_OUT_EMP"; + _retireTypeName = "ให้ออกจากราชการ"; break; } default: { _leaveType = ""; + _retireTypeName = ""; } } return { status: true, LeaveType: _leaveType, leaveRemark: _commandRecive ? _commandRecive.remarkVertical : null, + retireTypeName: _retireTypeName ? _retireTypeName : null }; } diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index aa02f882..326cb9a1 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -85,7 +85,7 @@ export async function init() { console.log("[AMQ] Listening for message..."); createConsumer(queue, channel, handler), //----> (3) Process Consumer - createConsumer(queue_org, channel, handler_org); + createConsumer(queue_org, channel, handler_org); createConsumer(queue_org_draft, channel, handler_org_draft); createConsumer(queue_command_noti, channel, handler_command_noti); // createConsumer(queue2, channel, handler2);