From bd9dee6da2eec8f6bf9cc947325d57d72f14ef38 Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 12 Jun 2024 14:41:16 +0700 Subject: [PATCH 1/2] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A7=20isDirecter=20isOfficer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/EmployeePositionController.ts | 4 ++++ src/controllers/PositionController.ts | 6 ++++++ src/entities/EmployeePosMaster.ts | 6 ++++++ src/entities/PosMaster.ts | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 33ad2684..0bbbca38 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -255,6 +255,8 @@ export class EmployeePositionController extends Controller { ? null : `${position.posType.posTypeShortName} ${position.posLevel.posLevelName}`, positionIsSelected: position.positionIsSelected, + isOfficer: posMaster.isOfficer, + isDirecter: posMaster.isDirector, })), }; return new HttpSuccess(formattedData); @@ -611,6 +613,8 @@ export class EmployeePositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); } posMaster.posMasterNo = requestBody.posMasterNo; + posMaster.isDirector = requestBody.isDirector; + posMaster.isOfficer = requestBody.isOfficer; posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix; posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix; posMaster.reason = requestBody.reason == null ? "" : requestBody.reason; diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 0061aecb..bfca037b 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -797,6 +797,8 @@ export class PositionController extends Controller { if (!posMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); } + posMaster.isDirector = requestBody.isDirector; + posMaster.isOfficer = requestBody.isOfficer; posMaster.posMasterNo = requestBody.posMasterNo; posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix; posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix; @@ -949,6 +951,8 @@ export class PositionController extends Controller { position.positionExecutiveField = x.posDictExecutiveField; position.positionArea = x.posDictArea; position.isSpecial = x.isSpecial; + position.isOfficer = x.isOfficer; + position.isDirector = x.isDirector; position.positionIsSelected = x.positionIsSelected; position.posMasterId = posMaster.id; position.createdUserId = request.user.sub; @@ -1001,6 +1005,8 @@ export class PositionController extends Controller { positionArea: position.positionArea, positionIsSelected: position.positionIsSelected, isSpecial: position.isSpecial, + isOfficer: posMaster.isOfficer, + isDirecter: posMaster.isDirector, })), }; return new HttpSuccess(formattedData); diff --git a/src/entities/EmployeePosMaster.ts b/src/entities/EmployeePosMaster.ts index 22c21dac..6c47e067 100644 --- a/src/entities/EmployeePosMaster.ts +++ b/src/entities/EmployeePosMaster.ts @@ -237,6 +237,12 @@ export class CreateEmployeePosMaster { @Column() reason: string | null; + + @Column() + isDirector: boolean; + + @Column() + isOfficer: boolean; } export type UpdateEmployeePosMaster = Partial; diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index ca8da472..5fc8d032 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -236,6 +236,12 @@ export class CreatePosMaster { @Column() reason: string | null; + + @Column() + isDirector: boolean; + + @Column() + isOfficer: boolean; } export type UpdatePosMaster = Partial; From 140bb6dbbc2a9916a9ad780417fb145c7493331c Mon Sep 17 00:00:00 2001 From: AnandaTon Date: Wed, 12 Jun 2024 14:44:18 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20Upload=20sql=20=E0=B8=82=E0=B8=AD=E0=B8=87=20posTyp?= =?UTF-8?q?e=20=E0=B9=80=E0=B9=80=E0=B8=A5=E0=B8=B0=20posLevel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ImportDataController.ts | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index fcebcf7b..f9230ec8 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -28,6 +28,8 @@ import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { PosLevel } from "../entities/PosLevel"; +import { PosType } from "../entities/PosType"; @Route("api/v1/org/upload") @Tags("UPLOAD") @@ -40,6 +42,8 @@ export class ImportDataController extends Controller { private salaryRepository = AppDataSource.getRepository(ProfileSalary); private profileRepo = AppDataSource.getRepository(Profile); private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); + private posLevelRepo = AppDataSource.getRepository(PosLevel); + private posTypeRepo = AppDataSource.getRepository(PosType); /** * API upload EDU * @@ -594,4 +598,58 @@ export class ImportDataController extends Controller { await this.salaryRepository.save(profiles); return new HttpSuccess(allData); } + + @Post("uploadposSQL") + @UseInterceptors(FileInterceptor("file")) + async UploadPOSFileSQL(@UploadedFile() file: Express.Multer.File) { + const workbook = xlsx.read(file.buffer, { type: "buffer" }); + const sheetName = workbook.SheetNames[0]; + const sheet = workbook.Sheets[sheetName]; + const getProFile = xlsx.utils.sheet_to_json(sheet); + let profiles: any = []; + await Promise.all( + getProFile.map(async (item: any) => { + // Find profile by ID + let profile = await this.profileRepo.findOne({ + where: { citizenId: item["ID"] }, + }); + if (!profile) { + return; // Skip processing this item + } + + if (item["MP_CEE_TYPE"] === "NULL") { + profile.posTypeId = null; + } else { + // Find posType by posTypeName + const posType = await this.posTypeRepo.findOne({ + where: { posTypeName: item["MP_CEE_TYPE"] }, + }); + if (!posType) { + return; // Skip processing this item + } + profile.posTypeId = posType.id; + } + // Check if posLevelName is "NULL" + if (item["MP_CEE_POSITION"] === "NULL") { + profile.posLevelId = null; + } else { + // Find posLevel by posLevelName + const posLevel = await this.posLevelRepo.findOne({ + where: { posLevelName: item["MP_CEE_POSITION"] }, + }); + if (!posLevel) { + console.error( + `posLevel with name ${item["MP_CEE_POSITION"]} not found for profile ID ${profile.id}`, + ); + return; // Skip processing this item + } + profile.posLevelId = posLevel.id; + } + + profiles.push(profile); + }), + ); + await this.profileRepo.save(profiles); + return new HttpSuccess(getProFile); + } }