From db51c0d7b2b43cceac75205ad72a98a1cfaac967 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 18 Aug 2025 10:57:49 +0700 Subject: [PATCH] =?UTF-8?q?Fix=20=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B9=80=E0=B8=A5=E0=B8=B7=E0=B8=AD?= =?UTF-8?q?=E0=B8=81=E0=B9=80=E0=B8=82=E0=B9=89=E0=B8=B2=E0=B8=95=E0=B8=B3?= =?UTF-8?q?=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87=20#1752=20&&=20#1?= =?UTF-8?q?751?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileGovernmentEmployeeController.ts | 204 ++++++++++++------ 1 file changed, 142 insertions(+), 62 deletions(-) diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index f93c96f0..0cfd43e3 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -17,6 +17,7 @@ import { import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; import { In } from "typeorm"; +import { ProfileSalary } from "../entities/ProfileSalary"; @Route("api/v1/org/profile-employee/government") @Tags("ProfileEmployeeGovernment") @Security("bearerAuth") @@ -26,6 +27,7 @@ export class ProfileGovernmentEmployeeController extends Controller { private positionRepo = AppDataSource.getRepository(EmployeePosition); private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); + private salaryRepo = AppDataSource.getRepository(ProfileSalary); /** * * @summary ข้อมูลราชการ @@ -150,32 +152,32 @@ export class ProfileGovernmentEmployeeController extends Controller { const record = await this.profileEmployeeRepo.findOne({ where: { id: profileEmployeeId, - profileSalary: { - commandCode: In([ - "0", - "9", - "1", - "2", - "3", - "4", - "8", - "10", - "11", - "12", - "13", - "14", - "15", - "16", - ]), - } + // profileSalary: { + // commandCode: In([ + // "0", + // "9", + // "1", + // "2", + // "3", + // "4", + // "8", + // "10", + // "11", + // "12", + // "13", + // "14", + // "15", + // "16", + // ]), + // } }, - relations: ["posType", "posLevel", "profileSalary"], - order: { - profileSalary: { - order: "DESC", - createdAt: "DESC" - } - } + relations: ["posType", "posLevel"/*, "profileSalary"*/], + // order: { + // profileSalary: { + // order: "DESC", + // createdAt: "DESC" + // } + // } }); const posMaster = await this.posMasterRepo.findOne({ where: { @@ -216,16 +218,55 @@ export class ProfileGovernmentEmployeeController extends Controller { } } let _OrgLeave:any = [] - if (record?.isLeave && record?.profileSalary.length > 0) { + let orgLeave:string = "" + let posNoLeave:string = "" + if (record?.isLeave /*&& record?.profileSalary.length > 0*/) { + const profileSalary = await this.salaryRepo.find({ + select: [ + "orgRoot", + "orgChild1", + "orgChild2", + "orgChild3", + "orgChild4", + "posNoAbb", + "posNo" + ], + where: { + profileEmployeeId: profileEmployeeId, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + order: { + order: "DESC", + createdAt: "DESC" + } + }); _OrgLeave = [ - record?.profileSalary[0].orgChild4 ? record?.profileSalary[0].orgChild4 : null, - record?.profileSalary[0].orgChild3 ? record?.profileSalary[0].orgChild3 : null, - record?.profileSalary[0].orgChild2 ? record?.profileSalary[0].orgChild2 : null, - record?.profileSalary[0].orgChild1 ? record?.profileSalary[0].orgChild1 : null, - record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null, + profileSalary.length > 0 && profileSalary[0].orgChild4 ? profileSalary[0].orgChild4 : null, + profileSalary.length > 0 && profileSalary[0].orgChild3 ? profileSalary[0].orgChild3 : null, + profileSalary.length > 0 && profileSalary[0].orgChild2 ? profileSalary[0].orgChild2 : null, + profileSalary.length > 0 && profileSalary[0].orgChild1 ? profileSalary[0].orgChild1 : null, + profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null, ]; + orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); + posNoLeave = profileSalary.length > 0 + ? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}` + : "" } - const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { org: record?.isLeave == false ? org : orgLeave, //สังกัด position: record?.position, //ตำแหน่ง @@ -235,9 +276,9 @@ export class ProfileGovernmentEmployeeController extends Controller { : `${record?.posType?.posTypeShortName ?? ""} ${record?.posLevel?.posLevelName ?? ""}`, //ระดับ posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record && record?.profileSalary.length > 0 + : posNoLeave/*record && record?.profileSalary.length > 0 ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` - : null, //เลขที่ตำแหน่ง + : null*/, //เลขที่ตำแหน่ง posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ @@ -265,29 +306,29 @@ export class ProfileGovernmentEmployeeController extends Controller { const record = await this.profileEmployeeRepo.findOne({ where: { id: profileEmployeeId, - profileSalary:{ - commandCode: In([ - "0", - "9", - "1", - "2", - "3", - "4", - "8", - "10", - "11", - "12", - "13", - "14", - "15", - "16", - ]), - } + // profileSalary:{ + // commandCode: In([ + // "0", + // "9", + // "1", + // "2", + // "3", + // "4", + // "8", + // "10", + // "11", + // "12", + // "13", + // "14", + // "15", + // "16", + // ]), + // } }, relations: { posType: true, posLevel: true, - profileSalary: true + // profileSalary: true }, }); const posMaster = await this.posMasterRepo.findOne({ @@ -329,16 +370,55 @@ export class ProfileGovernmentEmployeeController extends Controller { } } let _OrgLeave:any = [] - if (record?.isLeave && record?.profileSalary.length > 0) { + let orgLeave:string = "" + let posNoLeave:string = "" + if (record?.isLeave /*&& record?.profileSalary.length > 0*/) { + const profileSalary = await this.salaryRepo.find({ + select: [ + "orgRoot", + "orgChild1", + "orgChild2", + "orgChild3", + "orgChild4", + "posNoAbb", + "posNo" + ], + where: { + profileEmployeeId: profileEmployeeId, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + order: { + order: "DESC", + createdAt: "DESC" + } + }); _OrgLeave = [ - record?.profileSalary[0].orgChild4 ? record?.profileSalary[0].orgChild4 : null, - record?.profileSalary[0].orgChild3 ? record?.profileSalary[0].orgChild3 : null, - record?.profileSalary[0].orgChild2 ? record?.profileSalary[0].orgChild2 : null, - record?.profileSalary[0].orgChild1 ? record?.profileSalary[0].orgChild1 : null, - record?.profileSalary[0].orgRoot ? record?.profileSalary[0].orgRoot : null, + profileSalary.length > 0 && profileSalary[0].orgChild4 ? profileSalary[0].orgChild4 : null, + profileSalary.length > 0 && profileSalary[0].orgChild3 ? profileSalary[0].orgChild3 : null, + profileSalary.length > 0 && profileSalary[0].orgChild2 ? profileSalary[0].orgChild2 : null, + profileSalary.length > 0 && profileSalary[0].orgChild1 ? profileSalary[0].orgChild1 : null, + profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null, ]; + orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); + posNoLeave = profileSalary.length > 0 + ? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}` + : "" } - const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { org: record?.isLeave == false ? org : orgLeave, //สังกัด position: record?.position, //ตำแหน่ง @@ -350,9 +430,9 @@ export class ProfileGovernmentEmployeeController extends Controller { ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record && record.profileSalary.length > 0 + : posNoLeave/*record && record.profileSalary.length > 0 ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` - : null, //เลขที่ตำแหน่ง + : null*/, //เลขที่ตำแหน่ง posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ