From 6c65552dc50ac06c2f46a444978178b5e97991b7 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 10 Feb 2025 16:16:20 +0700 Subject: [PATCH 1/9] nis code list --- src/controllers/ImportDataController.ts | 38 +++++++++++++++++++++---- src/entities/IMPORT_ORG.ts | 21 ++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 5b9a6882..efc36d46 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -1469,7 +1469,7 @@ export class ImportDataController extends Controller { @Post("ImportOrg") async ImportOrg(@Request() request: { user: Record }) { const IMPORT_ORG = await this.IMPORT_ORGRepo.find({ - where: { orgChild1: Not(IsNull()) }, + where: { orgChild1: Not(IsNull()) || Not("") }, }); const orgRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, @@ -1479,7 +1479,14 @@ export class ImportDataController extends Controller { IMPORT_ORG.map(async (item) => { const orgRoot = new OrgRoot(); orgRoot.orgRootName = item.orgRoot; - orgRoot.misId = item.MISCODE; + orgRoot.orgRootShortName = item.orgShortname; + const rank: any = item.orgRank; + orgRoot.orgRootRank = rank; + orgRoot.orgRootRankSub = item.orgSubRank; + orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgRoot.DIVISION_CODE = item.DIVISION_CODE; + orgRoot.SECTION_CODE = item.SECTION_CODE; + orgRoot.JOB_CODE = item.JOB_CODE; orgRoot.orgRevisionId = orgRevision.id; orgRoot.createdUserId = request.user.sub; orgRoot.createdFullName = request.user.name; @@ -1497,7 +1504,14 @@ export class ImportDataController extends Controller { const orgChild1 = new OrgChild1(); orgChild1.orgRootId = orgRoot.id; orgChild1.orgChild1Name = item1.orgChild1; - orgChild1.misId = item1.MISCODE; + orgChild1.orgChild1ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild1.orgChild1Rank = rank; + orgChild1.orgChild1RankSub = item.orgSubRank; + orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild1.DIVISION_CODE = item.DIVISION_CODE; + orgChild1.SECTION_CODE = item.SECTION_CODE; + orgChild1.JOB_CODE = item.JOB_CODE; orgChild1.orgRevisionId = orgRevision.id; orgChild1.createdUserId = request.user.sub; orgChild1.createdFullName = request.user.name; @@ -1520,7 +1534,14 @@ export class ImportDataController extends Controller { orgChild2.orgRootId = orgRoot.id; orgChild2.orgChild1Id = orgChild1.id; orgChild2.orgChild2Name = item2.orgChild2; - orgChild2.misId = item2.MISCODE; + orgChild2.orgChild2ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild2.orgChild2Rank = rank; + orgChild2.orgChild2RankSub = item.orgSubRank; + orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild2.DIVISION_CODE = item.DIVISION_CODE; + orgChild2.SECTION_CODE = item.SECTION_CODE; + orgChild2.JOB_CODE = item.JOB_CODE; orgChild2.orgRevisionId = orgRevision.id; orgChild2.createdUserId = request.user.sub; orgChild2.createdFullName = request.user.name; @@ -1544,7 +1565,14 @@ export class ImportDataController extends Controller { orgChild3.orgChild1Id = orgChild1.id; orgChild3.orgChild2Id = orgChild2.id; orgChild3.orgChild3Name = item.orgChild3; - orgChild3.misId = item.MISCODE; + orgChild3.orgChild3ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild3.orgChild3Rank = rank; + orgChild3.orgChild3RankSub = item.orgSubRank; + orgChild3.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild3.DIVISION_CODE = item.DIVISION_CODE; + orgChild3.SECTION_CODE = item.SECTION_CODE; + orgChild3.JOB_CODE = item.JOB_CODE; orgChild3.orgRevisionId = orgRevision.id; orgChild3.createdUserId = request.user.sub; orgChild3.createdFullName = request.user.name; diff --git a/src/entities/IMPORT_ORG.ts b/src/entities/IMPORT_ORG.ts index 7c5a2e1e..ea153ae5 100644 --- a/src/entities/IMPORT_ORG.ts +++ b/src/entities/IMPORT_ORG.ts @@ -67,4 +67,25 @@ export class IMPORT_ORG { default: null, }) MISCODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + orgShortname: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + orgRank: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + orgSubRank: string; } From ec14148d721e9d7e5d51cf40055cb6eb11fc1490 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 10 Feb 2025 16:19:34 +0700 Subject: [PATCH 2/9] =?UTF-8?q?fix=20=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=8A=E0=B8=B1?= =?UTF-8?q?=E0=B9=89=E0=B8=99=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=20(=E0=B8=82?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=8A=E0=B8=B1=E0=B9=89=E0=B8=99?= =?UTF-8?q?=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= =?UTF-8?q?=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=84=E0=B8=A3=E0=B8=9A)=20#1172?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 0fa1829a..b58136c6 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -6641,7 +6641,9 @@ export class ProfileController extends Controller { position: profile.position, leaveDate: profile.dateLeave, posMasterNo: posMaster == null ? null : posMaster.posMasterNo, - posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, + posLevelName: profile.posLevel == null + ? null + : `${profile.posType.posTypeShortName ?? ""} ${profile.posLevel.posLevelName ?? ""}`, posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, posLevelId: profile.posLevel == null ? null : profile.posLevel.id, posTypeName: profile.posType == null ? null : profile.posType.posTypeName, From a7e12be51f20765e3d721f9e355b2c520d34249f Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 10 Feb 2025 17:32:19 +0700 Subject: [PATCH 3/9] =?UTF-8?q?fix=20issue=20#1175=20(=E0=B8=82=E0=B9=89?= =?UTF-8?q?=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B8=95=E0=B8=B1=E0=B8=A7?= =?UTF-8?q?=E0=B8=A2=E0=B9=88=E0=B8=AD=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB?= =?UTF-8?q?=E0=B8=99=E0=B9=88=E0=B8=87=20=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6=E0=B8=81=E0=B8=A5?= =?UTF-8?q?=E0=B8=87=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=AB=E0=B8=A5=E0=B8=B1=E0=B8=87=E0=B8=88=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA?= =?UTF-8?q?=E0=B8=B1=E0=B9=88=E0=B8=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 34 ++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 438cbf37..ac850cb2 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4707,7 +4707,37 @@ export class CommandController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - + const _posMaster = await this.employeePosMasterRepository.findOne({ + where: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + current_holderId: profile.id, + }, + order: { createdAt: "DESC" }, + relations: { + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + }, + }); + let orgShortName = ""; + if (_posMaster != null) { + if (_posMaster.orgChild1Id === null) { + orgShortName = _posMaster.orgRoot?.orgRootShortName; + } else if (_posMaster.orgChild2Id === null) { + orgShortName = _posMaster.orgChild1?.orgChild1ShortName; + } else if (_posMaster.orgChild3Id === null) { + orgShortName = _posMaster.orgChild2?.orgChild2ShortName; + } else if (_posMaster.orgChild4Id === null) { + orgShortName = _posMaster.orgChild3?.orgChild3ShortName; + } else { + orgShortName = _posMaster.orgChild4?.orgChild4ShortName; + } + } const dest_item = await this.salaryRepo.findOne({ where: { profileEmployeeId: item.refId }, order: { order: "DESC" }, @@ -4723,7 +4753,7 @@ export class CommandController extends Controller { commandId: item.commandId, positionSalaryAmount: item.positionSalaryAmount, mouthSalaryAmount: item.mouthSalaryAmount, - posNo: profile.posMasterNoTemp, + posNo: `${orgShortName ?? ""} ${profile.posMasterNoTemp ?? ""}`, position: profile.positionTemp, positionType: profile.posTypeNameTemp, positionLevel: profile.posLevelNameTemp, From 5edcb127f9bbaa49f9e0b40db293b1b14748a254 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Feb 2025 13:14:33 +0700 Subject: [PATCH 4/9] fix --- src/controllers/CommandController.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index ac850cb2..5670d395 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4707,15 +4707,17 @@ export class CommandController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + const orgRevision = await this.orgRevisionRepository.findOne({ + where: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }); const _posMaster = await this.employeePosMasterRepository.findOne({ - where: { - orgRevision: { - orgRevisionIsCurrent: true, - orgRevisionIsDraft: false, - }, - current_holderId: profile.id, + where: { + orgRevisionId: orgRevision?.id, + current_holderId: profile.id }, - order: { createdAt: "DESC" }, relations: { orgRoot: true, orgChild1: true, From 7878d912b1abac442d5131c988df65f278d98b8a Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Feb 2025 14:06:55 +0700 Subject: [PATCH 5/9] fix --- src/controllers/CommandController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 5670d395..f4208e5d 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4716,7 +4716,8 @@ export class CommandController extends Controller { const _posMaster = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: orgRevision?.id, - current_holderId: profile.id + id: profile.posmasterIdTemp + // current_holderId: profile.id }, relations: { orgRoot: true, From 86b1e55aee9a73e4e256dcdbd46a9bcf3f95ddf4 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Feb 2025 19:53:28 +0700 Subject: [PATCH 6/9] =?UTF-8?q?fix=20issue=20#1184=20=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B1?= =?UTF-8?q?=E0=B8=9A=E0=B8=A3=E0=B8=B0=E0=B8=94=E0=B8=B1=E0=B8=9A=E0=B8=8A?= =?UTF-8?q?=E0=B8=B1=E0=B9=89=E0=B8=99=E0=B8=87=E0=B8=B2=E0=B8=99+?= =?UTF-8?q?=E0=B8=A2=E0=B9=89=E0=B8=B2=E0=B8=A2=20(=E0=B8=95=E0=B8=B1?= =?UTF-8?q?=E0=B8=A7=E0=B8=A2=E0=B9=88=E0=B8=AD=E0=B8=A3=E0=B8=B0=E0=B8=94?= =?UTF-8?q?=E0=B8=B1=E0=B8=9A=E0=B8=8A=E0=B8=B1=E0=B9=89=E0=B8=99=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B9=84?= =?UTF-8?q?=E0=B8=A1=E0=B9=88=E0=B8=84=E0=B8=A3=E0=B8=9A)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 4 +++- src/controllers/ProfileController.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 913f00bc..1b1976ca 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -4383,7 +4383,9 @@ export class PositionController extends Controller { posTypeId: position.posTypeId, posTypeName: position.posType == null ? null : position.posType.posTypeName, posLevelId: position.posLevelId, - posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName, + posLevelName: position.posType == null && position.posLevel == null + ? null + : `${position.posType.posTypeShortName} ${position.posLevel.posLevelName}`, // posExecutiveId: position.posExecutiveId, // posExecutiveName: // position.posExecutive == null ? null : position.posExecutive.posExecutiveName, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index b58136c6..fca3c91b 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -6641,9 +6641,9 @@ export class ProfileController extends Controller { position: profile.position, leaveDate: profile.dateLeave, posMasterNo: posMaster == null ? null : posMaster.posMasterNo, - posLevelName: profile.posLevel == null + posLevelName: profile.posType == null && profile.posLevel == null ? null - : `${profile.posType.posTypeShortName ?? ""} ${profile.posLevel.posLevelName ?? ""}`, + : `${profile.posType.posTypeShortName} ${profile.posLevel.posLevelName}`, posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, posLevelId: profile.posLevel == null ? null : profile.posLevel.id, posTypeName: profile.posType == null ? null : profile.posType.posTypeName, From 33ec55250c7098a2ee6e972d0427c6158cf2fda4 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 12 Feb 2025 10:43:01 +0700 Subject: [PATCH 7/9] import --- src/controllers/ImportDataController.ts | 474 ++++++++++++++---------- src/entities/HR_EDUCATION.ts | 7 + src/entities/OFFICER.ts | 91 +++++ 3 files changed, 374 insertions(+), 198 deletions(-) create mode 100644 src/entities/OFFICER.ts diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index efc36d46..c6877280 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -44,6 +44,7 @@ import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; import { IMPORT_ORG } from "../entities/IMPORT_ORG"; import { OrgRevision } from "../entities/OrgRevision"; +import { OFFICER } from "../entities/OFFICER"; @Route("api/v1/org/upload") @Tags("UPLOAD") @@ -83,118 +84,24 @@ export class ImportDataController extends Controller { private orgChild3Repo = AppDataSource.getRepository(OrgChild3); private orgChild4Repo = AppDataSource.getRepository(OrgChild4); private IMPORT_ORGRepo = AppDataSource.getRepository(IMPORT_ORG); + private OFFICERRepo = AppDataSource.getRepository(OFFICER); /** * @summary ทะเบียนประวัติ ข้าราชการ */ @Post("uploadProfile-Officer") async UploadFileSqlOfficer(@Request() request: { user: Record }) { - let users = []; - let rowCount = 0; - const filePath = path.resolve(__dirname, "OFFICER.csv"); // Corrected file path - const readStream = fs.createReadStream(filePath).pipe(csvParser()); - let profiles: any = []; + const OFFICER = await this.OFFICERRepo.find(); let null_: any = null; - for await (const item of readStream) { - // readStream.map(async (item: any) => { - rowCount++; - let type_: any = null; - let level_: any = null; - const profile = new Profile(); - // if (item["FLAG_RETIRE_STATUSxxxx"] != "" && item["FLAG_RETIRE_STATUSxxxx"] != null) { - // continue; - // } - // if (item["FLAG_PERSON_TYPExxxx"] != "1") { - // continue; - // } - if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) { - continue; - } - - const existingProfile = await this.profileRepo.findOne({ - where: { citizenId: item["ID"] }, + for await (const item of OFFICER) { + let existingProfile = await this.profileRepo.findOne({ + where: { citizenId: item.ID }, }); - if (existingProfile) { - profile.id = existingProfile.id; - // continue; + if (existingProfile == null) { + } else { + existingProfile.position = item["WORK_LINE_NAME"] == "" ? null_ : item["WORK_LINE_NAME"]; + await this.profileRepo.save(existingProfile); } - - if (item["TYPE"]) { - type_ = await this.posTypeRepo.findOne({ - where: { posTypeName: item["TYPE"] }, - }); - } - if (item["LEVEL"]) { - if (type_ == null) { - level_ = await this.posLevelRepo.findOne({ - where: { - posLevelName: item["LEVEL"], - }, - }); - } else { - level_ = await this.posLevelRepo.findOne({ - where: { - posLevelName: item["LEVEL"], - posTypeId: type_.id, - }, - }); - } - } - - let dateRetire = new Date(item["BORN"]); - profile.citizenId = item["ID"] == "" ? "" : item["ID"]; - profile.rank = - item["RANK_NAME"] == "" || - item["RANK_NAME"] == "นาย" || - item["RANK_NAME"] == "นาง" || - item["RANK_NAME"] == "นางสาว" - ? null - : item["RANK_NAME"]; - profile.prefix = item["RANK_NAME"] == "" ? null : item["RANK_NAME"]; - profile.prefixMain = - item["RANK_NAME"] == "" || - (item["RANK_NAME"] != "นาย" && item["RANK_NAME"] != "นาง" && item["RANK_NAME"] != "นางสาว") - ? null - : item["RANK_NAME"]; - profile.firstName = item["FNAME"] == "" ? null : item["FNAME"]; - profile.lastName = item["LNAME"] == "" ? null : item["LNAME"]; - profile.gender = item["SEX"] == "1" ? "ชาย" : item["SEX"] == "2" ? "หญิง" : null_; - profile.birthDate = item["BORN"] == "" ? null_ : new Date(item["BORN"]); - profile.dateAppoint = - item["BEGIN_ENTRY_DATE"] == "" ? null_ : new Date(item["BEGIN_ENTRY_DATE"]); - profile.dateStart = - item["BEGIN_ENTRY_DATE"] == "" ? null_ : new Date(item["BEGIN_ENTRY_DATE"]); - profile.dateRetire = dateRetire == null ? null_ : calculateRetireDate(dateRetire); - profile.dateRetireLaw = dateRetire == null ? null_ : calculateRetireLaw(dateRetire); - profile.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"]; - profile.posTypeId = - type_ != null && type_.posTypeName == item["TYPE"] && type_ ? type_.id : null; - profile.posLevelId = - level_ != null && level_.posLevelName == item["LEVEL"] && level_ ? level_.id : null; - profile.relationship = - item["สถานภาพ"] == "" ? "" : Extension.CheckRelationship(item["สถานภาพ"]); - // profile.isLeave = - // item["FLAG_RETIRE_STATUSxxxx"] == "" || item["FLAG_RETIRE_STATUSxxxx"] == null ? false : true; - profile.createdUserId = request.user.sub; - profile.createdFullName = request.user.name; - profile.lastUpdateUserId = request.user.sub; - profile.lastUpdateFullName = request.user.name; - profile.createdAt = new Date(); - profile.lastUpdatedAt = new Date(); - // profiles.push(profile); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - - // if (profiles.length === BATCH_SIZE) { - await this.profileRepo.save(profile); - // profiles = await []; - // if (global.gc) { - // global.gc(); - // } - // } } - // ) - // ); - // console.log(rowCount); - // await this.profileRepo.save(profiles); return new HttpSuccess(); } @@ -296,7 +203,7 @@ export class ImportDataController extends Controller { .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") // .skip(0) - // .take(20) + // .take(1000) .getManyAndCount(); // for (var i = 1; i <= total / BATCH_SIZE; i++) { // const profiles = await AppDataSource.getRepository(Profile) @@ -546,7 +453,7 @@ export class ImportDataController extends Controller { .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") // .skip(0) - // .take(20) + // .take(1000) .getManyAndCount(); // for (var i = 1; i <= total / BATCH_SIZE; i++) { // const profiles = await AppDataSource.getRepository(Profile) @@ -853,7 +760,14 @@ export class ImportDataController extends Controller { profiles.map(async (_item) => { const existingProfile = await this.HR_EDUCATIONRepo.find({ where: { CIT: _item.citizenId }, - select: ["CIT", "EDUCATION_CODE", "START_EDUCATION_YEAR", "EDUCATION_YEAR", "INSTITUE"], + select: [ + "CIT", + "EDUCATION_CODE", + "START_EDUCATION_YEAR", + "EDUCATION_YEAR", + "INSTITUE", + "EDUCATION_SEQ", + ], }); const educationLevel = await this.profileEducationRepo.findOne({ @@ -885,6 +799,7 @@ export class ImportDataController extends Controller { education.profileId = _item.id; education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; education.institute = item.INSTITUE; + education.level = item.EDUCATION_SEQ ? null_ : Number(item.EDUCATION_SEQ); education.startDate = startDate; education.endDate = endDate; education.createdUserId = request.user.sub; @@ -1468,15 +1383,22 @@ export class ImportDataController extends Controller { */ @Post("ImportOrg") async ImportOrg(@Request() request: { user: Record }) { - const IMPORT_ORG = await this.IMPORT_ORGRepo.find({ - where: { orgChild1: Not(IsNull()) || Not("") }, - }); const orgRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, }); if (orgRevision == null) return new HttpSuccess(); + //create root + const IMPORT_CHILD = await this.IMPORT_ORGRepo.find({ + where: { + orgRoot: Not(""), + orgChild1: "", + orgChild2: "", + orgChild3: "", + }, + }); + await Promise.all( - IMPORT_ORG.map(async (item) => { + IMPORT_CHILD.map(async (item) => { const orgRoot = new OrgRoot(); orgRoot.orgRootName = item.orgRoot; orgRoot.orgRootShortName = item.orgShortname; @@ -1495,98 +1417,254 @@ export class ImportDataController extends Controller { orgRoot.createdAt = new Date(); orgRoot.lastUpdatedAt = new Date(); await this.orgRootRepo.save(orgRoot); + }), + ); - const IMPORT_CHILD1 = await this.IMPORT_ORGRepo.find({ - where: { orgChild2: Not(IsNull()), orgRoot: item.orgRoot }, + //create child1 + const IMPORT_CHILD1 = await this.IMPORT_ORGRepo.find({ + where: { + orgRoot: Not(""), + orgChild1: Not(""), + orgChild2: "", + orgChild3: "", + }, + }); + + await Promise.all( + IMPORT_CHILD1.map(async (item) => { + const orgChild1 = new OrgChild1(); + let orgRoot = await this.orgRootRepo.findOne({ + where: { orgRootName: item.orgRoot }, }); - await Promise.all( - IMPORT_CHILD1.map(async (item1) => { - const orgChild1 = new OrgChild1(); - orgChild1.orgRootId = orgRoot.id; - orgChild1.orgChild1Name = item1.orgChild1; - orgChild1.orgChild1ShortName = item.orgShortname; - const rank: any = item.orgRank; - orgChild1.orgChild1Rank = rank; - orgChild1.orgChild1RankSub = item.orgSubRank; - orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE; - orgChild1.DIVISION_CODE = item.DIVISION_CODE; - orgChild1.SECTION_CODE = item.SECTION_CODE; - orgChild1.JOB_CODE = item.JOB_CODE; - orgChild1.orgRevisionId = orgRevision.id; - orgChild1.createdUserId = request.user.sub; - orgChild1.createdFullName = request.user.name; - orgChild1.lastUpdateUserId = request.user.sub; - orgChild1.lastUpdateFullName = request.user.name; - orgChild1.createdAt = new Date(); - orgChild1.lastUpdatedAt = new Date(); - await this.orgChild1Repo.save(orgChild1); - const IMPORT_CHILD2 = await this.IMPORT_ORGRepo.find({ - where: { - orgChild3: Not(IsNull()), - orgRoot: item.orgRoot, - orgChild1: item1.orgChild1, - }, - }); + if (orgRoot == null) { + orgRoot = new OrgRoot(); + orgRoot.orgRootName = item.orgRoot; + orgRoot.orgRootShortName = item.orgShortname; + const rank: any = item.orgRank; + orgRoot.orgRootRank = rank; + orgRoot.orgRootRankSub = item.orgSubRank; + orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgRoot.DIVISION_CODE = item.DIVISION_CODE; + orgRoot.SECTION_CODE = item.SECTION_CODE; + orgRoot.JOB_CODE = item.JOB_CODE; + orgRoot.orgRevisionId = orgRevision.id; + orgRoot.createdUserId = request.user.sub; + orgRoot.createdFullName = request.user.name; + orgRoot.lastUpdateUserId = request.user.sub; + orgRoot.lastUpdateFullName = request.user.name; + orgRoot.createdAt = new Date(); + orgRoot.lastUpdatedAt = new Date(); + await this.orgRootRepo.save(orgRoot); + } - await Promise.all( - IMPORT_CHILD2.map(async (item2) => { - const orgChild2 = new OrgChild2(); - orgChild2.orgRootId = orgRoot.id; - orgChild2.orgChild1Id = orgChild1.id; - orgChild2.orgChild2Name = item2.orgChild2; - orgChild2.orgChild2ShortName = item.orgShortname; - const rank: any = item.orgRank; - orgChild2.orgChild2Rank = rank; - orgChild2.orgChild2RankSub = item.orgSubRank; - orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE; - orgChild2.DIVISION_CODE = item.DIVISION_CODE; - orgChild2.SECTION_CODE = item.SECTION_CODE; - orgChild2.JOB_CODE = item.JOB_CODE; - orgChild2.orgRevisionId = orgRevision.id; - orgChild2.createdUserId = request.user.sub; - orgChild2.createdFullName = request.user.name; - orgChild2.lastUpdateUserId = request.user.sub; - orgChild2.lastUpdateFullName = request.user.name; - orgChild2.createdAt = new Date(); - orgChild2.lastUpdatedAt = new Date(); - await this.orgChild2Repo.save(orgChild2); - const IMPORT_CHILD3 = await this.IMPORT_ORGRepo.find({ - where: { - orgRoot: item.orgRoot, - orgChild1: item1.orgChild1, - orgChild2: item2.orgChild2, - }, - }); + orgChild1.orgRootId = orgRoot.id; + orgChild1.orgChild1Name = item.orgChild1; + orgChild1.orgChild1ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild1.orgChild1Rank = rank; + orgChild1.orgChild1RankSub = item.orgSubRank; + orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild1.DIVISION_CODE = item.DIVISION_CODE; + orgChild1.SECTION_CODE = item.SECTION_CODE; + orgChild1.JOB_CODE = item.JOB_CODE; + orgChild1.orgRevisionId = orgRevision.id; + orgChild1.createdUserId = request.user.sub; + orgChild1.createdFullName = request.user.name; + orgChild1.lastUpdateUserId = request.user.sub; + orgChild1.lastUpdateFullName = request.user.name; + orgChild1.createdAt = new Date(); + orgChild1.lastUpdatedAt = new Date(); + await this.orgChild1Repo.save(orgChild1); + }), + ); - await Promise.all( - IMPORT_CHILD3.map(async (item) => { - const orgChild3 = new OrgChild3(); - orgChild3.orgRootId = orgRoot.id; - orgChild3.orgChild1Id = orgChild1.id; - orgChild3.orgChild2Id = orgChild2.id; - orgChild3.orgChild3Name = item.orgChild3; - orgChild3.orgChild3ShortName = item.orgShortname; - const rank: any = item.orgRank; - orgChild3.orgChild3Rank = rank; - orgChild3.orgChild3RankSub = item.orgSubRank; - orgChild3.DEPARTMENT_CODE = item.DEPARTMENT_CODE; - orgChild3.DIVISION_CODE = item.DIVISION_CODE; - orgChild3.SECTION_CODE = item.SECTION_CODE; - orgChild3.JOB_CODE = item.JOB_CODE; - orgChild3.orgRevisionId = orgRevision.id; - orgChild3.createdUserId = request.user.sub; - orgChild3.createdFullName = request.user.name; - orgChild3.lastUpdateUserId = request.user.sub; - orgChild3.lastUpdateFullName = request.user.name; - orgChild3.createdAt = new Date(); - orgChild3.lastUpdatedAt = new Date(); - await this.orgChild3Repo.save(orgChild3); - }), - ); - }), - ); - }), - ); + //create child2 + const IMPORT_CHILD2 = await this.IMPORT_ORGRepo.find({ + where: { + orgRoot: Not(""), + orgChild1: Not(""), + orgChild2: Not(""), + orgChild3: "", + }, + }); + await Promise.all( + IMPORT_CHILD2.map(async (item) => { + const orgChild2 = new OrgChild2(); + let orgRoot = await this.orgRootRepo.findOne({ + where: { orgRootName: item.orgRoot }, + }); + if (orgRoot == null) { + orgRoot = new OrgRoot(); + orgRoot.orgRootName = item.orgRoot; + orgRoot.orgRootShortName = item.orgShortname; + const rank: any = item.orgRank; + orgRoot.orgRootRank = rank; + orgRoot.orgRootRankSub = item.orgSubRank; + orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgRoot.DIVISION_CODE = item.DIVISION_CODE; + orgRoot.SECTION_CODE = item.SECTION_CODE; + orgRoot.JOB_CODE = item.JOB_CODE; + orgRoot.orgRevisionId = orgRevision.id; + orgRoot.createdUserId = request.user.sub; + orgRoot.createdFullName = request.user.name; + orgRoot.lastUpdateUserId = request.user.sub; + orgRoot.lastUpdateFullName = request.user.name; + orgRoot.createdAt = new Date(); + orgRoot.lastUpdatedAt = new Date(); + await this.orgRootRepo.save(orgRoot); + } + let orgChild1 = await this.orgChild1Repo.findOne({ + where: { orgChild1Name: item.orgChild1 }, + }); + if (orgChild1 == null) { + orgChild1 = new OrgChild1(); + orgChild1.orgRootId = orgRoot.id; + orgChild1.orgChild1Name = item.orgChild1; + orgChild1.orgChild1ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild1.orgChild1Rank = rank; + orgChild1.orgChild1RankSub = item.orgSubRank; + orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild1.DIVISION_CODE = item.DIVISION_CODE; + orgChild1.SECTION_CODE = item.SECTION_CODE; + orgChild1.JOB_CODE = item.JOB_CODE; + orgChild1.orgRevisionId = orgRevision.id; + orgChild1.createdUserId = request.user.sub; + orgChild1.createdFullName = request.user.name; + orgChild1.lastUpdateUserId = request.user.sub; + orgChild1.lastUpdateFullName = request.user.name; + orgChild1.createdAt = new Date(); + orgChild1.lastUpdatedAt = new Date(); + await this.orgChild1Repo.save(orgChild1); + } + orgChild2.orgRootId = orgRoot.id; + orgChild2.orgChild1Id = orgChild1.id; + orgChild2.orgChild2Name = item.orgChild2; + orgChild2.orgChild2ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild2.orgChild2Rank = rank; + orgChild2.orgChild2RankSub = item.orgSubRank; + orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild2.DIVISION_CODE = item.DIVISION_CODE; + orgChild2.SECTION_CODE = item.SECTION_CODE; + orgChild2.JOB_CODE = item.JOB_CODE; + orgChild2.orgRevisionId = orgRevision.id; + orgChild2.createdUserId = request.user.sub; + orgChild2.createdFullName = request.user.name; + orgChild2.lastUpdateUserId = request.user.sub; + orgChild2.lastUpdateFullName = request.user.name; + orgChild2.createdAt = new Date(); + orgChild2.lastUpdatedAt = new Date(); + await this.orgChild2Repo.save(orgChild2); + }), + ); + + //create child3 + const IMPORT_CHILD3 = await this.IMPORT_ORGRepo.find({ + where: { + orgRoot: Not(""), + orgChild1: Not(""), + orgChild2: Not(""), + orgChild3: Not(""), + }, + }); + + await Promise.all( + IMPORT_CHILD3.map(async (item) => { + const orgChild3 = new OrgChild3(); + let orgRoot = await this.orgRootRepo.findOne({ + where: { orgRootName: item.orgRoot }, + }); + if (orgRoot == null) { + orgRoot = new OrgRoot(); + orgRoot.orgRootName = item.orgRoot; + orgRoot.orgRootShortName = item.orgShortname; + const rank: any = item.orgRank; + orgRoot.orgRootRank = rank; + orgRoot.orgRootRankSub = item.orgSubRank; + orgRoot.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgRoot.DIVISION_CODE = item.DIVISION_CODE; + orgRoot.SECTION_CODE = item.SECTION_CODE; + orgRoot.JOB_CODE = item.JOB_CODE; + orgRoot.orgRevisionId = orgRevision.id; + orgRoot.createdUserId = request.user.sub; + orgRoot.createdFullName = request.user.name; + orgRoot.lastUpdateUserId = request.user.sub; + orgRoot.lastUpdateFullName = request.user.name; + orgRoot.createdAt = new Date(); + orgRoot.lastUpdatedAt = new Date(); + await this.orgRootRepo.save(orgRoot); + } + let orgChild1 = await this.orgChild1Repo.findOne({ + where: { orgChild1Name: item.orgChild1 }, + }); + if (orgChild1 == null) { + orgChild1 = new OrgChild1(); + orgChild1.orgRootId = orgRoot.id; + orgChild1.orgChild1Name = item.orgChild1; + orgChild1.orgChild1ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild1.orgChild1Rank = rank; + orgChild1.orgChild1RankSub = item.orgSubRank; + orgChild1.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild1.DIVISION_CODE = item.DIVISION_CODE; + orgChild1.SECTION_CODE = item.SECTION_CODE; + orgChild1.JOB_CODE = item.JOB_CODE; + orgChild1.orgRevisionId = orgRevision.id; + orgChild1.createdUserId = request.user.sub; + orgChild1.createdFullName = request.user.name; + orgChild1.lastUpdateUserId = request.user.sub; + orgChild1.lastUpdateFullName = request.user.name; + orgChild1.createdAt = new Date(); + orgChild1.lastUpdatedAt = new Date(); + await this.orgChild1Repo.save(orgChild1); + } + let orgChild2 = await this.orgChild2Repo.findOne({ + where: { orgChild2Name: item.orgChild2 }, + }); + if (orgChild2 == null) { + orgChild2 = new OrgChild2(); + orgChild2.orgRootId = orgRoot.id; + orgChild2.orgChild1Id = orgChild1.id; + orgChild2.orgChild2Name = item.orgChild2; + orgChild2.orgChild2ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild2.orgChild2Rank = rank; + orgChild2.orgChild2RankSub = item.orgSubRank; + orgChild2.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild2.DIVISION_CODE = item.DIVISION_CODE; + orgChild2.SECTION_CODE = item.SECTION_CODE; + orgChild2.JOB_CODE = item.JOB_CODE; + orgChild2.orgRevisionId = orgRevision.id; + orgChild2.createdUserId = request.user.sub; + orgChild2.createdFullName = request.user.name; + orgChild2.lastUpdateUserId = request.user.sub; + orgChild2.lastUpdateFullName = request.user.name; + orgChild2.createdAt = new Date(); + orgChild2.lastUpdatedAt = new Date(); + await this.orgChild2Repo.save(orgChild2); + } + + orgChild3.orgRootId = orgRoot.id; + orgChild3.orgChild1Id = orgChild1.id; + orgChild3.orgChild2Id = orgChild2.id; + orgChild3.orgChild3Name = item.orgChild3; + orgChild3.orgChild3ShortName = item.orgShortname; + const rank: any = item.orgRank; + orgChild3.orgChild3Rank = rank; + orgChild3.orgChild3RankSub = item.orgSubRank; + orgChild3.DEPARTMENT_CODE = item.DEPARTMENT_CODE; + orgChild3.DIVISION_CODE = item.DIVISION_CODE; + orgChild3.SECTION_CODE = item.SECTION_CODE; + orgChild3.JOB_CODE = item.JOB_CODE; + orgChild3.orgRevisionId = orgRevision.id; + orgChild3.createdUserId = request.user.sub; + orgChild3.createdFullName = request.user.name; + orgChild3.lastUpdateUserId = request.user.sub; + orgChild3.lastUpdateFullName = request.user.name; + orgChild3.createdAt = new Date(); + orgChild3.lastUpdatedAt = new Date(); + await this.orgChild3Repo.save(orgChild3); }), ); return new HttpSuccess(); diff --git a/src/entities/HR_EDUCATION.ts b/src/entities/HR_EDUCATION.ts index 1101b60f..a107632c 100644 --- a/src/entities/HR_EDUCATION.ts +++ b/src/entities/HR_EDUCATION.ts @@ -45,4 +45,11 @@ export class HR_EDUCATION { default: null, }) INSTITUE: string; + + @Column({ + nullable: true, + length: 255, + default: null, + }) + EDUCATION_SEQ: string; } diff --git a/src/entities/OFFICER.ts b/src/entities/OFFICER.ts new file mode 100644 index 00000000..2eed0314 --- /dev/null +++ b/src/entities/OFFICER.ts @@ -0,0 +1,91 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("OFFICER") +export class OFFICER { + @PrimaryGeneratedColumn() + id!: number; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // RET_YEAR: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ID: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + MP_CATEGORY: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + MP_LEVEL: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BORN: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BEGIN_ENTRY_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SEX: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LINE_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SALARY: string; +} From 408a3a76440a5f14971e8a4213b005cfda6a5d87 Mon Sep 17 00:00:00 2001 From: kittapath Date: Wed, 12 Feb 2025 11:22:03 +0700 Subject: [PATCH 8/9] update report --- src/controllers/ReportController.ts | 357 +++++++++++++++------------- 1 file changed, 197 insertions(+), 160 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 1139f2d3..5edcc77c 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1,4 +1,14 @@ -import { Controller, Get, Route, Security, Tags, SuccessResponse, Response, Path, Query } from "tsoa"; +import { + Controller, + Get, + Route, + Security, + Tags, + SuccessResponse, + Response, + Path, + Query, +} from "tsoa"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; @@ -37,7 +47,7 @@ export class ReportController extends Controller { private posMasterRepository = AppDataSource.getRepository(PosMaster); private profileRepository = AppDataSource.getRepository(Profile); private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); - /** + /** * API รายงานสถิติข้อมูลข้าราชการ กทม. สามัญ * * @summary รายงานสถิติข้อมูลข้าราชการ กทม. สามัญ @@ -60,69 +70,79 @@ export class ReportController extends Controller { const minAge = ageMin ?? 18; const maxAge = ageMax ?? 60; - + if (minAge > maxAge) { throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax"); } - const yearInAD = year?year:null; + const yearInAD = year ? year : null; const currentRevision = await this.orgRevisionRepository.findOne({ - where:{ - orgRevisionIsCurrent: true - } + where: { + orgRevisionIsCurrent: true, + }, }); const rawdataProfile = await this.posMasterRepository - .createQueryBuilder('posMaster') - .leftJoinAndSelect('posMaster.current_holder', 'current_holder') - .leftJoinAndSelect('posMaster.positions', 'positions') - .leftJoinAndSelect('posMaster.orgRoot', 'orgRoot') - .leftJoinAndSelect('positions.posExecutive', 'posExecutive') - .leftJoinAndSelect('current_holder.posType', 'posType') - .leftJoinAndSelect('current_holder.posLevel', 'posLevel') - .leftJoinAndSelect('current_holder.profileEducations', 'profileEducations') - .where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id }) - .andWhere(rootId?'posMaster.orgRootId = :rootId': "1=1", { rootId: rootId }) - .andWhere('posMaster.current_holderId Is Not Null') - .andWhere('positions.positionIsSelected = :positionIsSelected', { positionIsSelected: true }) - .andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD }) - .andWhere(` + .createQueryBuilder("posMaster") + .leftJoinAndSelect("posMaster.current_holder", "current_holder") + .leftJoinAndSelect("posMaster.positions", "positions") + .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") + .leftJoinAndSelect("positions.posExecutive", "posExecutive") + .leftJoinAndSelect("current_holder.posType", "posType") + .leftJoinAndSelect("current_holder.posLevel", "posLevel") + .leftJoinAndSelect("current_holder.profileEducations", "profileEducations") + .where("posMaster.orgRevisionId = :currentRevisionId", { + currentRevisionId: currentRevision?.id, + }) + .andWhere(rootId ? "posMaster.orgRootId = :rootId" : "1=1", { rootId: rootId }) + .andWhere("posMaster.current_holderId Is Not Null") + .andWhere("positions.positionIsSelected = :positionIsSelected", { positionIsSelected: true }) + .andWhere(yearInAD && yearInAD != null ? "YEAR(current_holder.dateAppoint) = :year" : "1=1", { + year: yearInAD, + }) + .andWhere( + ` TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge - `, { minAge, maxAge }) - .orderBy("posType.posTypeName","ASC") - .getMany(); - if(!rawdataProfile){ + `, + { minAge, maxAge }, + ) + .orderBy("posType.posTypeName", "ASC") + .getMany(); + if (!rawdataProfile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); } - const mapData = rawdataProfile - .map((x) => { - const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0]; + const mapData = rawdataProfile.map((x) => { + const latestEducation = x.current_holder.profileEducations.sort( + (a: any, b: any) => b.endDate - a.startDate, + )[0]; return { name: x.current_holder.firstName + " " + x.current_holder.lastName, - affiliation: x.orgRoot.orgRootName??"-", - gender: x.current_holder.gender??"-", - positionName: x.positions[0]?x.positions[0].positionName:"-", - status: x.current_holder.relationship??"-", - posType: x.current_holder.posType.posTypeName??"-", - posLevel: x.current_holder.posLevel.posLevelName??"-", + affiliation: x.orgRoot.orgRootName ?? "-", + gender: x.current_holder.gender ?? "-", + positionName: x.positions[0] ? x.positions[0].positionName : "-", + status: x.current_holder.relationship ?? "-", + posType: x.current_holder.posType.posTypeName ?? "-", + posLevel: x.current_holder.posLevel.posLevelName ?? "-", degree: latestEducation ? latestEducation.educationLevel : "-", - posExecutive: x.positions[0].posExecutive?x.positions[0].posExecutive.posExecutiveName:"-", + posExecutive: x.positions[0].posExecutive + ? x.positions[0].posExecutive.posExecutiveName + : "-", currentPreiodPos: "-", levelPeriodPos: "-", }; }); - const groupedData = mapData.reduce((acc:any, item) => { - const key = `${item.posType} - ${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.positionName} - ${item.posLevel} - ${item.posExecutive || 'ไม่พบข้อมูล'} `; + const groupedData = mapData.reduce((acc: any, item) => { + const key = `${item.posType} - ${item.affiliation} - ${item.gender} - ${item.degree || "ไม่พบข้อมูล"} - ${item.status || "ไม่พบข้อมูล"} - ${item.positionName} - ${item.posLevel} - ${item.posExecutive || "ไม่พบข้อมูล"} `; if (!acc[key]) { acc[key] = { - posType: item.posType && item.posType != "" ? item.posType: "-", - affiliation: item.affiliation && item.affiliation != "" ? item.affiliation: "-", - gender: item.gender && item.gender != "" ? item.gender: "-", - degree: item.degree && item.degree != "" ? item.degree: "-", - status: item.status && item.status != "" ? item.status: "-", - positionName: item.positionName && item.positionName != "" ? item.positionName: "-", - posLevel: item.posLevel && item.posLevel != "" ? item.posLevel: "-", - posExecutive: item.posExecutive && item.posExecutive != "" ? item.posExecutive: "-", + posType: item.posType && item.posType != "" ? item.posType : "-", + affiliation: item.affiliation && item.affiliation != "" ? item.affiliation : "-", + gender: item.gender && item.gender != "" ? item.gender : "-", + degree: item.degree && item.degree != "" ? item.degree : "-", + status: item.status && item.status != "" ? item.status : "-", + positionName: item.positionName && item.positionName != "" ? item.positionName : "-", + posLevel: item.posLevel && item.posLevel != "" ? item.posLevel : "-", + posExecutive: item.posExecutive && item.posExecutive != "" ? item.posExecutive : "-", currentPreiodPos: "-", levelPeriodPos: "-", count: 0, @@ -132,23 +152,25 @@ export class ReportController extends Controller { return acc; }, {}); - + const result = Object.values(groupedData).map((item: any) => ({ - ...item , - count: Extension.ToThaiNumber(item.count.toString()), + ...item, + count: Extension.ToThaiNumber(item.count.toString()), })); - + return new HttpSuccess({ template: "registry-officer", reportName: "xlsx-report", data: { - year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), + year: year + ? Extension.ToThaiNumber((year + 543).toString()) + : Extension.ToThaiNumber((new Date().getFullYear() + 543).toString()), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), - list: result + list: result, }, }); } - /** + /** * API รายงานสถิติข้อมูลลูกจ้างประจำ กทม. * * @summary รายงานสถิติข้อมูลลูกจ้างประจำ กทม. @@ -171,64 +193,73 @@ export class ReportController extends Controller { const minAge = ageMin ?? 18; const maxAge = ageMax ?? 60; - + if (minAge > maxAge) { throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax"); } - const yearInAD = year?year:null; + const yearInAD = year ? year : null; const currentRevision = await this.orgRevisionRepository.findOne({ - where:{ - orgRevisionIsCurrent: true - } + where: { + orgRevisionIsCurrent: true, + }, }); const rawdataProfile = await this.empPosMasterRepository - .createQueryBuilder('posMaster') - .leftJoinAndSelect('posMaster.current_holder', 'current_holder') - .leftJoinAndSelect('posMaster.positions', 'positions') - .leftJoinAndSelect('posMaster.orgRoot', 'orgRoot') - .leftJoinAndSelect('current_holder.posType', 'posType') - .leftJoinAndSelect('current_holder.posLevel', 'posLevel') - .leftJoinAndSelect('current_holder.profileEducations', 'profileEducations') - .where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id }) - .andWhere(rootId?'posMaster.orgRootId = :rootId': "1=1", { rootId: rootId }) - .andWhere('posMaster.current_holderId Is Not Null') - .andWhere('positions.positionIsSelected = :positionIsSelected', { positionIsSelected: true }) - .andWhere( yearInAD && yearInAD != null? 'YEAR(current_holder.dateAppoint) = :year': "1=1", { year: yearInAD }) - .andWhere(` + .createQueryBuilder("posMaster") + .leftJoinAndSelect("posMaster.current_holder", "current_holder") + .leftJoinAndSelect("posMaster.positions", "positions") + .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holder.posType", "posType") + .leftJoinAndSelect("current_holder.posLevel", "posLevel") + .leftJoinAndSelect("current_holder.profileEducations", "profileEducations") + .where("posMaster.orgRevisionId = :currentRevisionId", { + currentRevisionId: currentRevision?.id, + }) + .andWhere(rootId ? "posMaster.orgRootId = :rootId" : "1=1", { rootId: rootId }) + .andWhere("posMaster.current_holderId Is Not Null") + .andWhere("positions.positionIsSelected = :positionIsSelected", { positionIsSelected: true }) + .andWhere(yearInAD && yearInAD != null ? "YEAR(current_holder.dateAppoint) = :year" : "1=1", { + year: yearInAD, + }) + .andWhere( + ` TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) >= :minAge AND TIMESTAMPDIFF(YEAR, current_holder.birthDate, CURDATE()) <= :maxAge - `, { minAge, maxAge }) - .orderBy("posType.posTypeName","ASC") - .getMany(); - if(!rawdataProfile){ + `, + { minAge, maxAge }, + ) + .orderBy("posType.posTypeName", "ASC") + .getMany(); + if (!rawdataProfile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); } const mapData = rawdataProfile.map((x) => { - const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0]; + const latestEducation = x.current_holder.profileEducations.sort( + (a: any, b: any) => b.endDate - a.startDate, + )[0]; return { name: x.current_holder.firstName + " " + x.current_holder.lastName, - affiliation: x.orgRoot.orgRootName??"-", - gender: x.current_holder.gender??"-", - positionName: x.positions[0]?x.positions[0].positionName: "-", - status: x.current_holder.relationship??"-", - posType: x.current_holder.posType.posTypeName??"-", - posLevel: x.current_holder.posLevel.posLevelName??"-", - degree: latestEducation ? latestEducation.educationLevel : "-", + affiliation: x.orgRoot.orgRootName ?? "-", + gender: x.current_holder.gender ?? "-", + positionName: x.positions[0] ? x.positions[0].positionName : "-", + status: x.current_holder.relationship ?? "-", + posType: x.current_holder.posType.posTypeName ?? "-", + posLevel: x.current_holder.posLevel.posLevelName ?? "-", + degree: latestEducation ? latestEducation.educationLevel : "-", period: "-", }; }); - const groupedData = mapData.reduce((acc:any, item) => { - const key = `${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.posType} - ${item.positionName} - ${item.posLevel} + const groupedData = mapData.reduce((acc: any, item) => { + const key = `${item.affiliation} - ${item.gender} - ${item.degree || "ไม่พบข้อมูล"} - ${item.status || "ไม่พบข้อมูล"} - ${item.posType} - ${item.positionName} - ${item.posLevel} `; if (!acc[key]) { acc[key] = { - affiliation: item.affiliation && item.affiliation != ""?item.affiliation:"-", - gender: item.gender && item.gender != ""?item.gender:"-", - degree: item.degree && item.degree != ""?item.degree:"-", - status: item.status && item.status != ""?item.status:"-", - posType: item.posType && item.posType != ""?item.posType:"-", - positionName: item.positionName && item.positionName != ""?item.positionName:"-", + affiliation: item.affiliation && item.affiliation != "" ? item.affiliation : "-", + gender: item.gender && item.gender != "" ? item.gender : "-", + degree: item.degree && item.degree != "" ? item.degree : "-", + status: item.status && item.status != "" ? item.status : "-", + posType: item.posType && item.posType != "" ? item.posType : "-", + positionName: item.positionName && item.positionName != "" ? item.positionName : "-", posLevel: Extension.ToThaiNumber(item.posLevel.toString()), period: "-", count: 0, @@ -240,20 +271,21 @@ export class ReportController extends Controller { }, {}); const result = Object.values(groupedData).map((item: any) => ({ - ...item , - count: Extension.ToThaiNumber(item.count.toString()) + ...item, + count: Extension.ToThaiNumber(item.count.toString()), })); - + return new HttpSuccess({ template: "registry-emp", reportName: "xlsx-report", data: { - year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()), + year: year + ? Extension.ToThaiNumber((year + 543).toString()) + : Extension.ToThaiNumber((new Date().getFullYear() + 543).toString()), date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), - list: result + list: result, }, }); - } /** @@ -6468,11 +6500,11 @@ export class ReportController extends Controller { @Get("report4/{rootId}") async findReport4(@Path() rootId: string) { - const orgRootData = await this.orgRootRepository.findOne({ - where: { id: rootId } + const orgRootData = await this.orgRootRepository.findOne({ + where: { id: rootId }, }); if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - + const posMaster = await this.posMasterRepository .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.positions", "position") @@ -6482,17 +6514,20 @@ export class ReportController extends Controller { .orderBy("posType.posTypeRank", "ASC") .addOrderBy("posLevel.posLevelRank", "ASC") .getMany(); - - const _posMaster = posMaster - .map((x) => ({ - type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), - typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), - level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), - levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""), - positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""), - })) - const groupedData = _posMaster.reduce((acc:any, curr:any) => { + const _posMaster = posMaster.map((x) => ({ + type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), + typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), + level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), + levelRank: [ + ...new Set( + x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`), + ), + ].join(""), + positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""), + })); + + const groupedData = _posMaster.reduce((acc: any, curr: any) => { const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`; if (!acc[key]) { acc[key] = { ...curr, total: 1 }; @@ -6501,7 +6536,7 @@ export class ReportController extends Controller { } return acc; }, {}); - + let result = Object.values(groupedData) .map((x: any) => ({ type: x.type, @@ -6523,16 +6558,16 @@ export class ReportController extends Controller { let _total: number = 0; let _reslut = new Array(); - result.forEach((x:any, idx:number) => { + result.forEach((x: any, idx: number) => { allTotal += x.total; total += x.total; - if(x.type === tmpType) { + if (x.type === tmpType) { _reslut.push({ ...x, - type: "" - }) - }else { - if(x.type !== tmpType && tmpType != "") { + type: "", + }); + } else { + if (x.type !== tmpType && tmpType != "") { _total = total - x.total; _reslut.push({ type: "", @@ -6541,13 +6576,13 @@ export class ReportController extends Controller { levelRank: "", total: _total, remark: "", - }) + }); total = x.total; _total = 0; } _reslut.push({ - ...x - }) + ...x, + }); } tmpType = x.type; }); @@ -6559,7 +6594,7 @@ export class ReportController extends Controller { levelRank: "", total: total, remark: "", - }) + }); _reslut.push({ type: "", typeRank: "", @@ -6569,24 +6604,24 @@ export class ReportController extends Controller { remark: "", }); - return new HttpSuccess({ - template: "report4", - reportName: "report4", - data: { + return new HttpSuccess({ + template: "report4", + reportName: "report4", + data: { dateCurrent: Extension.ToThaiShortDate(new Date()), rootName: orgRootData ? orgRootData.orgRootName : "-", - data: _reslut - } - }); + data: _reslut, + }, + }); } @Get("report4-employee/{rootId}") async findReportEmp4(@Path() rootId: string) { - const orgRootData = await this.orgRootRepository.findOne({ - where: { id: rootId } + const orgRootData = await this.orgRootRepository.findOne({ + where: { id: rootId }, }); if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - + const posMaster = await this.empPosMasterRepository .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.positions", "position") @@ -6596,17 +6631,20 @@ export class ReportController extends Controller { .orderBy("posType.posTypeRank", "ASC") .addOrderBy("posLevel.posLevelRank", "ASC") .getMany(); - - const _posMaster = posMaster - .map((x) => ({ - type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), - typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), - level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), - levelRank: [...new Set(x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`))].join(""), - positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""), - })) - const groupedData = _posMaster.reduce((acc:any, curr:any) => { + const _posMaster = posMaster.map((x) => ({ + type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","), + typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""), + level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","), + levelRank: [ + ...new Set( + x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`), + ), + ].join(""), + positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""), + })); + + const groupedData = _posMaster.reduce((acc: any, curr: any) => { const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`; if (!acc[key]) { acc[key] = { ...curr, total: 1 }; @@ -6615,14 +6653,14 @@ export class ReportController extends Controller { } return acc; }, {}); - + let result = Object.values(groupedData) .map((x: any) => ({ type: x.type, typeRank: parseInt(x.typeRank), level: x.level, levelRank: parseInt(x.levelRank), - + total: x.total, remark: x.positions, })) @@ -6638,16 +6676,16 @@ export class ReportController extends Controller { let _total: number = 0; let _reslut = new Array(); - result.forEach((x:any, idx:number) => { + result.forEach((x: any, idx: number) => { allTotal += x.total; total += x.total; - if(x.type === tmpType) { + if (x.type === tmpType) { _reslut.push({ ...x, - type: "" - }) - }else { - if(x.type !== tmpType && tmpType != "") { + type: "", + }); + } else { + if (x.type !== tmpType && tmpType != "") { _total = total - x.total; _reslut.push({ type: "", @@ -6656,13 +6694,13 @@ export class ReportController extends Controller { levelRank: "", total: _total, remark: "", - }) + }); total = x.total; _total = 0; } _reslut.push({ - ...x - }) + ...x, + }); } tmpType = x.type; }); @@ -6674,7 +6712,7 @@ export class ReportController extends Controller { levelRank: "", total: total, remark: "", - }) + }); _reslut.push({ type: "", typeRank: "", @@ -6684,15 +6722,14 @@ export class ReportController extends Controller { remark: "", }); - return new HttpSuccess({ - template: "report4", - reportName: "report4", - data: { + return new HttpSuccess({ + template: "report4", + reportName: "report4", + data: { dateCurrent: Extension.ToThaiShortDate(new Date()), rootName: orgRootData ? orgRootData.orgRootName : "-", - data: _reslut - } - }); + data: _reslut, + }, + }); } - } From b94d4e1b9309c8670ed3aacfe6efe0b3dc36e433 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 14 Feb 2025 09:58:51 +0700 Subject: [PATCH 9/9] edit dna --- src/controllers/ImportDataController.ts | 271 +++++++++++++++++- .../OrganizationDotnetController.ts | 40 +-- src/entities/OFFICER.ts | 42 +++ 3 files changed, 324 insertions(+), 29 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index c6877280..0e4ada5c 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -45,6 +45,8 @@ import { OrgChild4 } from "../entities/OrgChild4"; import { IMPORT_ORG } from "../entities/IMPORT_ORG"; import { OrgRevision } from "../entities/OrgRevision"; import { OFFICER } from "../entities/OFFICER"; +import { Position } from "../entities/Position"; +import { PosMaster } from "../entities/PosMaster"; @Route("api/v1/org/upload") @Tags("UPLOAD") @@ -85,23 +87,143 @@ export class ImportDataController extends Controller { private orgChild4Repo = AppDataSource.getRepository(OrgChild4); private IMPORT_ORGRepo = AppDataSource.getRepository(IMPORT_ORG); private OFFICERRepo = AppDataSource.getRepository(OFFICER); + private positionRepo = AppDataSource.getRepository(Position); + private posMasterRepo = AppDataSource.getRepository(PosMaster); /** * @summary ทะเบียนประวัติ ข้าราชการ */ @Post("uploadProfile-Officer") async UploadFileSqlOfficer(@Request() request: { user: Record }) { const OFFICER = await this.OFFICERRepo.find(); + // let users = []; + let rowCount = 0; + // const filePath = path.resolve(__dirname, "OFFICER.csv"); // Corrected file path + // const readStream = fs.createReadStream(filePath).pipe(csvParser()); + // let profiles: any = []; let null_: any = null; + let profile: any; + // await Promise.all( + // OFFICER.map(async (item) => { for await (const item of OFFICER) { - let existingProfile = await this.profileRepo.findOne({ + // readStream.map(async (item: any) => { + rowCount++; + let type_: any = null; + let level_: any = null; + profile = null; + profile = new Profile(); + // if (item["FLAG_RETIRE_STATUSxxxx != "" && item["FLAG_RETIRE_STATUSxxxx != null) { + // continue; + // } + // if (item["FLAG_PERSON_TYPExxxx != "1") { + // continue; + // } + // if (new Date(item.RET_YEAR).getFullYear() >= 2567) { + // return; + // } + + const existingProfile = await this.profileRepo.findOne({ where: { citizenId: item.ID }, }); - if (existingProfile == null) { - } else { - existingProfile.position = item["WORK_LINE_NAME"] == "" ? null_ : item["WORK_LINE_NAME"]; - await this.profileRepo.save(existingProfile); + if (existingProfile) { + profile.id = existingProfile.id; + // continue; } + + if (item.MP_CATEGORY) { + type_ = await this.posTypeRepo.findOne({ + where: { posTypeName: item.MP_CATEGORY }, + }); + } + if (item.MP_LEVEL) { + if (type_ == null) { + level_ = await this.posLevelRepo.findOne({ + where: { + posLevelName: item.MP_LEVEL, + }, + }); + } else { + level_ = await this.posLevelRepo.findOne({ + where: { + posLevelName: item.MP_LEVEL, + posTypeId: type_.id, + }, + }); + } + } + + let dateRetire = new Date(item.BORN); + profile.citizenId = item.ID == "" ? "" : item.ID; + profile.rank = + item.RANK_NAME == "" || + item.RANK_NAME == "นาย" || + item.RANK_NAME == "นาง" || + item.RANK_NAME == "นางสาว" + ? null + : item.RANK_NAME; + profile.prefix = item.RANK_NAME == "" ? null : item.RANK_NAME; + profile.prefixMain = + item.RANK_NAME == "" || + (item.RANK_NAME != "นาย" && item.RANK_NAME != "นาง" && item.RANK_NAME != "นางสาว") + ? null + : item.RANK_NAME; + profile.firstName = item.FNAME == "" ? null : item.FNAME; + profile.lastName = item.LNAME == "" ? null : item.LNAME; + profile.gender = item.SEX == "1" ? "ชาย" : item.SEX == "2" ? "หญิง" : null_; + profile.birthDate = item.BORN == "" ? null_ : new Date(item.BORN); + profile.dateAppoint = item.BEGIN_ENTRY_DATE == "" ? null_ : new Date(item.BEGIN_ENTRY_DATE); + profile.dateStart = item.BEGIN_ENTRY_DATE == "" ? null_ : new Date(item.BEGIN_ENTRY_DATE); + profile.dateRetire = dateRetire == null ? null_ : calculateRetireDate(dateRetire); + profile.dateRetireLaw = dateRetire == null ? null_ : calculateRetireLaw(dateRetire); + profile.position = item.WORK_LINE_NAME == "" ? null : item.WORK_LINE_NAME; + profile.posTypeId = + type_ != null && type_.posTypeName == item.MP_CATEGORY && type_ ? type_.id : null; + profile.posLevelId = + level_ != null && level_.posLevelName == item.MP_LEVEL && level_ ? level_.id : null; + // profile.relationship = + // item.สถานภาพ == "" ? "" : Extension.CheckRelationship(item.สถานภาพ); + // profile.position = + // item.WORK_LINE_NAME == "" ? "" : Extension.CheckRelationship(item.WORK_LINE_NAME); + profile.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"]; + // const level = await this.posLevelRepo.findOne({ + // where: { + // posLevelName: item.MP_LEVEL, + // posType: { + // posTypeName: item.MP_Type, + // }, + // }, + // }); + // profile.posLevelId = level?.id ?? null_; + // const type = await this.posTypeRepo.findOne({ + // where: { posTypeName: item.MP_Type }, + // }); + // profile.posTypeId = type?.id ?? null_; + profile.amount = item.SALARY == "" ? 0 : Number(Extension.CheckRelationship(item.SALARY)); + // profile.isLeave = + // item.FLAG_RETIRE_STATUSxxxx == "" || item.FLAG_RETIRE_STATUSxxxx == null ? false : true; + profile.createdUserId = request.user.sub; + profile.createdFullName = request.user.name; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + profile.createdAt = new Date(); + profile.lastUpdatedAt = new Date(); + // profiles.push(profile); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + + // if (profiles.length === BATCH_SIZE) { + await this.profileRepo.save(profile); + // console.log(profile); + // profiles = await []; + // if (global.gc) { + // global.gc(); + // } + // } } + // }), + // ); + // ) + // ); + // console.log(rowCount); + // await this.profileRepo.save(profiles); return new HttpSuccess(); } @@ -116,19 +238,21 @@ export class ImportDataController extends Controller { const readStream = fs.createReadStream(filePath).pipe(csvParser()); let profiles: any = []; let null_: any = null; + let profileEmp: any; for await (const item of readStream) { rowCount++; - const profileEmp = new ProfileEmployee(); + profileEmp = null; + profileEmp = new ProfileEmployee(); // if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) { // continue; // } if (item["FLAG_PERSON_TYPE"] != "6") { continue; } - if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) { - continue; - } + // if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) { + // continue; + // } const existingProfile = await this.profileEmpRepo.findOne({ where: { citizenId: item["ID"] }, }); @@ -168,6 +292,8 @@ export class ImportDataController extends Controller { profileEmp.salaryLevel = item["SALARY_LEVEL_CODE"] == "" ? null : item["SALARY_LEVEL_CODE"]; profileEmp.relationship = item["MARRIAGE_STATE"] == "" ? "" : Extension.CheckRelationship(item["MARRIAGE_STATE"]); + profileEmp.amount = + item["SALARY"] == "" ? 0 : Number(Extension.CheckRelationship(item.SALARY)); profileEmp.createdUserId = request.user.sub; profileEmp.createdFullName = request.user.name; profileEmp.lastUpdateUserId = request.user.sub; @@ -1669,4 +1795,131 @@ export class ImportDataController extends Controller { ); return new HttpSuccess(); } + /** + * @summary ทะเบียนประวัติ ข้าราชการ + */ + @Post("mapposition-Officer") + async MapPositionOfficer(@Request() request: { user: Record }) { + const [officer, total] = await AppDataSource.getRepository(OFFICER) + .createQueryBuilder("OFFICER") + // .skip(0) + // .take(20) + .getManyAndCount(); + let rowCount = 0; + let null_: any = null; + let type_: any = null; + let level_: any = null; + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }); + if (orgRevision == null) return new HttpSuccess(); + for await (const item of officer) { + rowCount++; + + const existingProfile = await this.profileRepo.findOne({ + where: { citizenId: item.ID }, + }); + if (existingProfile == null) { + continue; + } + const orgRoot = await this.orgRootRepo.findOne({ + where: { orgRootName: item.DEPARTMENT_NAME, orgRevisionId: orgRevision.id }, + }); + if (orgRoot == null) { + continue; + } + const orgChild1 = await this.orgChild1Repo.findOne({ + where: { + orgChild1Name: item.DIVISION_NAME, + orgRoot: { orgRootName: item.DEPARTMENT_NAME }, + orgRevisionId: orgRevision.id, + }, + }); + const orgChild2 = await this.orgChild2Repo.findOne({ + where: { + orgChild2Name: item.SECTION_NAME, + orgChild1: { + orgChild1Name: item.DIVISION_NAME, + orgRoot: { orgRootName: item.DEPARTMENT_NAME }, + }, + orgRevisionId: orgRevision.id, + }, + }); + const 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, + }, + }); + let posMaster = new PosMaster(); + posMaster.orgRootId = orgRoot?.id ?? null_; + posMaster.orgChild1Id = orgChild1?.id ?? null_; + posMaster.orgChild2Id = orgChild2?.id ?? null_; + posMaster.orgChild3Id = orgChild3?.id ?? null_; + posMaster.statusReport = "PENDING"; + posMaster.isCondition = false; + posMaster.isStaff = false; + posMaster.isDirector = false; + posMaster.isSit = false; + posMaster.current_holderId = existingProfile.id; + posMaster.posMasterNo = item.SALARY == "" ? null_ : Number(item.POS_NUM_CODE); + posMaster.orgRevisionId = orgRevision.id; + posMaster.posMasterCreatedAt = new Date(); + posMaster.createdUserId = request.user.sub; + posMaster.createdFullName = request.user.name; + posMaster.lastUpdateUserId = request.user.sub; + posMaster.lastUpdateFullName = request.user.name; + posMaster.createdAt = new Date(); + posMaster.lastUpdatedAt = new Date(); + await this.posMasterRepo.save(posMaster); + posMaster.ancestorDNA = posMaster.id; + await this.posMasterRepo.save(posMaster); + + let position = new Position(); + if (item.MP_CATEGORY) { + type_ = await this.posTypeRepo.findOne({ + where: { posTypeName: item.MP_CATEGORY }, + }); + } + if (item.MP_LEVEL) { + if (type_ == null) { + level_ = await this.posLevelRepo.findOne({ + where: { + posLevelName: item.MP_LEVEL, + }, + }); + } else { + level_ = await this.posLevelRepo.findOne({ + where: { + posLevelName: item.MP_LEVEL, + posTypeId: type_.id, + }, + }); + } + } + position.posMasterId = posMaster.id; + position.isSpecial = false; + position.positionIsSelected = true; + position.createdUserId = request.user.sub; + position.createdFullName = request.user.name; + position.lastUpdateUserId = request.user.sub; + position.lastUpdateFullName = request.user.name; + position.createdAt = new Date(); + position.lastUpdatedAt = new Date(); + position.positionName = item.WORK_LINE_NAME == "" ? null_ : item.WORK_LINE_NAME; + position.posTypeId = + type_ != null && type_.posTypeName == item.MP_CATEGORY && type_ ? type_.id : null; + position.posLevelId = + level_ != null && level_.posLevelName == item.MP_LEVEL && level_ ? level_.id : null; + await this.positionRepo.save(position); + } + return new HttpSuccess(); + } } diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index e0a4a8e9..c9c49c45 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -1213,31 +1213,31 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgRoot.ancestorDNA ?? null, child1DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild3.ancestorDNA ?? null, child2DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild2.ancestorDNA ?? null, child3DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild3.ancestorDNA ?? null, child4DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild4.ancestorDNA ?? null, commander: fullname, posLevel: profile.posLevel?.posLevelName ?? null, posType: profile.posType?.posTypeName ?? null, @@ -1510,31 +1510,31 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgRoot.ancestorDNA ?? null, child1DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild1.ancestorDNA ?? null, child2DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild2.ancestorDNA ?? null, child3DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild3.ancestorDNA ?? null, child4DnaId: profile?.current_holders?.find( (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild4.ancestorDNA ?? null, commander: fullname, posLevel: profile.posLevel?.posLevelName ?? null, posType: profile.posType?.posTypeName ?? null, @@ -2276,7 +2276,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgRoot.ancestorDNA ?? null, child1: profile?.current_holders?.find( (x) => @@ -2294,7 +2294,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild1.ancestorDNA ?? null, child2: profile?.current_holders?.find( (x) => @@ -2312,7 +2312,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild2.ancestorDNA ?? null, child3: profile?.current_holders?.find( (x) => @@ -2330,7 +2330,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild3.ancestorDNA ?? null, child4: profile?.current_holders?.find( (x) => @@ -2348,7 +2348,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild4.ancestorDNA ?? null, posNo: shortName ?? "", }; }); @@ -2643,7 +2643,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgRoot.ancestorDNA ?? null, child1: profile?.current_holders?.find( (x) => @@ -2661,7 +2661,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild1.ancestorDNA ?? null, child2: profile?.current_holders?.find( (x) => @@ -2679,7 +2679,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild2.ancestorDNA ?? null, child3: profile?.current_holders?.find( (x) => @@ -2697,7 +2697,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild3.ancestorDNA ?? null, child4: profile?.current_holders?.find( (x) => @@ -2715,7 +2715,7 @@ export class OrganizationDotnetController extends Controller { (x) => x.orgRevision?.orgRevisionIsDraft == false && x.orgRevision?.orgRevisionIsCurrent == true, - )?.ancestorDNA ?? null, + )?.orgChild4.ancestorDNA ?? null, posNo: shortName ?? "", }; }); diff --git a/src/entities/OFFICER.ts b/src/entities/OFFICER.ts index 2eed0314..17632f72 100644 --- a/src/entities/OFFICER.ts +++ b/src/entities/OFFICER.ts @@ -88,4 +88,46 @@ export class OFFICER { default: null, }) SALARY: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_NAME: string; }