From 8cd69646c1c9267911b34f08f7cf7b21b6612b14 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 13 Mar 2025 14:15:28 +0700 Subject: [PATCH 1/2] =?UTF-8?q?fix=20issue=20#1238=20:=20=E0=B8=81?= =?UTF-8?q?=E0=B8=A3=E0=B8=93=E0=B8=B5=E0=B8=96=E0=B8=B6=E0=B8=87=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=88=E0=B8=81=E0=B8=A3=E0=B8=A3=E0=B8=A1=E0=B8=9B?= =?UTF-8?q?=E0=B8=A5=E0=B8=94=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=88=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 14 +++++++++++++- src/controllers/ProfileEmployeeController.ts | 14 +++++++++++++- src/controllers/ProfileEmployeeTempController.ts | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 8bf28811..0ec76d94 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -60,7 +60,7 @@ import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import Extension from "../interfaces/extension"; import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; -import { updateName } from "../keycloak"; +import { updateName, deleteUser } from "../keycloak"; import permission from "../interfaces/permission"; import { PosMasterAct } from "../entities/PosMasterAct"; import axios from "axios"; @@ -9405,6 +9405,7 @@ export class ProfileController extends Controller { }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const before = structuredClone(profile); + let _null:any = null; profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; @@ -9412,6 +9413,17 @@ export class ProfileController extends Controller { await removeProfileInOrganize(profile.id, "OFFICER"); } profile.leaveType = "RETIRE_DECEASED"; + profile.position = _null; + profile.posLevelId = _null; + profile.posTypeId = _null; + if (profile.keycloak != null) { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.keycloak = _null; + profile.roleKeycloaks = []; + profile.isActive = false; + } + } await this.profileRepo.save(profile, { data: request }); setLogDataDiff(request, { before, after: profile }); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index c54ad861..d2f5cf71 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -68,6 +68,7 @@ import permission from "../interfaces/permission"; import axios from "axios"; import { Position } from "../entities/Position"; import { EmployeePosition } from "../entities/EmployeePosition"; +import { deleteUser } from "../keycloak"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -4113,13 +4114,24 @@ export class ProfileEmployeeController extends Controller { where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + let _null:any = null; profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + profile.position = _null; + profile.posLevelId = _null; + profile.posTypeId = _null; + if (profile.keycloak != null) { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.keycloak = _null; + profile.roleKeycloaks = []; + profile.isActive = false; + } + } profile.leaveType = "RETIRE_DECEASED"; await this.profileRepo.save(profile); diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 6d98310d..3fc25988 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -66,6 +66,7 @@ import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; import permission from "../interfaces/permission"; import axios from "axios"; +import { deleteUser } from "../keycloak"; @Route("api/v1/org/profile-temp") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -3201,13 +3202,25 @@ export class ProfileEmployeeTempController extends Controller { where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + let _null:any = null; profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + profile.leaveType = "RETIRE_DECEASED"; + profile.position = _null; + profile.posLevelId = _null; + profile.posTypeId = _null; + if (profile.keycloak != null) { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.keycloak = _null; + profile.roleKeycloaks = []; + profile.isActive = false; + } + } await this.profileRepo.save(profile); return new HttpSuccess(); From f1f7412db0aec13303ef9ffb576a0bc78cad6137 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 13 Mar 2025 14:53:55 +0700 Subject: [PATCH 2/2] =?UTF-8?q?import=20=E0=B8=95=E0=B8=B3=E0=B9=81?= =?UTF-8?q?=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EmployeeTempPositionController.ts | 120 +++++++------- src/controllers/ImportDataController.ts | 151 +++++++++--------- src/entities/OFFICER.ts | 21 +++ 3 files changed, 160 insertions(+), 132 deletions(-) diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index e5abc961..deb32067 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -540,12 +540,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgRoot"], }); - if (chk_SName0 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName0 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName1 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -556,12 +556,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild1"], }); - if (chk_SName1 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName1 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName2 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -572,12 +572,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild2"], }); - if (chk_SName2 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName2 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName3 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -588,12 +588,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild3"], }); - if (chk_SName3 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName3 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName4 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -603,12 +603,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild4"], }); - if (chk_SName4 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName4 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const before = null; posMaster.createdUserId = request.user.sub; posMaster.createdFullName = request.user.name; @@ -749,12 +749,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgRoot"], }); - if (chk_SName0 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName0 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName1 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -766,12 +766,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild1"], }); - if (chk_SName1 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName1 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName2 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -783,12 +783,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild2"], }); - if (chk_SName2 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName2 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName3 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -800,12 +800,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild3"], }); - if (chk_SName3 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName3 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const chk_SName4 = await this.employeeTempPosMasterRepository.findOne({ where: { @@ -816,12 +816,12 @@ export class EmployeeTempPositionController extends Controller { }, relations: ["orgChild4"], }); - if (chk_SName4 != null) { - throw new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", - ); - } + // if (chk_SName4 != null) { + // throw new HttpError( + // HttpStatusCode.INTERNAL_SERVER_ERROR, + // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", + // ); + // } const before = structuredClone(posMaster); posMaster.createdUserId = request.user.sub; //สงสัยว่าทำให้ bug แก้ไขไม่ได้ posMaster.createdFullName = request.user.name; diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 8f029255..da833b71 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -2277,11 +2277,11 @@ export class ImportDataController extends Controller { async MapPositionOfficer(@Request() request: { user: Record }) { const [officer, total] = await AppDataSource.getRepository(OFFICER) .createQueryBuilder("OFFICER") - .where({ DEPARTMENT_CODE: "50" }) + // .where({ DEPARTMENT_CODE: "50" }) // .skip(0) // .take(20) .getManyAndCount(); - let rowCount = 0; + let rowCount = 0; let _null: any = null; let type_: any = null; let level_: any = null; @@ -2305,77 +2305,84 @@ export class ImportDataController extends Controller { if (posMasterCheck != null) { continue; } - let orgRoot = new OrgRoot(); - let orgChild1 = new OrgChild1(); - let orgChild2 = new OrgChild2(); - let orgChild3 = new OrgChild3(); - if ((item.DEPARTMENT_CODE = "50")) { - orgRoot = (await this.orgRootRepo.findOne({ - where: { orgRootName: item.DIVISION_NAME, orgRevisionId: orgRevision.id }, - })) as OrgRoot; - if (orgRoot == null) { - continue; - } - orgChild1 = (await this.orgChild1Repo.findOne({ - where: { - orgChild1Name: item.SECTION_NAME, - orgRoot: { orgRootName: item.DIVISION_NAME }, - orgRevisionId: orgRevision.id, - }, - })) as OrgChild1; - orgChild2 = (await this.orgChild2Repo.findOne({ - where: { - orgChild2Name: item.JOB_NAME, - orgChild1: { - orgChild1Name: item.SECTION_NAME, - orgRoot: { orgRootName: item.DIVISION_NAME }, - }, - orgRevisionId: orgRevision.id, - }, - })) as OrgChild2; - } else { - orgRoot = (await this.orgRootRepo.findOne({ - where: { orgRootName: item.DEPARTMENT_NAME, orgRevisionId: orgRevision.id }, - })) as OrgRoot; - if (orgRoot == null) { - continue; - } - orgChild1 = (await this.orgChild1Repo.findOne({ - where: { - orgChild1Name: item.DIVISION_NAME, - orgRoot: { orgRootName: item.DEPARTMENT_NAME }, - orgRevisionId: orgRevision.id, - }, - })) as OrgChild1; - orgChild2 = (await this.orgChild2Repo.findOne({ - where: { - orgChild2Name: item.SECTION_NAME, - orgChild1: { - orgChild1Name: item.DIVISION_NAME, - orgRoot: { orgRootName: item.DEPARTMENT_NAME }, - }, - orgRevisionId: orgRevision.id, - }, - })) as OrgChild2; - orgChild3 = (await this.orgChild3Repo.findOne({ - where: { - orgChild3Name: item.JOB_NAME, - orgChild2: { - orgChild2Name: item.SECTION_NAME, - orgChild1: { - orgChild1Name: item.DIVISION_NAME, - orgRoot: { orgRootName: item.DEPARTMENT_NAME }, - }, - }, - orgRevisionId: orgRevision.id, - }, - })) as OrgChild3; - } let posMaster = new PosMaster(); - posMaster.orgRootId = orgRoot?.id ?? _null; - posMaster.orgChild1Id = orgChild1?.id ?? _null; - posMaster.orgChild2Id = orgChild2?.id ?? _null; - posMaster.orgChild3Id = orgChild3?.id ?? _null; + let orgRoot = new OrgRoot(); + if (item.DEPARTMENT_CODE != "50") { + orgRoot = (await this.orgRootRepo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + })) as OrgRoot; + } + if (orgRoot != null) { + posMaster.orgRootId = orgRoot.id ?? _null; + } else { + let orgChild1 = await this.orgChild1Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild1 != null) { + posMaster.orgRootId = orgChild1.orgRootId ?? _null; + posMaster.orgChild1Id = orgChild1.id ?? _null; + } else { + let orgChild2 = await this.orgChild2Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild2 != null) { + posMaster.orgRootId = orgChild2.orgRootId ?? _null; + posMaster.orgChild1Id = orgChild2.orgChild1Id ?? _null; + posMaster.orgChild2Id = orgChild2.id ?? _null; + } else { + let orgChild3 = await this.orgChild3Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild3 != null) { + posMaster.orgRootId = orgChild3.orgRootId ?? _null; + posMaster.orgChild1Id = orgChild3.orgChild1Id ?? _null; + posMaster.orgChild2Id = orgChild3.orgChild2Id ?? _null; + posMaster.orgChild3Id = orgChild3.id ?? _null; + } else { + let orgChild4 = await this.orgChild4Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild4 != null) { + posMaster.orgRootId = orgChild4.id ?? _null; + posMaster.orgChild1Id = orgChild4.id ?? _null; + posMaster.orgChild2Id = orgChild4.id ?? _null; + posMaster.orgChild3Id = orgChild4.id ?? _null; + posMaster.orgChild4Id = orgChild4.id ?? _null; + } + } + } + } + } posMaster.statusReport = "PENDING"; posMaster.isCondition = false; posMaster.isStaff = false; diff --git a/src/entities/OFFICER.ts b/src/entities/OFFICER.ts index 92dc117a..e0ffe3c7 100644 --- a/src/entities/OFFICER.ts +++ b/src/entities/OFFICER.ts @@ -117,6 +117,13 @@ export class OFFICER { }) DIVISION_NAME: string; + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_CODE: string; + @Column({ nullable: true, type: "text", @@ -124,6 +131,13 @@ export class OFFICER { }) SECTION_NAME: string; + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_CODE: string; + @Column({ nullable: true, type: "text", @@ -131,6 +145,13 @@ export class OFFICER { }) JOB_NAME: string; + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_CODE: string; + @Column({ nullable: true, type: "text",