From f1f7412db0aec13303ef9ffb576a0bc78cad6137 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 13 Mar 2025 14:53:55 +0700 Subject: [PATCH] =?UTF-8?q?import=20=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=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",