From 354dd4399b1e5c1080c1618a61adae0cef4fab9a Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 24 Jul 2025 17:22:47 +0700 Subject: [PATCH] =?UTF-8?q?Fix=20=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A?= =?UTF-8?q?=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B9=81=E0=B8=9A=E0=B8=9A=E0=B8=A2?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=20=E0=B8=81=E0=B8=A3=E0=B8=93=E0=B8=B5?= =?UTF-8?q?=E0=B8=9E=E0=B9=89=E0=B8=99=E0=B8=AA=E0=B8=A0=E0=B8=B2=E0=B8=9E?= =?UTF-8?q?=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= =?UTF-8?q?=E0=B8=AA=E0=B8=B3=E0=B8=99=E0=B8=B1=E0=B8=81=20&=20=E0=B9=80?= =?UTF-8?q?=E0=B8=A5=E0=B8=82=E0=B8=97=E0=B8=B5=E0=B9=88=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#1673?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileGovernmentController.ts | 94 +++++++++++++++--- .../ProfileGovernmentEmployeeController.ts | 98 ++++++++++++++----- 2 files changed, 158 insertions(+), 34 deletions(-) diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 2d440801..7e8c4e2a 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -16,6 +16,7 @@ import { } from "../interfaces/utils"; import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; +import { In } from "typeorm"; @Route("api/v1/org/profile/government") @Tags("ProfileGovernment") @Security("bearerAuth") @@ -155,7 +156,27 @@ export class ProfileGovernmentHistoryController extends Controller { }, }); const record = await this.profileRepo.findOne({ - where: { id: profileId }, + where: { + id: profileId, + profileSalary: { + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + } + }, relations: ["posType", "posLevel", "profileSalary"], order: { profileSalary: { @@ -215,14 +236,17 @@ export class ProfileGovernmentHistoryController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName ?? ""; } } - const _OrgLeave = [ - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild4 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild3 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild2 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild1 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgRoot : null, - ]; - const orgLeave = _OrgLeave.filter((x) => x !== undefined && x !== null).join("\n"); + let _OrgLeave:any = [] + if (record?.isLeave && record?.profileSalary.length > 0) { + _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, + ]; + } + const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { org: record.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน @@ -264,11 +288,38 @@ export class ProfileGovernmentHistoryController extends Controller { }, }); const record = await this.profileRepo.findOne({ - where: { id: profileId }, + where: { + id: profileId, + profileSalary: { + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + } + }, relations: { posType: true, posLevel: true, + profileSalary: true }, + order: { + profileSalary: { + order: "DESC", + createdAt: "DESC" + } + } }); const posMaster = await this.posMasterRepo.findOne({ where: { @@ -321,12 +372,30 @@ export class ProfileGovernmentHistoryController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName; } } + let _OrgLeave:any = [] + if (record?.isLeave && record?.profileSalary.length > 0) { + _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, + ]; + } + const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: org, //สังกัด + org: record.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน position: record.position, //ตำแหน่ง posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ - posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posMasterNo: + record.isLeave == false + ? posMaster == null + ? null + : `${orgShortName} ${posMaster.posMasterNo}` + : record?.profileSalary.length > 0 + ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : null, //เลขที่ตำแหน่ง posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท posExecutive: position == null || position.posExecutive == null @@ -343,6 +412,7 @@ export class ProfileGovernmentHistoryController extends Controller { govAgeAbsent: record.govAgeAbsent, govAgePlus: record.govAgePlus, reasonSameDate: record.reasonSameDate, + isLeave: record.isLeave }; return new HttpSuccess(data); diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index bae4a59b..32c32006 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -16,6 +16,7 @@ import { } from "../interfaces/utils"; import permission from "../interfaces/permission"; import { OrgRevision } from "../entities/OrgRevision"; +import { In } from "typeorm"; @Route("api/v1/org/profile-employee/government") @Tags("ProfileEmployeeGovernment") @Security("bearerAuth") @@ -147,7 +148,27 @@ export class ProfileGovernmentEmployeeController extends Controller { }, }); const record = await this.profileEmployeeRepo.findOne({ - where: { id: profileEmployeeId }, + where: { + id: profileEmployeeId, + profileSalary: { + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + } + }, relations: ["posType", "posLevel", "profileSalary"], order: { profileSalary: { @@ -194,14 +215,17 @@ export class ProfileGovernmentEmployeeController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName; } } - const _OrgLeave = [ - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild4 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild3 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild2 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgChild1 : null, - record.profileSalary.length > 0 ? record.profileSalary[0].orgRoot : null, - ]; - const orgLeave = _OrgLeave.filter((x) => x !== undefined && x !== null).join("\n"); + let _OrgLeave:any = [] + if (record?.isLeave && record?.profileSalary.length > 0) { + _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, + ]; + } + const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { org: record.isLeave == false ? org : orgLeave, //สังกัด position: record.position, //ตำแหน่ง @@ -239,10 +263,31 @@ export class ProfileGovernmentEmployeeController extends Controller { }, }); const record = await this.profileEmployeeRepo.findOne({ - where: { id: profileEmployeeId }, + where: { + id: profileEmployeeId, + profileSalary:{ + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + } + }, relations: { posType: true, posLevel: true, + profileSalary: true }, }); const posMaster = await this.posMasterRepo.findOne({ @@ -259,16 +304,6 @@ export class ProfileGovernmentEmployeeController extends Controller { orgChild4: true, }, }); - const position = await this.positionRepo.findOne({ - where: { - positionIsSelected: true, - posMaster: { - orgRevisionId: orgRevision?.id, - current_holderId: profileEmployeeId, - }, - }, - order: { createdAt: "DESC" }, - }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ @@ -293,13 +328,31 @@ export class ProfileGovernmentEmployeeController extends Controller { orgShortName = posMaster.orgChild4?.orgChild4ShortName; } } + let _OrgLeave:any = [] + if (record?.isLeave && record?.profileSalary.length > 0) { + _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, + ]; + } + const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: org, //สังกัด + org: record.isLeave == false ? org : orgLeave, //สังกัด position: record.position, //ตำแหน่ง posLevel: record.posLevel == null && record.posType == null ? null : `${record.posType.posTypeShortName} ${record.posLevel.posLevelName}`, //ระดับ - posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posMasterNo: + record.isLeave == false + ? posMaster == null + ? null + : `${orgShortName} ${posMaster.posMasterNo}` + : record?.profileSalary.length > 0 + ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : null, //เลขที่ตำแหน่ง posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ @@ -311,6 +364,7 @@ export class ProfileGovernmentEmployeeController extends Controller { govAgeAbsent: record.govAgeAbsent ?? null, // ขาดราชการ govAgePlus: record.govAgePlus, // อายุราชการเกื้อกูล dateRetireLaw: record.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย + isLeave: record.isLeave }; return new HttpSuccess(data); }