From 5678f333dbd719597192390ff52c7b7fef941e49 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 25 Aug 2025 18:59:33 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1?= =?UTF-8?q?=E0=B8=B9=E0=B8=A5=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99?= =?UTF-8?q?=E0=B9=88=E0=B8=87=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B9=80=E0=B8=87?= =?UTF-8?q?=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99?= =?UTF-8?q?=20(=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B9=83=E0=B8=99=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=AA=E0=B8=B3?= =?UTF-8?q?=E0=B8=AB=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B9=80=E0=B8=AA=E0=B8=99=E0=B8=AD=E0=B8=82=E0=B8=AD=E0=B8=9E?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A3=E0=B8=B2=E0=B8=8A=E0=B8=97=E0=B8=B2?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=AB=E0=B8=A3=E0=B8=B5=E0=B8=A2=E0=B8=8D?= =?UTF-8?q?=E0=B8=88=E0=B8=B1=E0=B8=81=E0=B8=A3=E0=B8=9E=E0=B8=A3=E0=B8=A3?= =?UTF-8?q?=E0=B8=94=E0=B8=B4=E0=B8=A1=E0=B8=B2=E0=B8=A5=E0=B8=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileInsigniaController.ts | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 4ed9c189..f71f1601 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -26,6 +26,8 @@ import { Profile } from "../entities/Profile"; import { Insignia } from "../entities/Insignia"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; +import { ProfileSalary } from "../entities/ProfileSalary"; +import { In, IsNull } from "typeorm"; @Route("api/v1/org/profile/insignia") @Tags("ProfileInsignia") @Security("bearerAuth") @@ -34,6 +36,7 @@ export class ProfileInsigniaController extends Controller { private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaMetaRepo = AppDataSource.getRepository(Insignia); + private profileSalaryRepo = AppDataSource.getRepository(ProfileSalary); @Get("user") public async getInsigniaUser(@Request() request: { user: Record }) { @@ -258,4 +261,75 @@ export class ProfileInsigniaController extends Controller { return new HttpSuccess(); } + + /** + * @summary ข้อมูลตำแหน่งและเงินเดือน (ใช้ในรายงานประวัติสำหรับการเสนอขอพระราชทานเหรียญจักรพรรดิมาลา) + */ + @Post("position") + public async GetPprofileSalarys( + @Request() req: RequestWithUser, + @Body() body: { profileId: string }, + ) { + const profile = await this.profileRepo.findOneBy({ id: body.profileId }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const profileSalarys = await this.profileSalaryRepo.find({ + where: [ + { + profileId: body.profileId, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + { profileId: body.profileId, commandCode: IsNull() }, + ], + order: { order: "ASC" }, + }); + if (!profileSalarys) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบข้อมูลตำแหน่งและเงินเดือน"); + } + const birth = new Date(profile.birthDate); + const mapData = profileSalarys.map(x => { + // คำนวณอายุ + let age = null; + if (x.commandDateAffect && profile.birthDate) { + const affect = new Date(x.commandDateAffect); + age = affect.getFullYear() - birth.getFullYear(); + // เช็คเดือน/วัน ถ้าวันเกิดยังไม่มาถึงในปีนั้น ให้ลบ 1 + const monthDiff = affect.getMonth() - birth.getMonth(); + const dayDiff = affect.getDate() - birth.getDate(); + if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) { + age--; + } + } + return { + dateAffect: x.commandDateAffect, + position: x.positionName, + root: x.orgRoot, + child1: x.orgChild1, + child2: x.orgChild2, + child3: x.orgChild3, + child4: x.orgChild4, + age: age, + amount: x.amount, + remark: x.remark, + commandCode: x.commandCode + }; + }); + return new HttpSuccess(mapData); + } }