From 7eae9d2c8d264e07f2a93e6ccf6bbffbd2054e22 Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Wed, 1 Oct 2025 08:59:18 +0700 Subject: [PATCH 01/12] =?UTF-8?q?=E0=B8=A5=E0=B8=9A=E0=B8=84=E0=B8=99?= =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=88=E0=B8=B2=E0=B8=81=E0=B9=82?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 5ad7c11c..83b407a6 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -7915,4 +7915,31 @@ export class OrganizationController extends Controller { return new HttpSuccess(); } + + /** + * API ลบคนในโครงสร้าง + * + * @summary - ลบคนในโครงสร้าง (ADMIN) + * + */ + @Get("delete/profile/org/{orgRevisionId}") + async deleteRetireInOrg(@Path() orgRevisionId: string, @Request() request: RequestWithUser) { + const posMasters = await this.posMasterRepository.find({ + where: { + orgRevisionId: orgRevisionId, + current_holder: { + isLeave: true, + }, + }, + }); + + await Promise.all( + posMasters.map(async (posMaster) => { + posMaster.current_holderId = null; + await this.posMasterRepository.save(posMaster); + }), + ); + + return new HttpSuccess(); + } } From a366e5ca0d9ea51ba57f797b7bee225a0e2feb43 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 1 Oct 2025 11:33:00 +0700 Subject: [PATCH 02/12] update scrip update retire --- src/controllers/OrganizationController.ts | 125 ++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 83b407a6..e6ceb790 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -1,3 +1,5 @@ +import { ProfileSalaryHistory } from "./../entities/ProfileSalaryHistory"; +import { ProfileSalary } from "./../entities/ProfileSalary"; import { Controller, Get, @@ -31,6 +33,7 @@ import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PermissionOrg } from "../entities/PermissionOrg"; +import { deleteUser } from "../keycloak"; @Route("api/v1/org") @Tags("Organization") @@ -51,6 +54,9 @@ export class OrganizationController extends Controller { private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg); + private profileSalaryRepository = AppDataSource.getRepository(ProfileSalary); + private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); + private orgRevisionRepo = AppDataSource.getRepository(OrgRevision); /** * API ล้างข้อมูล @@ -7942,4 +7948,123 @@ export class OrganizationController extends Controller { return new HttpSuccess(); } + + /** + * API บันทึกลงประวัติตำแหน่ง + * + * @summary - แก้ไขเหตุผลการลาออก และปลดจาก keycloak (ADMIN) + * + */ + @Get("save/profile/position-history") + async saveRetireToPositionHistory(request: RequestWithUser) { + const profileLeave = await this.profileRepo.find({ + where: { + isLeave: true, + leaveType: "RETIRE", + }, + relations: [ + "posType", + "posLevel", + "current_holders", + "current_holders.orgRoot", + "current_holders.orgChild1", + "current_holders.orgChild2", + "current_holders.orgChild3", + "current_holders.orgChild4", + "current_holders.positions", + "current_holders.positions.posExecutive", + ], + }); + + const batchSize = 1000; + for (let i = 0; i < profileLeave.length; i += batchSize) { + const batch = profileLeave.slice(i, i + batchSize); + await Promise.all( + batch.map(async (profile: any) => { + const dest_item = await this.profileSalaryRepository.findOne({ + where: { profileId: profile.id }, + order: { order: "DESC" }, + }); + const data: any = { + order: dest_item == null ? 1 : dest_item.order + 1, + amount: null, + positionSalaryAmount: null, + mouthSalaryAmount: null, + profileId: profile.id, + posNo: "-", + positionExecutive: "-", + positionType: "-", + positionLevel: "-", + amountSpecial: null, + orgRoot: null, + orgChild1: null, + orgChild2: null, + orgChild3: null, + orgChild4: null, + commandYear: new Date().getFullYear() + 543, + commandDateAffect: profile.dateLeave, + commandCode: "16", + commandName: "พ้นจากราชการ", + posNoAbb: "-", + isEntry: false, + positionName: "เกษียณอายุราชการ", + createdUserId: request.user.sub, + createdFullName: request.user.name, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + remark: "ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. 31 มี.ค. 68", // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง + isGovernment: false, + }; + + delete data.id; + + const history = new ProfileSalaryHistory(); + Object.assign(history, { ...data, id: undefined }); + data.dateGovernment = profile.dateLeave; + await this.profileSalaryRepository.save(data); + history.profileSalaryId = data.id; + await this.salaryHistoryRepo.save(history); + }), + ); + } + + return new HttpSuccess(); + } + + /** + * API แก้ไขเหตุผลการลาออก และปลดจาก keycloak + * + * @summary - แก้ไขเหตุผลการลาออก และปลดจาก keycloak (ADMIN) + * + */ + @Get("update/profile/leave-reason") + async updateRetireReason() { + const profileLeave = await this.profileRepo.find({ + where: { + isLeave: true, + leaveType: "RETIRE", + }, + }); + + const batchSize = 1000; + for (let i = 0; i < profileLeave.length; i += batchSize) { + const batch = profileLeave.slice(i, i + batchSize); + await Promise.all( + batch.map(async (profile) => { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.leaveReason = "เกษียณอายุราชการ"; + profile.keycloak = ""; + profile.isActive = false; + profile.roleKeycloaks = []; + await this.profileRepo.save(profile); + } + }), + ); + } + + return new HttpSuccess(); + } } From aff6958149d2da76632f8b598306fd2c0ff6f8b4 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 1 Oct 2025 12:10:27 +0700 Subject: [PATCH 03/12] fix error script retire --- src/controllers/OrganizationController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index e6ceb790..702e857f 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -7956,7 +7956,7 @@ export class OrganizationController extends Controller { * */ @Get("save/profile/position-history") - async saveRetireToPositionHistory(request: RequestWithUser) { + async saveRetireToPositionHistory(@Request() request: RequestWithUser) { const profileLeave = await this.profileRepo.find({ where: { isLeave: true, From 08af004d4acde11710b5f11c4a2e83c507f57260 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 1 Oct 2025 13:01:54 +0700 Subject: [PATCH 04/12] fix script update retire of 2569 --- src/controllers/OrganizationController.ts | 152 +++++++++++----------- 1 file changed, 74 insertions(+), 78 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 702e857f..068170f6 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -56,7 +56,6 @@ export class OrganizationController extends Controller { private permissionOrgRepository = AppDataSource.getRepository(PermissionOrg); private profileSalaryRepository = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); - private orgRevisionRepo = AppDataSource.getRepository(OrgRevision); /** * API ล้างข้อมูล @@ -7939,14 +7938,18 @@ export class OrganizationController extends Controller { }, }); + let check = 0; await Promise.all( posMasters.map(async (posMaster) => { posMaster.current_holderId = null; await this.posMasterRepository.save(posMaster); + check += 1; }), ); - return new HttpSuccess(); + // จำนวนคนที่ถูกลบออกจากโครงสร้าง + const total = posMasters.length; + return new HttpSuccess({ total, successAmount: check }); } /** @@ -7962,75 +7965,64 @@ export class OrganizationController extends Controller { isLeave: true, leaveType: "RETIRE", }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - "current_holders.positions", - "current_holders.positions.posExecutive", - ], }); - const batchSize = 1000; - for (let i = 0; i < profileLeave.length; i += batchSize) { - const batch = profileLeave.slice(i, i + batchSize); - await Promise.all( - batch.map(async (profile: any) => { - const dest_item = await this.profileSalaryRepository.findOne({ - where: { profileId: profile.id }, - order: { order: "DESC" }, - }); - const data: any = { - order: dest_item == null ? 1 : dest_item.order + 1, - amount: null, - positionSalaryAmount: null, - mouthSalaryAmount: null, - profileId: profile.id, - posNo: "-", - positionExecutive: "-", - positionType: "-", - positionLevel: "-", - amountSpecial: null, - orgRoot: null, - orgChild1: null, - orgChild2: null, - orgChild3: null, - orgChild4: null, - commandYear: new Date().getFullYear() + 543, - commandDateAffect: profile.dateLeave, - commandCode: "16", - commandName: "พ้นจากราชการ", - posNoAbb: "-", - isEntry: false, - positionName: "เกษียณอายุราชการ", - createdUserId: request.user.sub, - createdFullName: request.user.name, - lastUpdateUserId: request.user.sub, - lastUpdateFullName: request.user.name, - createdAt: new Date(), - lastUpdatedAt: new Date(), - remark: "ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. 31 มี.ค. 68", // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง - isGovernment: false, - }; + let check: number = 0; + await Promise.all( + profileLeave.map(async (profile: any) => { + const dest_item = await this.profileSalaryRepository.findOne({ + where: { profileId: profile.id }, + order: { order: "DESC" }, + }); + const data: any = { + order: dest_item == null ? 1 : dest_item.order + 1, + amount: null, + positionSalaryAmount: null, + mouthSalaryAmount: null, + profileId: profile.id, + posNo: null, + positionExecutive: null, + positionType: null, + positionLevel: null, + amountSpecial: null, + orgRoot: null, + orgChild1: null, + orgChild2: null, + orgChild3: null, + orgChild4: null, + commandYear: new Date().getFullYear() + 543, + commandDateAffect: profile.dateLeave, + commandCode: "16", + commandName: "พ้นจากราชการ", + posNoAbb: null, + isEntry: false, + positionName: "เกษียณอายุราชการ", + createdUserId: request.user.sub, + createdFullName: request.user.name, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + remark: "ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. 31 มี.ค. 68", // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง + isGovernment: false, + }; - delete data.id; + const history = new ProfileSalaryHistory(); + Object.assign(history, { ...data, id: undefined }); + data.dateGovernment = profile.dateLeave; + const savedData = await this.profileSalaryRepository.save(data); - const history = new ProfileSalaryHistory(); - Object.assign(history, { ...data, id: undefined }); - data.dateGovernment = profile.dateLeave; - await this.profileSalaryRepository.save(data); - history.profileSalaryId = data.id; - await this.salaryHistoryRepo.save(history); - }), - ); - } + history.profileSalaryId = savedData.id; + await this.salaryHistoryRepo.save(history); - return new HttpSuccess(); + check += 1; + }), + ); + + // จำนวนคนที่บันทึกลงประวัติตำแหน่ง + const total = profileLeave.length; + // จำนวนคนที่ถูกบันทึกลงประวัติตำแหน่งสำเร็จ + return new HttpSuccess({ total, successAmount: check }); } /** @@ -8048,23 +8040,27 @@ export class OrganizationController extends Controller { }, }); - const batchSize = 1000; - for (let i = 0; i < profileLeave.length; i += batchSize) { - const batch = profileLeave.slice(i, i + batchSize); - await Promise.all( - batch.map(async (profile) => { + let check: number = 0; + await Promise.all( + profileLeave.map(async (profile) => { + profile.leaveReason = "เกษียณอายุราชการ"; + profile.isActive = false; + + if (profile.keycloak != null) { const delUserKeycloak = await deleteUser(profile.keycloak); if (delUserKeycloak) { - profile.leaveReason = "เกษียณอายุราชการ"; profile.keycloak = ""; - profile.isActive = false; profile.roleKeycloaks = []; - await this.profileRepo.save(profile); + check += 1; } - }), - ); - } + } - return new HttpSuccess(); + await this.profileRepo.save(profile); + }), + ); + + // จำนวนคนที่ถูกแก้ไขเหตุผลการลาออก + const total = profileLeave.length; + return new HttpSuccess({ total, successAmount: check }); } } From 18aa974c3d23078c7468fa023634409d7e588f18 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 1 Oct 2025 16:31:40 +0700 Subject: [PATCH 05/12] update --- src/controllers/ProfileController.ts | 2 +- src/controllers/ProfileEmployeeController.ts | 2 +- .../ProfileGovernmentController.ts | 74 ++++++++++++++----- .../ProfileGovernmentEmployeeController.ts | 74 ++++++++++++++----- 4 files changed, 114 insertions(+), 38 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 33d33227..636a4e48 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5888,7 +5888,7 @@ export class ProfileController extends Controller { ) // .andWhere("profile.leaveCommandId Is NOT NULL") .andWhere( - "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id)", + "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and profileSalary.positionName != 'เกษียณอายุราชการ')", ) .andWhere( diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 04b43f87..4bc85898 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2786,7 +2786,7 @@ export class ProfileEmployeeController extends Controller { ) // .andWhere("profileEmployee.leaveCommandId Is NOT NULL") .andWhere( - "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id)", + "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id and profileSalary.positionName != 'เกษียณอายุราชการ')", ) // .andWhere( diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 6f63bd0e..8abe6617 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -237,14 +237,33 @@ export class ProfileGovernmentHistoryController extends Controller { } } let _OrgLeave:any = [] + let _profileSalary:any = null; 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, - ]; + // _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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { @@ -254,8 +273,8 @@ export class ProfileGovernmentHistoryController extends Controller { posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record && record?.profileSalary.length > 0 - ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` + : _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : null, //เลขที่ตำแหน่ง posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: @@ -373,14 +392,33 @@ export class ProfileGovernmentHistoryController extends Controller { } } let _OrgLeave:any = [] + let _profileSalary:any = null; 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, - ]; + // _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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { @@ -393,8 +431,8 @@ export class ProfileGovernmentHistoryController extends Controller { ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record && record.profileSalary.length > 0 - ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` + : _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : null, //เลขที่ตำแหน่ง posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 0cfd43e3..9191eb2e 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -220,6 +220,7 @@ export class ProfileGovernmentEmployeeController extends Controller { let _OrgLeave:any = [] let orgLeave:string = "" let posNoLeave:string = "" + let _profileSalary:any = null; if (record?.isLeave /*&& record?.profileSalary.length > 0*/) { const profileSalary = await this.salaryRepo.find({ select: [ @@ -255,16 +256,34 @@ export class ProfileGovernmentEmployeeController extends Controller { createdAt: "DESC" } }); - _OrgLeave = [ - 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 = [ + // 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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); - posNoLeave = profileSalary.length > 0 - ? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}` + posNoLeave = _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : "" } const data = { @@ -372,6 +391,7 @@ export class ProfileGovernmentEmployeeController extends Controller { let _OrgLeave:any = [] let orgLeave:string = "" let posNoLeave:string = "" + let _profileSalary:any = null; if (record?.isLeave /*&& record?.profileSalary.length > 0*/) { const profileSalary = await this.salaryRepo.find({ select: [ @@ -407,16 +427,34 @@ export class ProfileGovernmentEmployeeController extends Controller { createdAt: "DESC" } }); - _OrgLeave = [ - 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 = [ + // 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, + // ]; + if (record.leaveType == "RETIRE") { + _profileSalary = record?.profileSalary.length > 1 + ? record?.profileSalary[1] + : null; + } else { + _profileSalary = record?.profileSalary[0]; + } + if (_profileSalary) { + _OrgLeave = [ + _profileSalary.orgChild4 ?? null, + _profileSalary.orgChild3 ?? null, + _profileSalary.orgChild2 ?? null, + _profileSalary.orgChild1 ?? null, + _profileSalary.orgRoot ?? null, + ]; + } else { + _OrgLeave = []; + } orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); - posNoLeave = profileSalary.length > 0 - ? `${profileSalary[0].posNoAbb} ${profileSalary[0].posNo}` + posNoLeave = _profileSalary != null + ? `${_profileSalary.posNoAbb} ${_profileSalary.posNo}` : "" } const data = { From d8d376386d9fc39ccdc03e888ffc8b8ad16909bc Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 1 Oct 2025 16:37:23 +0700 Subject: [PATCH 06/12] fix --- src/controllers/OrganizationController.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 068170f6..c12b1a72 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -8041,17 +8041,21 @@ export class OrganizationController extends Controller { }); let check: number = 0; + let notDelete: string[] = []; await Promise.all( profileLeave.map(async (profile) => { profile.leaveReason = "เกษียณอายุราชการ"; profile.isActive = false; - if (profile.keycloak != null) { + if (profile.keycloak != null && profile.keycloak != "") { const delUserKeycloak = await deleteUser(profile.keycloak); if (delUserKeycloak) { profile.keycloak = ""; profile.roleKeycloaks = []; check += 1; + } else { + // push array not delete + notDelete.push(profile.keycloak); } } @@ -8061,6 +8065,6 @@ export class OrganizationController extends Controller { // จำนวนคนที่ถูกแก้ไขเหตุผลการลาออก const total = profileLeave.length; - return new HttpSuccess({ total, successAmount: check }); + return new HttpSuccess({ total, successAmount: check, notDelete }); } } From 77918a4b6b0c5836066a4919a764877958b56d77 Mon Sep 17 00:00:00 2001 From: Adisak Date: Wed, 1 Oct 2025 17:41:27 +0700 Subject: [PATCH 07/12] sort --- src/controllers/ProfileController.ts | 36 ++++++++++++++++++-- src/controllers/ProfileEmployeeController.ts | 36 ++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 33d33227..76950695 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -9781,6 +9781,8 @@ export class ProfileController extends Controller { rootId?: string; year: number; period: string; + sortBy?: string; + descending?: boolean; }, ) { const findRevision = await this.orgRevisionRepo.findOne({ @@ -9790,7 +9792,7 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster) + let query = await AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.current_holder", "current_holder") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") @@ -9923,7 +9925,37 @@ export class ProfileController extends Controller { ); }), ) - .orderBy("current_holder.citizenId", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posType"){ + query = query.orderBy( + `posType.posTypeName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "posLevel"){ + query = query.orderBy( + `posLevel.posLevelName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "orgShortName" || body.sortBy === "posMasterNo"){ + query = query + .orderBy(`orgRoot.orgRootShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild1.orgChild1ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild2.orgChild2ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild3.orgChild3ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild4.orgChild4ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`posMaster.posMasterNo`,body.descending ? "DESC" : "ASC") + }else{ + query = query.orderBy( + `current_holder.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("current_holder.citizenId", "ASC") + } + + const [findPosMaster, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 04b43f87..6b1ec5f4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -4981,6 +4981,8 @@ export class ProfileEmployeeController extends Controller { rootId?: string; year: number; period: string; + sortBy?: string; + descending?: boolean; }, ) { const findRevision = await this.orgRevisionRepo.findOne({ @@ -4990,7 +4992,7 @@ export class ProfileEmployeeController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - const [findPosMaster, total] = await AppDataSource.getRepository(EmployeePosMaster) + let query = await AppDataSource.getRepository(EmployeePosMaster) .createQueryBuilder("employeePosMaster") .leftJoinAndSelect("employeePosMaster.current_holder", "current_holder") .leftJoinAndSelect("employeePosMaster.orgRoot", "orgRoot") @@ -5122,10 +5124,40 @@ export class ProfileEmployeeController extends Controller { ); }), ) - .orderBy("current_holder.citizenId", "ASC") + + if (body.sortBy) { + if(body.sortBy === "posType"){ + query = query.orderBy( + `posType.posTypeName`, + body.descending ? "DESC" : "ASC" + ); + }else if(body.sortBy === "posLevel"){ + query = query + .orderBy(`posType.posTypeShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`posLevel.posLevelName`,body.descending ? "DESC" : "ASC"); + }else if(body.sortBy === "orgShortName" || body.sortBy === "posMasterNo"){ + query = query + .orderBy(`orgRoot.orgRootShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild1.orgChild1ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild2.orgChild2ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild3.orgChild3ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`orgChild4.orgChild4ShortName`,body.descending ? "DESC" : "ASC") + .addOrderBy(`employeePosMaster.posMasterNo`,body.descending ? "DESC" : "ASC") + }else{ + query = query.orderBy( + `current_holder.${body.sortBy}`, + body.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("current_holder.citizenId", "ASC") + } + + const [findPosMaster, total] = await query .skip((body.page - 1) * body.pageSize) .take(body.pageSize) .getManyAndCount(); + if (!findPosMaster) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. PosMaster"); } From e5dfed9312d32ac3d7d2a0d9c8599fce8ba82858 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 1 Oct 2025 17:58:36 +0700 Subject: [PATCH 08/12] fix query --- src/controllers/ProfileController.ts | 2 +- src/controllers/ProfileEmployeeController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index bc02a392..e6f4c1e7 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -5888,7 +5888,7 @@ export class ProfileController extends Controller { ) // .andWhere("profile.leaveCommandId Is NOT NULL") .andWhere( - "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and profileSalary.positionName != 'เกษียณอายุราชการ')", + "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileId = profile.id and ps.positionName != 'เกษียณอายุราชการ')", ) .andWhere( diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 076881de..7ee64703 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2786,7 +2786,7 @@ export class ProfileEmployeeController extends Controller { ) // .andWhere("profileEmployee.leaveCommandId Is NOT NULL") .andWhere( - "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id and profileSalary.positionName != 'เกษียณอายุราชการ')", + "profileSalary.order = (SELECT MAX(ps.order) FROM profileSalary ps WHERE ps.profileEmployeeId = profileEmployee.id and ps.positionName != 'เกษียณอายุราชการ')", ) // .andWhere( From 7ffb698252593136ddee6de15df901697c99c682 Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 1 Oct 2025 22:21:16 +0700 Subject: [PATCH 09/12] =?UTF-8?q?test=20job=20=E0=B9=80=E0=B8=81=E0=B8=A9?= =?UTF-8?q?=E0=B8=B5=E0=B8=A2=E0=B8=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 3 +- src/controllers/CommandController.ts | 162 ++++++++++++++++++++++++--- 2 files changed, 149 insertions(+), 16 deletions(-) diff --git a/src/app.ts b/src/app.ts index 236fb105..fb2c4d5b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -62,7 +62,8 @@ async function main() { } }); - const cronTime_Oct = "0 0 1 10 *"; + // const cronTime_Oct = "0 0 1 10 *"; + const cronTime_Oct = "0 0 2 10 *"; // test 2 ตุลาคม cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 4e5f898e..2f72f709 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1499,6 +1499,7 @@ export class CommandController extends Controller { const today = new Date(); today.setUTCHours(0, 0, 0, 0); let type: string = "OFFICER"; + let _Date = new Date() try { const response_ = await axios.get( process.env.API_URL + `/retirement/update-status/${type}/${today.getFullYear()}`, @@ -1510,23 +1511,46 @@ export class CommandController extends Controller { }, }, ); - if (response && response_.data.result.length > 0) { - let profiles: Profile[] = []; + if (response_ && response_.data.result) { + let signDate:string = "" + if (response_.data.result.signDate != null) { + signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)) + } + else { + signDate = Extension.ToThaiShortDate_noPrefix(_Date) + } + // let profiles: Profile[] = []; await Promise.all( - response_.data.result.map(async (x: any) => { + response_.data.result.profiles.map(async (x: any) => { const _profile = await this.profileRepository.findOneBy({ id: x.profileId }); if (_profile) { + // console.log("1. บันทึกลงประวัติตำแหน่ง") + await this.profileSalaryRetire(x.profileId, type, signDate, _Date); + // console.log("2. ปลดออกจากโครงสร้าง") + await this.posMasterRetire(x.profileId, type, _Date); + // console.log("3. แก้ไขสถานะในทะเบียนประวัติ") _profile.isRetirement = true; _profile.isLeave = true; + _profile.isActive = false _profile.leaveType = "RETIRE"; - _profile.leaveDate = new Date(); - _profile.dateLeave = new Date(); - _profile.lastUpdatedAt = new Date(); - profiles.push(_profile); + _profile.leaveReason = "เกษียณอายุราชการ"; + _profile.leaveDate = _Date; + _profile.dateLeave = _Date; + _profile.lastUpdatedAt = _Date; + if (_profile.keycloak != null && _profile.keycloak != "") { + // console.log("4. disable keycloak/authen") + const delUserKeycloak = await deleteUser(_profile.keycloak); + if (delUserKeycloak) { + _profile.keycloak = ""; + _profile.roleKeycloaks = []; + } + } + // profiles.push(_profile); + // console.log("5. save profile ",_profile) + await this.profileRepository.save(_profile); } }), ); - await this.profileRepository.save(profiles); } } catch {} @@ -1542,29 +1566,137 @@ export class CommandController extends Controller { }, }, ); - if (response && response_.data.result.length > 0) { - let profiles: ProfileEmployee[] = []; + if (response_ && response_.data.result) { + let signDate:string = "" + if (response_.data.result.signDate != null) { + signDate = Extension.ToThaiShortDate_noPrefix(new Date(response_.data.result.signDate)) + } + else { + signDate = Extension.ToThaiShortDate_noPrefix(_Date) + } + // let profiles: ProfileEmployee[] = []; await Promise.all( response_.data.result.map(async (x: any) => { const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId }); if (_profileEmp) { + // บันทึกลงประวัติตำแหน่ง + await this.profileSalaryRetire(x.profileId, type, signDate, _Date); + // ปลดออกจากโครงสร้าง + await this.posMasterRetire(x.profileId, type, _Date); + // แก้ไขสถานะในทะเบียนประวัติ _profileEmp.isRetirement = true; _profileEmp.isLeave = true; + _profileEmp.isActive = false _profileEmp.leaveType = "RETIRE"; - _profileEmp.leaveDate = new Date(); - _profileEmp.dateLeave = new Date(); - _profileEmp.lastUpdatedAt = new Date(); - profiles.push(_profileEmp); + _profileEmp.leaveReason = "เกษียณอายุราชการ"; + _profileEmp.leaveDate = _Date; + _profileEmp.dateLeave = _Date; + _profileEmp.lastUpdatedAt = _Date; + if (_profileEmp.keycloak != null && _profileEmp.keycloak != "") { + // disable keycloak/authen + const delUserKeycloak = await deleteUser(_profileEmp.keycloak); + if (delUserKeycloak) { + _profileEmp.keycloak = ""; + _profileEmp.roleKeycloaks = []; + } + } + // profiles.push(_profileEmp); + await this.profileEmployeeRepository.save(_profileEmp); } }), ); - await this.profileEmployeeRepository.save(profiles); } } catch {} return new HttpSuccess(); } + async profileSalaryRetire(profileId: string, type: string, signDate: string, _Date: Date) { + const whereKey = type == "OFFICER" + ? { profileId: profileId } + : { profileEmployeeId: profileId }; + const maxOrder = await this.salaryRepo.findOne({ + select: { order: true }, + where: whereKey, + order: { order: "DESC" }, + }); + const data: any = { + order: maxOrder ? maxOrder.order + 1 : 1, + amount: null, + positionSalaryAmount: null, + mouthSalaryAmount: null, + profileId: profileId, + posNo: null, + positionExecutive: null, + positionType: null, + positionLevel: null, + amountSpecial: null, + orgRoot: null, + orgChild1: null, + orgChild2: null, + orgChild3: null, + orgChild4: null, + commandYear: _Date.getFullYear() + 543, + commandDateAffect: _Date, + commandCode: "16", + commandName: "พ้นจากราชการ", + posNoAbb: null, + isEntry: false, + positionName: "เกษียณอายุราชการ", + createdUserId: "", + createdFullName: "System Administrator", + lastUpdateUserId: "", + lastUpdateFullName: "System Administrator", + createdAt: _Date, + lastUpdatedAt: _Date, + remark: `ประกาศคณะอนุกรรมการสามัญข้าราชการกรุงเทพมหานครสามัญ ลว. ${signDate}`, // script เกษียณจริง ๆ ให้เอา “วันที่ประกาศเกษียณฉบับแรก” มาลงในเอกสารอ้างอิง + isGovernment: false, + }; + const history = new ProfileSalaryHistory(); + Object.assign(history, { ...data, id: undefined }); + data.dateGovernment = _Date; + const savedData = await this.salaryRepo.save(data); + history.profileSalaryId = savedData.id; + await this.salaryHistoryRepo.save(history); + } + + async posMasterRetire(profileId: string, type: string, _Date: Date) { + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } + }); + if (orgRevision) { + let _posMaster:any = null; + if (type == "OFFICER") { + _posMaster = await this.posMasterRepository.findOne({ + where: { + orgRevisionId: orgRevision.id, + current_holderId: profileId, + }, + }); + if (_posMaster) { + _posMaster.current_holderId = null; + _posMaster.lastUpdateFullName = "System Administrator"; + _posMaster.lastUpdatedAt = _Date; + await this.posMasterRepository.save(_posMaster); + } + } + else if (type == "EMPLOYEE") { + _posMaster = await this.employeePosMasterRepository.findOne({ + where: { + orgRevisionId: orgRevision.id, + current_holderId: profileId, + }, + }); + if (_posMaster) { + _posMaster.current_holderId = null; + _posMaster.lastUpdateFullName = "System Administrator"; + _posMaster.lastUpdatedAt = _Date; + await this.employeePosMasterRepository.save(_posMaster); + } + } + } + } + @Get("cornjob/cronjobUpdateRetirementStatus") async runCronjobUpdateRetirementStatus() { await this.cronjobUpdateRetirementStatus(); From 6b719049b09ead7b541b09db57728d08926c7157 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 2 Oct 2025 11:40:01 +0700 Subject: [PATCH 10/12] =?UTF-8?q?update=20script=20=E0=B8=A3=E0=B8=B1?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= =?UTF-8?q?=20#169?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 13 +++++++--- .../ProfileGovernmentController.ts | 16 +++++++++---- .../ProfileGovernmentEmployeeController.ts | 24 ++++++++++++------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 2f72f709..68bd0588 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1478,7 +1478,7 @@ export class CommandController extends Controller { return new HttpSuccess(); } - async cronjobUpdateRetirementStatus() { + async cronjobUpdateRetirementStatus(/*@Request() request: RequestWithUser*/) { let body = { client_id: "gettoken", client_secret: process.env.AUTH_ACCOUNT_SECRET, @@ -1576,7 +1576,7 @@ export class CommandController extends Controller { } // let profiles: ProfileEmployee[] = []; await Promise.all( - response_.data.result.map(async (x: any) => { + response_.data.result.profiles.map(async (x: any) => { const _profileEmp = await this.profileEmployeeRepository.findOneBy({ id: x.profileId }); if (_profileEmp) { // บันทึกลงประวัติตำแหน่ง @@ -1625,7 +1625,6 @@ export class CommandController extends Controller { amount: null, positionSalaryAmount: null, mouthSalaryAmount: null, - profileId: profileId, posNo: null, positionExecutive: null, positionType: null, @@ -1655,6 +1654,14 @@ export class CommandController extends Controller { const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); data.dateGovernment = _Date; + if (type == "OFFICER") { + data.profileId = profileId; + data.profileEmployeeId = null; + } + else if (type == "EMPLOYEE"){ + data.profileEmployeeId = profileId; + data.profileId = null; + } const savedData = await this.salaryRepo.save(data); history.profileSalaryId = savedData.id; await this.salaryHistoryRepo.save(history); diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 8abe6617..f2acbaba 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -249,9 +249,13 @@ export class ProfileGovernmentHistoryController extends Controller { if (record.leaveType == "RETIRE") { _profileSalary = record?.profileSalary.length > 1 ? record?.profileSalary[1] - : null; + : record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } if (_profileSalary) { _OrgLeave = [ @@ -404,9 +408,13 @@ export class ProfileGovernmentHistoryController extends Controller { if (record.leaveType == "RETIRE") { _profileSalary = record?.profileSalary.length > 1 ? record?.profileSalary[1] - : null; + : record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = record?.profileSalary.length > 0 + ? record?.profileSalary[0] + : null; } if (_profileSalary) { _OrgLeave = [ diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 9191eb2e..ce170d17 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -264,11 +264,15 @@ export class ProfileGovernmentEmployeeController extends Controller { // profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null, // ]; if (record.leaveType == "RETIRE") { - _profileSalary = record?.profileSalary.length > 1 - ? record?.profileSalary[1] - : null; + _profileSalary = profileSalary.length > 1 + ? profileSalary[1] + : profileSalary.length > 0 + ? profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = profileSalary.length > 0 + ? profileSalary[0] + : null } if (_profileSalary) { _OrgLeave = [ @@ -435,11 +439,15 @@ export class ProfileGovernmentEmployeeController extends Controller { // profileSalary.length > 0 && profileSalary[0].orgRoot ? profileSalary[0].orgRoot : null, // ]; if (record.leaveType == "RETIRE") { - _profileSalary = record?.profileSalary.length > 1 - ? record?.profileSalary[1] - : null; + _profileSalary = profileSalary.length > 1 + ? profileSalary[1] + : profileSalary.length > 0 + ? profileSalary[0] + : null; } else { - _profileSalary = record?.profileSalary[0]; + _profileSalary = profileSalary.length > 0 + ? profileSalary[0] + : null; } if (_profileSalary) { _OrgLeave = [ From 364e69729319a51676551b515c691b69acd66b25 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 2 Oct 2025 11:42:01 +0700 Subject: [PATCH 11/12] revert --- src/app.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index fb2c4d5b..236fb105 100644 --- a/src/app.ts +++ b/src/app.ts @@ -62,8 +62,7 @@ async function main() { } }); - // const cronTime_Oct = "0 0 1 10 *"; - const cronTime_Oct = "0 0 2 10 *"; // test 2 ตุลาคม + const cronTime_Oct = "0 0 1 10 *"; cron.schedule(cronTime_Oct, async () => { try { const commandController = new CommandController(); From 4be0b068bcc0030b7e2e12a4448b05af8ffaa853 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 2 Oct 2025 14:37:25 +0700 Subject: [PATCH 12/12] #170 and calAge --- src/controllers/OrganizationDotnetController.ts | 4 ++-- src/controllers/ProfileEmployeeController.ts | 6 +++--- src/controllers/ProfileEmployeeTempController.ts | 4 ++-- src/controllers/ProfileSalaryTempController.ts | 2 +- src/interfaces/extension.ts | 6 ++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 415759af..38e17b06 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -5521,7 +5521,7 @@ export class OrganizationDotnetController extends Controller { govAge: profile.dateAppoint ? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี` : "-", - age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0) : "-", + age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET") : "-", dateAppoint: profile.dateAppoint, dateCurrent: new Date(), amount: profile.amount ?? "-", @@ -5636,7 +5636,7 @@ export class OrganizationDotnetController extends Controller { govAge: profile.dateAppoint ? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี` : "-", - age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0) : "-", + age: profile.birthDate ? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET") : "-", dateAppoint: profile.dateAppoint, dateCurrent: new Date(), amount: profile.amount ?? "-", diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 076881de..c1f1db7a 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2127,7 +2127,7 @@ export class ProfileEmployeeController extends Controller { posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), - age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0, "GET"), dateEmployment: dateEmployment, dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, @@ -2995,7 +2995,7 @@ export class ProfileEmployeeController extends Controller { : _data.profileSalary[0].posNo || "", employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), - age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0, "GET"), dateEmployment: dateEmployment, dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, @@ -3417,7 +3417,7 @@ export class ProfileEmployeeController extends Controller { posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), - age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0, "GET"), dateEmployment: dateEmployment, dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index e5d03e4a..12c65e10 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1189,7 +1189,7 @@ export class ProfileEmployeeTempController extends Controller { posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), - age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0, "GET"), dateEmployment: dateEmployment, dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, @@ -1724,7 +1724,7 @@ export class ProfileEmployeeTempController extends Controller { posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), - age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0, "GET"), dateEmployment: dateEmployment, dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index b160f98d..5da8860e 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -878,7 +878,7 @@ export class ProfileSalaryTempController extends Controller { posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), - age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0), + age: Extension.CalculateAgeStrV2(_data.birthDate, 0, 0, "GET"), dateEmployment: dateEmployment, dateAppoint: _data.dateAppoint, dateStart: _data.dateStart, diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 26a12465..c81e66c0 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -309,11 +309,13 @@ class Extension { return years; } - public static CalculateAgeStrV2(date: Date, plusYear: number = 0, subtractYear: number = 0) { + public static CalculateAgeStrV2(date: Date, plusYear: number = 0, subtractYear: number = 0, method?:string) { if (date == null || date == undefined) return ""; const currentDate = new Date(); - if (date > currentDate) { + if (date > currentDate && method !== "GET") { throw new Error("วันเกิดต้องไม่มากกว่าวันที่ปัจจุบัน"); + }else if(date > currentDate && method === "GET"){ + return "" } let years = currentDate.getFullYear() - date.getFullYear();