From cfb50383575472e156ff639e7bbe80b09446469f Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 11 Mar 2025 10:03:55 +0700 Subject: [PATCH 1/6] import edu mis --- src/controllers/ImportDataController.ts | 48 ++++++++++++++++++++----- src/entities/HR_EDUCATION.ts | 7 ++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index b8cc0c07..ca8689c7 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -1242,14 +1242,15 @@ export class ImportDataController extends Controller { for (const _item of profiles) { const existingProfile = await this.HR_EDUCATIONRepo.find({ where: { CIT: _item.citizenId }, - select: [ - "CIT", - "EDUCATION_CODE", - "START_EDUCATION_YEAR", - "EDUCATION_YEAR", - "INSTITUE", - "EDUCATION_SEQ", - ], + // select: [ + // "CIT", + // "EDUCATION_CODE", + // "START_EDUCATION_YEAR", + // "EDUCATION_YEAR", + // "INSTITUE", + // "EDUCATION_SEQ", + // ], + order: { EDUCATION_SEQ: "ASC" }, }); const educationLevel = await this.profileEducationRepo.findOne({ @@ -1281,7 +1282,36 @@ export class ImportDataController extends Controller { ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) : _null; // endDate = endDate ? new Date(endDate, 0, 1) : _null; - + if (item.FLAG_EDUCATION == "1") { + const checkData = await this.HR_EDUCATIONRepo.find({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" }, + order: { EDUCATION_SEQ: "DESC" }, + }); + if ((checkData.length > 1 && checkData[0].id == item.id) || checkData.length == 1) { + education.isEducation = true; + const findIsHigh = await this.HR_EDUCATIONRepo.findOne({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "3" }, + }); + if (findIsHigh == null) { + education.isHigh = true; + } + } + } else if (item.FLAG_EDUCATION == "2") { + } else if (item.FLAG_EDUCATION == "3") { + const checkData = await this.HR_EDUCATIONRepo.find({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "3" }, + order: { EDUCATION_SEQ: "DESC" }, + }); + if ((checkData.length > 1 && checkData[0].id == item.id) || checkData.length == 1) { + education.isHigh = true; + const findIsEducation = await this.HR_EDUCATIONRepo.findOne({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" }, + }); + if (findIsEducation == null) { + education.isEducation = true; + } + } + } education.level = educationLevel == null ? 1 : educationLevel.level + 1; education.profileId = _item.id; education.degree = educationCode ? educationCode.EDUCATION_NAME : _null; diff --git a/src/entities/HR_EDUCATION.ts b/src/entities/HR_EDUCATION.ts index 5f4e34f4..57614548 100644 --- a/src/entities/HR_EDUCATION.ts +++ b/src/entities/HR_EDUCATION.ts @@ -66,4 +66,11 @@ export class HR_EDUCATION { default: null, }) MAJOR_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_EDUCATION: string; } From 848b5747130653e0237821320074db4e7a9ac284 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Mar 2025 10:36:59 +0700 Subject: [PATCH 2/6] update field isHigh & order educ.level --- src/controllers/ReportController.ts | 1 - src/entities/ProfileEducation.ts | 3 + src/entities/ProfileEducationHistory.ts | 10 + src/entities/view/viewRegistryEmployee.ts | 4 +- src/entities/view/viewRegistryOfficer.ts | 4 +- .../1741663507026-updateFieldIsHigh.ts | 266 ++++++++++++++++++ 6 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 src/migration/1741663507026-updateFieldIsHigh.ts diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 436176e6..9fad03b4 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -589,7 +589,6 @@ export class ReportController extends Controller { .orderBy(`registryEmployee.${sortBy}`, sort) .getManyAndCount(); - const mapData = []; for await (const x of lists) { let _educations:any = [] diff --git a/src/entities/ProfileEducation.ts b/src/entities/ProfileEducation.ts index 721f66a1..0b02ff11 100644 --- a/src/entities/ProfileEducation.ts +++ b/src/entities/ProfileEducation.ts @@ -225,6 +225,7 @@ export class CreateProfileEducation { positionPathId: string | null; isDate: boolean | null; isEducation: boolean | null; + isHigh?: boolean | null; note: string | null; } @@ -248,6 +249,7 @@ export class CreateProfileEducationEmployee { positionPathId: string | null; isDate: boolean | null; isEducation: boolean | null; + isHigh?: boolean | null; note: string | null; } @@ -270,5 +272,6 @@ export type UpdateProfileEducation = { positionPathId?: string | null; isDate?: boolean | null; isEducation?: boolean | null; + isHigh?: boolean | null; note?: string | null; }; diff --git a/src/entities/ProfileEducationHistory.ts b/src/entities/ProfileEducationHistory.ts index f44e2836..7a8d5497 100644 --- a/src/entities/ProfileEducationHistory.ts +++ b/src/entities/ProfileEducationHistory.ts @@ -144,6 +144,13 @@ export class ProfileEducationHistory extends EntityBase { }) isEducation: boolean; + @Column({ + nullable: true, + comment: "เป็นวุฒิศึกษาสูงสุด", + default: null, + }) + isHigh: boolean; + @Column({ nullable: true, comment: "หมายเหตุ", @@ -222,6 +229,9 @@ export class CreateProfileEducationHistory { @Column() isEducation: boolean | null; + @Column() + isHigh?: boolean | null; + @Column("uuid") profileEducationId: string | null; diff --git a/src/entities/view/viewRegistryEmployee.ts b/src/entities/view/viewRegistryEmployee.ts index fcea5b8f..aca7c6aa 100644 --- a/src/entities/view/viewRegistryEmployee.ts +++ b/src/entities/view/viewRegistryEmployee.ts @@ -61,10 +61,12 @@ import { ViewColumn, ViewEntity } from "typeorm"; eds.educationLevel, eds.isEducation, eds.isHigh, - eds.profileEmployeeId + eds.profileEmployeeId, + eds.level FROM profileEducation eds ) AS eds GROUP BY eds.profileEmployeeId + ORDER BY eds.level DESC ), EducationLevels AS ( SELECT diff --git a/src/entities/view/viewRegistryOfficer.ts b/src/entities/view/viewRegistryOfficer.ts index aa705546..4f4bdb16 100644 --- a/src/entities/view/viewRegistryOfficer.ts +++ b/src/entities/view/viewRegistryOfficer.ts @@ -67,10 +67,12 @@ import { ViewColumn, ViewEntity } from "typeorm"; eds.educationLevel, eds.isEducation, eds.isHigh, - eds.profileId + eds.profileId, + eds.level FROM profileEducation eds ) AS eds GROUP BY eds.profileId + ORDER BY eds.level DESC ), EducationLevels AS ( SELECT diff --git a/src/migration/1741663507026-updateFieldIsHigh.ts b/src/migration/1741663507026-updateFieldIsHigh.ts new file mode 100644 index 00000000..38ce4c5b --- /dev/null +++ b/src/migration/1741663507026-updateFieldIsHigh.ts @@ -0,0 +1,266 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateFieldIsHigh1741663507026 implements MigrationInterface { + name = 'UpdateFieldIsHigh1741663507026' + + public async up(queryRunner: QueryRunner): Promise { +// await queryRunner.query(`CREATE VIEW \`view_current_tenure_officer\` AS +// WITH resultData AS ( +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber +// FROM ( +// SELECT +// commandDateAffect, +// commandDateSign, +// positionName, +// positionCee, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, +// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - +// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId +// FROM +// profileSalary +// WHERE +// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) +// ORDER BY +// commandDateAffect ASC, commandDateSign ASC +// ) AS groupedPosition +// WHERE +// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign +// GROUP BY +// profileId, groupedId, positionName +// ) +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// days_diff, +// Years, +// Months, +// Days, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileId, +// orderNumber +// FROM resultData + +// UNION ALL + +// SELECT +// CURDATE() AS commandDateAffect, +// NULL AS positionName, +// NULL AS positionCee, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', +// NULL AS posNo, +// NULL AS positionExecutive, +// NULL AS positionType, +// NULL AS positionLevel, +// NULL AS OrgRoot, +// NULL AS orgChild1, +// NULL AS orgChild2, +// NULL AS orgChild3, +// NULL AS orgChild4, +// NULL AS commandCode, +// NULL AS commandName, +// NULL AS commandNo, +// NULL AS commandYear, +// NULL AS remark, +// profileId, +// NULL AS orderNumber +// FROM resultData +// `); +// await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_current_tenure_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); +// await queryRunner.query(`CREATE VIEW \`view_current_tenure_employee\` AS +// WITH resultData AS ( +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF( +// DAY, +// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileEmployeeId, +// ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber +// FROM ( +// SELECT +// commandDateAffect, +// commandDateSign, +// positionName, +// positionCee, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileEmployeeId, +// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, +// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - +// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId +// FROM +// profileSalary +// WHERE +// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) +// ORDER BY +// commandDateAffect ASC, commandDateSign ASC +// ) AS groupedPosition +// WHERE +// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign +// GROUP BY +// profileEmployeeId, groupedId, positionName +// ) +// SELECT +// commandDateAffect, +// positionName, +// positionCee, +// days_diff, +// Years, +// Months, +// Days, +// posNo, +// positionExecutive, +// positionType, +// positionLevel, +// OrgRoot, +// orgChild1, +// orgChild2, +// orgChild3, +// orgChild4, +// commandCode, +// commandName, +// commandNo, +// commandYear, +// remark, +// profileEmployeeId, +// orderNumber +// FROM resultData + +// UNION ALL + +// SELECT +// CURDATE() AS commandDateAffect, +// NULL AS positionName, +// NULL AS positionCee, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', +// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', +// NULL AS posNo, +// NULL AS positionExecutive, +// NULL AS positionType, +// NULL AS positionLevel, +// NULL AS OrgRoot, +// NULL AS orgChild1, +// NULL AS orgChild2, +// NULL AS orgChild3, +// NULL AS orgChild4, +// NULL AS commandCode, +// NULL AS commandName, +// NULL AS commandNo, +// NULL AS commandYear, +// NULL AS remark, +// profileEmployeeId, +// NULL AS orderNumber +// FROM resultData +// `); +// await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_current_tenure_employee","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]); + } + + public async down(queryRunner: QueryRunner): Promise { + // await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_employee","bma_ehr_organization_demo"]); + // await queryRunner.query(`DROP VIEW \`view_current_tenure_employee\``); + // await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_officer","bma_ehr_organization_demo"]); + // await queryRunner.query(`DROP VIEW \`view_current_tenure_officer\``); + } + +} From 4051e90e63cc46fc26316f82151888f1e14c3f22 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 11 Mar 2025 11:53:26 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=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=81=E0=B8=B2=E0=B8=A3=E0=B8=A8=E0=B8=B6=E0=B8=81?= =?UTF-8?q?=E0=B8=A9=E0=B8=B2=20Issue=20#1242?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileEducationsController.ts | 27 +++++++++++++++-- .../ProfileEducationsEmployeeController.ts | 25 ++++++++++++++++ ...ProfileEducationsEmployeeTempController.ts | 29 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index e01c7e30..d2f1c48f 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -12,11 +12,10 @@ import { Patch, Put, } from "tsoa"; - +import { Not } from "typeorm" import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; - import { ProfileEducation, CreateProfileEducation, @@ -118,6 +117,18 @@ export class ProfileEducationsController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); + if (body.isEducation) { + await this.profileEducationRepo.update( + { profileId: body.profileId, isEducation: true }, + { isEducation: false } + ); + } + if (body.isHigh) { + await this.profileEducationRepo.update( + { profileId: body.profileId, isHigh: true }, + { isHigh: false } + ); + } const before = null; const data = new ProfileEducation(); const meta = { @@ -157,6 +168,18 @@ export class ProfileEducationsController extends Controller { const record = await this.profileEducationRepo.findOneBy({ id: educationId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); + if (body.isEducation) { + await this.profileEducationRepo.update( + { profileId: record.profileId, isEducation: true, id: Not(educationId) }, + { isEducation: false } + ); + } + if (body.isHigh) { + await this.profileEducationRepo.update( + { profileId: record.profileId, isHigh: true, id: Not(educationId) }, + { isHigh: false } + ); + } const before = structuredClone(record); // const before_null = null; const history = new ProfileEducationHistory(); diff --git a/src/controllers/ProfileEducationsEmployeeController.ts b/src/controllers/ProfileEducationsEmployeeController.ts index d181ae96..34d92475 100644 --- a/src/controllers/ProfileEducationsEmployeeController.ts +++ b/src/controllers/ProfileEducationsEmployeeController.ts @@ -12,6 +12,7 @@ import { Patch, Put, } from "tsoa"; +import { Not } from "typeorm" import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; @@ -124,6 +125,18 @@ export class ProfileEducationsEmployeeController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); + if (body.isEducation) { + await this.profileEducationRepo.update( + { profileEmployeeId: body.profileEmployeeId, isEducation: true }, + { isEducation: false } + ); + } + if (body.isHigh) { + await this.profileEducationRepo.update( + { profileEmployeeId: body.profileEmployeeId, isHigh: true }, + { isHigh: false } + ); + } const before = null; const data = new ProfileEducation(); const meta = { @@ -167,6 +180,18 @@ export class ProfileEducationsEmployeeController extends Controller { "SYS_REGISTRY_EMP", record.profileEmployeeId, ); + if (body.isEducation) { + await this.profileEducationRepo.update( + { profileEmployeeId: record.profileEmployeeId, isEducation: true, id: Not(educationId) }, + { isEducation: false } + ); + } + if (body.isHigh) { + await this.profileEducationRepo.update( + { profileEmployeeId: record.profileEmployeeId, isHigh: true, id: Not(educationId) }, + { isHigh: false } + ); + } const before = structuredClone(record); const before_null = null; const history = new ProfileEducationHistory(); diff --git a/src/controllers/ProfileEducationsEmployeeTempController.ts b/src/controllers/ProfileEducationsEmployeeTempController.ts index 045e493d..7d6d4117 100644 --- a/src/controllers/ProfileEducationsEmployeeTempController.ts +++ b/src/controllers/ProfileEducationsEmployeeTempController.ts @@ -12,6 +12,7 @@ import { Patch, Put, } from "tsoa"; +import { Not } from "typeorm" import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; @@ -114,6 +115,22 @@ export class ProfileEducationsEmployeeTempController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } + if (body.isEducation) { + await this.profileEducationRepo.update( + { profileEmployeeId: body.profileEmployeeId, isEducation: true }, + { isEducation: false } + ); + } + if (body.isHigh) { + const existing = await this.profileEducationRepo.find({ + where: { profileId: body.profileEmployeeId, isHigh: true }, + }); + console.log("isHigh ",existing) + await this.profileEducationRepo.update( + { profileEmployeeId: body.profileEmployeeId, isHigh: true }, + { isHigh: false } + ); + } const before = null; const data = new ProfileEducation(); const meta = { @@ -153,6 +170,18 @@ export class ProfileEducationsEmployeeTempController extends Controller { await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); const record = await this.profileEducationRepo.findOneBy({ id: educationId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (body.isEducation) { + await this.profileEducationRepo.update( + { profileEmployeeId: record.profileEmployeeId, isEducation: true, id: Not(educationId) }, + { isEducation: false } + ); + } + if (body.isHigh) { + await this.profileEducationRepo.update( + { profileEmployeeId: record.profileEmployeeId, isHigh: true, id: Not(educationId) }, + { isHigh: false } + ); + } const before = structuredClone(record); // const before_null = null; const history = new ProfileEducationHistory(); From b55f2774a3401b717fe8ee42ccf600c7870980f4 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Tue, 11 Mar 2025 12:15:28 +0700 Subject: [PATCH 4/6] updated --- src/database/data-source.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/database/data-source.ts b/src/database/data-source.ts index 08237d5b..655d6386 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -34,9 +34,9 @@ export class MyCustomLogger implements Logger { export const AppDataSource = new DataSource({ type: "mysql", - extra: { - timezone: "+07:00", // Bangkok timezone (UTC+7) - }, + // extra: { + // timezone: "+07:00", // Bangkok timezone (UTC+7) + // }, database: process.env.DB_NAME, host: process.env.DB_HOST, port: +(process.env.DB_PORT || 3306), From 0e2b534277b3f35b147dd0b5cc8b1df0ea5764f7 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 11 Mar 2025 12:50:11 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=E0=B8=9B=E0=B8=B4=E0=B8=94=20socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app.ts b/src/app.ts index dfb4a7b3..dc1f99c6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -18,9 +18,9 @@ import { initWebSocket } from "./services/webSocket"; async function main() { await AppDataSource.initialize(); - - initWebSocket(); - + + // initWebSocket(); + const app = express(); app.use( @@ -104,8 +104,6 @@ async function main() { } runMessageQueue(); - - } main(); From 759d42c1495c2ab1d69a8ace1bc879079c7b753a Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 11 Mar 2025 13:07:59 +0700 Subject: [PATCH 6/6] =?UTF-8?q?=E0=B8=9B=E0=B8=B4=E0=B8=94=20web=20socket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 2 +- src/controllers/ReportController.ts | 2167 +++++++++++++-------------- src/services/webSocket.ts | 72 +- 3 files changed, 1089 insertions(+), 1152 deletions(-) diff --git a/src/app.ts b/src/app.ts index dc1f99c6..b0652ce4 100644 --- a/src/app.ts +++ b/src/app.ts @@ -14,7 +14,7 @@ import logMiddleware from "./middlewares/logs"; import { CommandController } from "./controllers/CommandController"; import { ProfileSalaryController } from "./controllers/ProfileSalaryController"; -import { initWebSocket } from "./services/webSocket"; +// import { initWebSocket } from "./services/webSocket"; async function main() { await AppDataSource.initialize(); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 9fad03b4..dbbf0df3 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -31,7 +31,7 @@ import { Profile } from "../entities/Profile"; import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; -import { sendWebSocket } from "../services/webSocket"; +// import { sendWebSocket } from "../services/webSocket"; @Route("api/v1/org/report") @Tags("Report") @@ -217,37 +217,30 @@ export class ReportController extends Controller { }, ) .andWhere( - positionArea != null && positionArea != "" - ? "registryOfficer.positionArea LIKE :positionArea" + positionArea != null && positionArea != "" + ? "registryOfficer.positionArea LIKE :positionArea" : "1=1", { positionArea: `%${positionArea}%`, }, ) .andWhere( - education != null && education != "" - ? "registryOfficer.degrees LIKE :degrees" - : "1=1", + education != null && education != "" ? "registryOfficer.degrees LIKE :degrees" : "1=1", { degrees: `%${education}%`, }, ) .andWhere( - educationLevel != null && educationLevel != "" - ? "registryOfficer.educationLevels LIKE :educationLevels" + educationLevel != null && educationLevel != "" + ? "registryOfficer.educationLevels LIKE :educationLevels" : "1=1", { educationLevels: `%${educationLevel}%`, }, ) - .andWhere( - field != null && field != "" - ? "registryOfficer.fields LIKE :fields" - : "1=1", - { - fields: `%${field}%`, - }, - ) + .andWhere(field != null && field != "" ? "registryOfficer.fields LIKE :fields" : "1=1", { + fields: `%${field}%`, + }) .orderBy(`registryOfficer.${sortBy}`, sort) .getManyAndCount(); @@ -306,38 +299,38 @@ export class ReportController extends Controller { const mapData = []; for await (const x of lists) { - let _educations:any = [] - if(!education && !educationLevel && !field) { - _educations = Array.isArray(x.Educations) && x.Educations != null - ? (x.Educations as any[]).filter( - (i: any) => i.isEducation == true - ) - : [] - if(_educations.length == 0) { - _educations = Array.isArray(x.Educations) && x.Educations != null - ? (x.Educations as any[]).filter( - (i: any) => i.isHigh == true - ) - : [] + let _educations: any = []; + if (!education && !educationLevel && !field) { + _educations = + Array.isArray(x.Educations) && x.Educations != null + ? (x.Educations as any[]).filter((i: any) => i.isEducation == true) + : []; + if (_educations.length == 0) { + _educations = + Array.isArray(x.Educations) && x.Educations != null + ? (x.Educations as any[]).filter((i: any) => i.isHigh == true) + : []; // if(_educations.length == 0) { // _educations = Array.isArray(x.Educations) && x.Educations != null - // ? (x.Educations as any[])[0] + // ? (x.Educations as any[])[0] // : [] // } } - } - else { - _educations = Array.isArray(x.Educations) && x.Educations != null - ? (x.Educations as any[]).filter( - (i: any) => - // i.degree === education || - // i.educationLevel === educationLevel || - // i.field === field - (education ? i.degree?.toString().includes(education) : false) || - (educationLevel ? i.educationLevel?.toString().includes(educationLevel) : false) || - (field ? i.field?.toString().includes(field) : false) - ) - : [] + } else { + _educations = + Array.isArray(x.Educations) && x.Educations != null + ? (x.Educations as any[]).filter( + (i: any) => + // i.degree === education || + // i.educationLevel === educationLevel || + // i.field === field + (education ? i.degree?.toString().includes(education) : false) || + (educationLevel + ? i.educationLevel?.toString().includes(educationLevel) + : false) || + (field ? i.field?.toString().includes(field) : false), + ) + : []; } mapData.push({ profileId: x.profileId, @@ -540,138 +533,123 @@ export class ReportController extends Controller { }, ) .andWhere( - position != null && position != "" - ? "registryEmployee.position LIKE :position" - : "1=1", + position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1", { position: `${position}`, }, ) - .andWhere(gender != null && gender != "" - ? "registryEmployee.gender LIKE :gender" - : "1=1", - { - gender: `${gender}`, - } - ) + .andWhere(gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1", { + gender: `${gender}`, + }) .andWhere( - status != null && status != "" - ? "registryEmployee.relationship LIKE :relationship" - : "1=1", + status != null && status != "" ? "registryEmployee.relationship LIKE :relationship" : "1=1", { relationship: `${status}`, }, ) .andWhere( - education != null && education != "" - ? "registryEmployee.degrees LIKE :degrees" - : "1=1", + education != null && education != "" ? "registryEmployee.degrees LIKE :degrees" : "1=1", { degrees: `%${education}%`, }, ) .andWhere( - educationLevel != null && educationLevel != "" - ? "registryEmployee.educationLevels LIKE :educationLevels" + educationLevel != null && educationLevel != "" + ? "registryEmployee.educationLevels LIKE :educationLevels" : "1=1", { educationLevels: `%${educationLevel}%`, }, ) - .andWhere( - field != null && field != "" - ? "registryEmployee.fields LIKE :fields" - : "1=1", - { - fields: `%${field}%`, - }, - ) + .andWhere(field != null && field != "" ? "registryEmployee.fields LIKE :fields" : "1=1", { + fields: `%${field}%`, + }) .orderBy(`registryEmployee.${sortBy}`, sort) .getManyAndCount(); - - const mapData = []; - for await (const x of lists) { - let _educations:any = [] - if(!education && !educationLevel && !field) { - _educations = Array.isArray(x.Educations) && x.Educations != null - ? (x.Educations as any[]).filter( - (i: any) => i.isEducation == true - ) - : [] - if(_educations.length == 0) { - _educations = Array.isArray(x.Educations) && x.Educations != null - ? (x.Educations as any[]).filter( - (i: any) => i.isHigh == true - ) - : [] - } + + const mapData = []; + for await (const x of lists) { + let _educations: any = []; + if (!education && !educationLevel && !field) { + _educations = + Array.isArray(x.Educations) && x.Educations != null + ? (x.Educations as any[]).filter((i: any) => i.isEducation == true) + : []; + if (_educations.length == 0) { + _educations = + Array.isArray(x.Educations) && x.Educations != null + ? (x.Educations as any[]).filter((i: any) => i.isHigh == true) + : []; } - else { - _educations = Array.isArray(x.Educations) && x.Educations != null + } else { + _educations = + Array.isArray(x.Educations) && x.Educations != null ? (x.Educations as any[]).filter( - (i: any) => + (i: any) => (education ? i.degree?.toString().includes(education) : false) || - (educationLevel ? i.educationLevel?.toString().includes(educationLevel) : false) || - (field ? i.field?.toString().includes(field) : false) - ) - : [] - } - mapData.push({ - profileId: x.profileEmployeeId, - citizenId: x.citizenId, - prefix: x.prefix, - firstName: x.firstName, - lastName: x.lastName, - isProbation: x.isProbation, - isLeave: x.isLeave, - isRetirement: x.isRetirement, - leaveType: x.leaveType, - posMasterNo: x.posMasterNo, - orgRootId: x.orgRootId, - orgChild1Id: x.orgChild1Id, - orgChild2Id: x.orgChild2Id, - orgChild3Id: x.orgChild3Id, - orgChild4Id: x.orgChild4Id, - orgRootName: x.orgRootName, - orgChild1Name: x.orgChild1Name, - orgChild2Name: x.orgChild2Name, - orgChild3Name: x.orgChild3Name, - orgChild4Name: x.orgChild4Name, - org: x.org, - searchShortName: x.searchShortName, - position: x.position, - posTypeName: x.posTypeName, - posLevelName: x.posLevelName, - gender: x.gender, - relationship: x.relationship, - dateAppoint: x.dateAppoint, - dateRetire: x.dateRetire, - dateRetireLaw: x.dateRetireLaw, - birthdate: x.birthdate, - Educations: _educations != null ? _educations : [], - // degree: x.degrees, - // educationLevel: x.educationLevels, - // field: x.fields, - age: x.age, - currentPosition: null, - lengthPosition: null, - positionDate: { - Years: x.Years ? x.Years : 0, - Months: x.Months ? x.Months : 0, - Days: x.Days ? x.Days : 0, - }, - levelDate: { - posExecutiveYears: x.levelYears ? x.levelYears : 0, - posExecutiveMonths: x.levelMonths ? x.levelMonths : 0, - posExecutiveDays: x.levelDays ? x.levelDays : 0, - }, - }); + (educationLevel + ? i.educationLevel?.toString().includes(educationLevel) + : false) || + (field ? i.field?.toString().includes(field) : false), + ) + : []; } - return new HttpSuccess({ - data: mapData, - total: total, - }); -} + mapData.push({ + profileId: x.profileEmployeeId, + citizenId: x.citizenId, + prefix: x.prefix, + firstName: x.firstName, + lastName: x.lastName, + isProbation: x.isProbation, + isLeave: x.isLeave, + isRetirement: x.isRetirement, + leaveType: x.leaveType, + posMasterNo: x.posMasterNo, + orgRootId: x.orgRootId, + orgChild1Id: x.orgChild1Id, + orgChild2Id: x.orgChild2Id, + orgChild3Id: x.orgChild3Id, + orgChild4Id: x.orgChild4Id, + orgRootName: x.orgRootName, + orgChild1Name: x.orgChild1Name, + orgChild2Name: x.orgChild2Name, + orgChild3Name: x.orgChild3Name, + orgChild4Name: x.orgChild4Name, + org: x.org, + searchShortName: x.searchShortName, + position: x.position, + posTypeName: x.posTypeName, + posLevelName: x.posLevelName, + gender: x.gender, + relationship: x.relationship, + dateAppoint: x.dateAppoint, + dateRetire: x.dateRetire, + dateRetireLaw: x.dateRetireLaw, + birthdate: x.birthdate, + Educations: _educations != null ? _educations : [], + // degree: x.degrees, + // educationLevel: x.educationLevels, + // field: x.fields, + age: x.age, + currentPosition: null, + lengthPosition: null, + positionDate: { + Years: x.Years ? x.Years : 0, + Months: x.Months ? x.Months : 0, + Days: x.Days ? x.Days : 0, + }, + levelDate: { + posExecutiveYears: x.levelYears ? x.levelYears : 0, + posExecutiveMonths: x.levelMonths ? x.levelMonths : 0, + posExecutiveDays: x.levelDays ? x.levelDays : 0, + }, + }); + } + return new HttpSuccess({ + data: mapData, + total: total, + }); + } /** * API Report1 @@ -1339,171 +1317,183 @@ export class ReportController extends Controller { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // } // (async () => { - const orgRootData = await this.orgRootRepository.find({ - where: { - id: rootId, - // orgRevisionId: orgRevision.id, - }, - order: { orgRootOrder: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgRootData = await this.orgRootRepository.find({ + where: { + id: rootId, + // orgRevisionId: orgRevision.id, + }, + order: { orgRootOrder: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null; - const orgChild1Data = await this.child1Repository.find({ - where: { - orgRootId: In(orgRootIds), - }, - order: { orgChild1Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null; + const orgChild1Data = await this.child1Repository.find({ + where: { + orgRootId: In(orgRootIds), + }, + order: { orgChild1Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; - const orgChild2Data = await this.child2Repository.find({ - where: { - orgChild1: In(orgChild1Ids), - }, - order: { orgChild2Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; + const orgChild2Data = await this.child2Repository.find({ + where: { + orgChild1: In(orgChild1Ids), + }, + order: { orgChild2Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; - const orgChild3Data = await this.child3Repository.find({ - where: { - orgChild2: In(orgChild2Ids), - }, - order: { orgChild3Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; + const orgChild3Data = await this.child3Repository.find({ + where: { + orgChild2: In(orgChild2Ids), + }, + order: { orgChild3Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; - const orgChild4Data = await this.child4Repository.find({ - where: { - orgChild3: In(orgChild3Ids), - }, - order: { orgChild4Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; + const orgChild4Data = await this.child4Repository.find({ + where: { + orgChild3: In(orgChild3Ids), + }, + order: { orgChild4Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - let orgRevisionActive: any = await this.orgRevisionRepository.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + let orgRevisionActive: any = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + relations: [ + "posMasters", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); + if (orgRevisionActive == null) { + const _orgRevisionActive = await this.orgRevisionRepository.find({ + order: { createdAt: "DESC" }, + skip: 1, relations: [ "posMasters", "posMasters.positions", @@ -1512,30 +1502,392 @@ export class ReportController extends Controller { "posMasters.positions.posExecutive", ], }); - if (orgRevisionActive == null) { - const _orgRevisionActive = await this.orgRevisionRepository.find({ - order: { createdAt: "DESC" }, - skip: 1, - relations: [ - "posMasters", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); - if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; - } + if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; + } - let data = new Array(); - let _node: any; - let no = 1; - for (let orgRoot of orgRootData) { + let data = new Array(); + let _node: any; + let no = 1; + for (let orgRoot of orgRootData) { + await Promise.all( + orgRoot.posMasters + .sort((a, b) => a.posMasterOrder - b.posMasterOrder) + .map(async (posMaster) => { + if (posMaster.orgChild1Id == null) { + const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; + const posType = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posType != null) + .map((x) => x.posType.posTypeName), + ), + ]; + const posLevel = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posLevel != null) + .map((x) => x.posLevel.posLevelName), + ), + ]; + const posExecutive = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posExecutive != null) + .map((x) => x.posExecutive.posExecutiveName), + ), + ]; + let positionMasterProfileOld: any = null; + if (posMaster.next_holder != null) { + positionMasterProfileOld = posMaster.next_holder.current_holders.find( + (x) => x.orgRevisionId == orgRevisionActive.id, + ); + } + + let positionMasterOld: any = null; + let profilePositionName: any = []; + let profilePosType: any = []; + let profilePosLevel: any = []; + let profilePosExecutive: any = []; + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { + positionMasterOld = orgRevisionActive.posMasters.find( + (x: any) => + x.orgRevisionId == orgRevisionActive.id && + x.ancestorDNA == posMaster.ancestorDNA, + ); + profilePositionName = [ + ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), + ]; + profilePosType = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posType != null) + .map((x: any) => x.posType.posTypeName), + ), + ]; + profilePosLevel = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posLevel != null) + .map((x: any) => x.posLevel.posLevelName), + ), + ]; + profilePosExecutive = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posExecutive != null) + .map((x: any) => x.posExecutive.posExecutiveName), + ), + ]; + } + let education: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileEducations != null && + posMaster.next_holder.profileEducations.length > 0 + ) { + let _education: any = posMaster.next_holder.profileEducations.sort( + (a, b) => + (b.finishDate == null ? 0 : b.finishDate.getTime()) - + (a.finishDate == null ? 0 : a.finishDate.getTime()), + ); + if (_education.length > 0) { + education = _education[0]; + } + } + let salary: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileSalary != null && + posMaster.next_holder.profileSalary.length > 0 + ) { + let _salary: any = posMaster.next_holder.profileSalary.sort( + (a, b) => + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), + ); + if (_salary.length > 0) { + salary = _salary[0]; + } + } + + let node = { + posMasterOrder: posMaster.posMasterOrder, // + isSit: posMaster.isSit, // + orgTreeName: orgRoot.orgRootName, + orgTreeShortName: orgRoot.orgRootShortName, + posMasterNo: posMaster.posMasterNo, + positionName: + posMaster.next_holder == null + ? positionName.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.positionName + : posMaster.next_holder.position, + posType: + posMaster.next_holder == null + ? posType.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posType + ?.posTypeName + : posMaster.next_holder.posType == null + ? "-" + : posMaster.next_holder.posType.posTypeName, + posLevel: + posMaster.next_holder == null + ? posLevel.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posLevel + ?.posLevelName + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + posExecutive: + posMaster.next_holder == null + ? posExecutive.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posExecutive?.posExecutiveName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posExecutive?.posExecutiveName, + + profileOrgName: + posMaster.next_holder == null + ? orgRoot.orgRootName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4Name + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3Name + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2Name + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1Name + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootName + : "-", + profileOrgShortName: + posMaster.next_holder == null + ? orgRoot.orgRootShortName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4ShortName + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3ShortName + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2ShortName + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1ShortName + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootShortName + : "-", + profileFullname: + posMaster.next_holder == null + ? "- ว่าง -" + : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, + profilePosMasterNo: + posMaster.next_holder == null + ? positionMasterOld == null + ? "-" + : positionMasterOld.posMasterNo + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.posMasterNo, + profilePositionName: + posMaster.next_holder == null + ? positionMasterOld == null + ? positionName.join(" หรือ ") + : profilePositionName.join(" หรือ ") + : posMaster.next_holder.position, + profilePosType: + posMaster.next_holder == null + ? positionMasterOld == null + ? posType.join(" หรือ ") + : profilePosType.join(" หรือ ") + : posMaster.next_holder.posType == null + ? "-" + : posMaster.next_holder.posType.posTypeName, + profilePosLevel: + posMaster.next_holder == null + ? positionMasterOld == null + ? posLevel.join(" หรือ ") + : profilePosLevel.join(" หรือ ") + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + profilePosExecutive: + posMaster.next_holder == null + ? positionMasterOld == null + ? posExecutive.join(" หรือ ") + : profilePosExecutive.join(" หรือ ") + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posExecutive?.posExecutiveName, + education: education == "" ? "" : education.degree, + salary: salary == "" ? "" : salary.amount, + reason: posMaster.reason, + }; + if (_node == null) { + const head = { + posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), + profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + reason: "", + }; + data.push(head); + const _head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName || + node.profileOrgShortName != _node.profileOrgShortName || + node.profileOrgName != _node.profileOrgName + ) { + const head = { + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName ? "" : node.orgTreeShortName, + profileFullname: + node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, + posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + reason: "", + }; + data.push(head); + _node == null; + } + const head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", + reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(head); + } + no += 1; + _node = node; + } + }), + ); + _node = null; + + for (let orgChild1 of orgChild1Data.filter( + (orgChild1) => orgChild1.orgRootId === orgRoot.id, + )) { await Promise.all( - orgRoot.posMasters + orgChild1.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild1Id == null) { + if (posMaster.orgChild2Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -1635,8 +1987,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgRoot.orgRootName, - orgTreeShortName: orgRoot.orgRootShortName, + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -1677,7 +2029,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgRoot.orgRootName + ? orgChild1.orgChild1Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1693,7 +2045,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgRoot.orgRootShortName + ? orgChild1.orgChild1ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1910,14 +2262,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild1 of orgChild1Data.filter( - (orgChild1) => orgChild1.orgRootId === orgRoot.id, + for (let orgChild2 of orgChild2Data.filter( + (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, )) { await Promise.all( - orgChild1.posMasters + orgChild2.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild2Id == null) { + if (posMaster.orgChild3Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -2017,8 +2369,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild1.orgChild1Name, - orgTreeShortName: orgChild1.orgChild1ShortName, + orgTreeName: orgChild2.orgChild2Name, + orgTreeShortName: orgChild2.orgChild2ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -2059,7 +2411,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild1.orgChild1Name + ? orgChild2.orgChild2Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2075,7 +2427,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild1.orgChild1ShortName + ? orgChild2.orgChild2ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2306,14 +2658,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild2 of orgChild2Data.filter( - (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, + for (let orgChild3 of orgChild3Data.filter( + (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, )) { await Promise.all( - orgChild2.posMasters + orgChild3.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild3Id == null) { + if (posMaster.orgChild4Id == null) { const positionName = [ ...new Set(posMaster.positions.map((x) => x.positionName)), ]; @@ -2415,8 +2767,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild2.orgChild2Name, - orgTreeShortName: orgChild2.orgChild2ShortName, + orgTreeName: orgChild3.orgChild3Name, + orgTreeShortName: orgChild3.orgChild3ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -2457,7 +2809,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild2.orgChild2Name + ? orgChild3.orgChild3Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2473,7 +2825,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild2.orgChild2ShortName + ? orgChild3.orgChild3ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2709,246 +3061,333 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild3 of orgChild3Data.filter( - (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, + for (let orgChild4 of orgChild4Data.filter( + (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, )) { await Promise.all( - orgChild3.posMasters + orgChild4.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild4Id == null) { - const positionName = [ - ...new Set(posMaster.positions.map((x) => x.positionName)), + const positionName = [ + ...new Set(posMaster.positions.map((x) => x.positionName)), + ]; + const posType = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posType != null) + .map((x) => x.posType.posTypeName), + ), + ]; + const posLevel = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posLevel != null) + .map((x) => x.posLevel.posLevelName), + ), + ]; + const posExecutive = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posExecutive != null) + .map((x) => x.posExecutive.posExecutiveName), + ), + ]; + let positionMasterProfileOld: any = null; + if (posMaster.next_holder != null) { + positionMasterProfileOld = posMaster.next_holder.current_holders.find( + (x) => x.orgRevisionId == orgRevisionActive.id, + ); + } + + let positionMasterOld: any = null; + let profilePositionName: any = []; + let profilePosType: any = []; + let profilePosLevel: any = []; + let profilePosExecutive: any = []; + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { + positionMasterOld = orgRevisionActive.posMasters.find( + (x: any) => + x.orgRevisionId == orgRevisionActive.id && + x.ancestorDNA == posMaster.ancestorDNA, + ); + profilePositionName = [ + ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), ]; - const posType = [ + profilePosType = [ ...new Set( - posMaster.positions + positionMasterOld.positions .filter((x: any) => x.posType != null) - .map((x) => x.posType.posTypeName), + .map((x: any) => x.posType.posTypeName), ), ]; - const posLevel = [ + profilePosLevel = [ ...new Set( - posMaster.positions + positionMasterOld.positions .filter((x: any) => x.posLevel != null) - .map((x) => x.posLevel.posLevelName), + .map((x: any) => x.posLevel.posLevelName), ), ]; - const posExecutive = [ + profilePosExecutive = [ ...new Set( - posMaster.positions + positionMasterOld.positions .filter((x: any) => x.posExecutive != null) - .map((x) => x.posExecutive.posExecutiveName), + .map((x: any) => x.posExecutive.posExecutiveName), ), ]; - let positionMasterProfileOld: any = null; - if (posMaster.next_holder != null) { - positionMasterProfileOld = posMaster.next_holder.current_holders.find( - (x) => x.orgRevisionId == orgRevisionActive.id, - ); + } + let education: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileEducations != null && + posMaster.next_holder.profileEducations.length > 0 + ) { + let _education: any = posMaster.next_holder.profileEducations.sort( + (a, b) => + (b.finishDate == null ? 0 : b.finishDate.getTime()) - + (a.finishDate == null ? 0 : a.finishDate.getTime()), + ); + if (_education.length > 0) { + education = _education[0]; } + } + let salary: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileSalary != null && + posMaster.next_holder.profileSalary.length > 0 + ) { + let _salary: any = posMaster.next_holder.profileSalary.sort( + (a, b) => + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), + ); + if (_salary.length > 0) { + salary = _salary[0]; + } + } - let positionMasterOld: any = null; - let profilePositionName: any = []; - let profilePosType: any = []; - let profilePosLevel: any = []; - let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { - positionMasterOld = orgRevisionActive.posMasters.find( - (x: any) => - x.orgRevisionId == orgRevisionActive.id && - x.ancestorDNA == posMaster.ancestorDNA, - ); - profilePositionName = [ - ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), - ]; - profilePosType = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posType != null) - .map((x: any) => x.posType.posTypeName), - ), - ]; - profilePosLevel = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posLevel != null) - .map((x: any) => x.posLevel.posLevelName), - ), - ]; - profilePosExecutive = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posExecutive != null) - .map((x: any) => x.posExecutive.posExecutiveName), - ), - ]; - } - let education: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileEducations != null && - posMaster.next_holder.profileEducations.length > 0 - ) { - let _education: any = posMaster.next_holder.profileEducations.sort( - (a, b) => - (b.finishDate == null ? 0 : b.finishDate.getTime()) - - (a.finishDate == null ? 0 : a.finishDate.getTime()), - ); - if (_education.length > 0) { - education = _education[0]; - } - } - let salary: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileSalary != null && - posMaster.next_holder.profileSalary.length > 0 - ) { - let _salary: any = posMaster.next_holder.profileSalary.sort( - (a, b) => - (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - - (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), - ); - if (_salary.length > 0) { - salary = _salary[0]; - } - } - - let node = { - posMasterOrder: posMaster.posMasterOrder, // - isSit: posMaster.isSit, // - orgTreeName: orgChild3.orgChild3Name, - orgTreeShortName: orgChild3.orgChild3ShortName, - posMasterNo: posMaster.posMasterNo, - positionName: - posMaster.next_holder == null - ? positionName.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.positionName - : posMaster.next_holder.position, - posType: - posMaster.next_holder == null - ? posType.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posType?.posTypeName - : posMaster.next_holder.posType == null - ? "-" - : posMaster.next_holder.posType.posTypeName, - posLevel: - posMaster.next_holder == null - ? posLevel.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posLevel?.posLevelName - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - posExecutive: - posMaster.next_holder == null - ? posExecutive.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posExecutive?.posExecutiveName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.positions.find( - (x: any) => x.positionIsSelected == true, - )?.posExecutive?.posExecutiveName, - - profileOrgName: - posMaster.next_holder == null - ? orgChild3.orgChild3Name - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4Name - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3Name - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2Name - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1Name - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootName - : "-", - profileOrgShortName: - posMaster.next_holder == null - ? orgChild3.orgChild3ShortName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4ShortName - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3ShortName - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2ShortName - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1ShortName - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootShortName - : "-", - profileFullname: - posMaster.next_holder == null - ? "- ว่าง -" - : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, - profilePosMasterNo: - posMaster.next_holder == null - ? positionMasterOld == null - ? "-" - : positionMasterOld.posMasterNo - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.posMasterNo, - profilePositionName: - posMaster.next_holder == null - ? positionMasterOld == null - ? positionName.join(" หรือ ") - : profilePositionName.join(" หรือ ") + let node = { + posMasterOrder: posMaster.posMasterOrder, // + isSit: posMaster.isSit, // + orgTreeName: orgChild4.orgChild4Name, + orgTreeShortName: orgChild4.orgChild4ShortName, + posMasterNo: posMaster.posMasterNo, + positionName: + posMaster.next_holder == null + ? positionName.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.positionName : posMaster.next_holder.position, - profilePosType: - posMaster.next_holder == null - ? positionMasterOld == null - ? posType.join(" หรือ ") - : profilePosType.join(" หรือ ") + posType: + posMaster.next_holder == null + ? posType.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posType?.posTypeName : posMaster.next_holder.posType == null ? "-" : posMaster.next_holder.posType.posTypeName, - profilePosLevel: - posMaster.next_holder == null - ? positionMasterOld == null - ? posLevel.join(" หรือ ") - : profilePosLevel.join(" หรือ ") + posLevel: + posMaster.next_holder == null + ? posLevel.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posLevel?.posLevelName : posMaster.next_holder.posLevel == null ? "-" : posMaster.next_holder.posLevel.posLevelName, - profilePosExecutive: - posMaster.next_holder == null - ? positionMasterOld == null - ? posExecutive.join(" หรือ ") - : profilePosExecutive.join(" หรือ ") + posExecutive: + posMaster.next_holder == null + ? posExecutive.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posExecutive?.posExecutiveName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.positions.find( (x: any) => x.positionIsSelected == true, )?.posExecutive?.posExecutiveName, - education: education == "" ? "" : education.degree, - salary: salary == "" ? "" : salary.amount, - reason: posMaster.reason, + + profileOrgName: + posMaster.next_holder == null + ? orgChild4.orgChild4Name + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4Name + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3Name + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2Name + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1Name + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootName + : "-", + profileOrgShortName: + posMaster.next_holder == null + ? orgChild4.orgChild4ShortName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4ShortName + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3ShortName + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2ShortName + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1ShortName + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootShortName + : "-", + profileFullname: + posMaster.next_holder == null + ? "- ว่าง -" + : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, + profilePosMasterNo: + posMaster.next_holder == null + ? positionMasterOld == null + ? "-" + : positionMasterOld.posMasterNo + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.posMasterNo, + profilePositionName: + posMaster.next_holder == null + ? positionMasterOld == null + ? positionName.join(" หรือ ") + : profilePositionName.join(" หรือ ") + : posMaster.next_holder.position, + profilePosType: + posMaster.next_holder == null + ? positionMasterOld == null + ? posType.join(" หรือ ") + : profilePosType.join(" หรือ ") + : posMaster.next_holder.posType == null + ? "-" + : posMaster.next_holder.posType.posTypeName, + profilePosLevel: + posMaster.next_holder == null + ? positionMasterOld == null + ? posLevel.join(" หรือ ") + : profilePosLevel.join(" หรือ ") + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + profilePosExecutive: + posMaster.next_holder == null + ? positionMasterOld == null + ? posExecutive.join(" หรือ ") + : profilePosExecutive.join(" หรือ ") + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posExecutive?.posExecutiveName, + education: education == "" ? "" : education.degree, + salary: salary == "" ? "" : salary.amount, + reason: posMaster.reason, + }; + if (_node == null) { + const head = { + posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), + profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: Extension.ToThaiNumber( + node.profileOrgShortName.toString(), + ), + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + reason: "", }; - if (_node == null) { + data.push(head); + const _head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null + ? "" + : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null + ? "" + : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber( + node.profilePosMasterNo.toString(), + ), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null + ? "" + : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary + ? Extension.ToThaiNumber(node.salary.toLocaleString()) + : "", + reason: + node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName || + node.profileOrgShortName != _node.profileOrgShortName || + node.profileOrgName != _node.profileOrgName + ) { const head = { - posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), - posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName + ? "" + : node.orgTreeShortName, + profileFullname: + node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, + posExecutive: + node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, positionName: "", posType: "", posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber( - node.profileOrgShortName.toString(), - ), + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -2958,577 +3397,75 @@ export class ReportController extends Controller { reason: "", }; data.push(head); - const _head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null - ? "" - : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null - ? "" - : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber( - node.profilePosMasterNo.toString(), - ), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null - ? "" - : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary - ? Extension.ToThaiNumber(node.salary.toLocaleString()) - : "", - reason: - node.reason == null - ? "" - : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName || - node.profileOrgShortName != _node.profileOrgShortName || - node.profileOrgName != _node.profileOrgName - ) { - const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName - ? "" - : node.orgTreeShortName, - profileFullname: - node.profileOrgName == _node.profileOrgName - ? "" - : node.profileOrgName, - posExecutive: - node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: - node.profileOrgShortName == _node.profileOrgShortName - ? "" - : node.profileOrgShortName, - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - reason: "", - }; - data.push(head); - _node == null; - } - const head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null - ? "" - : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null - ? "" - : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber( - node.profilePosMasterNo.toString(), - ), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null - ? "" - : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary - ? Extension.ToThaiNumber(node.salary.toLocaleString()) - : "", - reason: - node.reason == null - ? "" - : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(head); + _node == null; } - no += 1; - _node = node; + const head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null + ? "" + : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null + ? "" + : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber( + node.profilePosMasterNo.toString(), + ), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null + ? "" + : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary + ? Extension.ToThaiNumber(node.salary.toLocaleString()) + : "", + reason: + node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(head); } + no += 1; + _node = node; }), ); _node = null; - - for (let orgChild4 of orgChild4Data.filter( - (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, - )) { - await Promise.all( - orgChild4.posMasters - .sort((a, b) => a.posMasterOrder - b.posMasterOrder) - .map(async (posMaster) => { - const positionName = [ - ...new Set(posMaster.positions.map((x) => x.positionName)), - ]; - const posType = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posType != null) - .map((x) => x.posType.posTypeName), - ), - ]; - const posLevel = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posLevel != null) - .map((x) => x.posLevel.posLevelName), - ), - ]; - const posExecutive = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posExecutive != null) - .map((x) => x.posExecutive.posExecutiveName), - ), - ]; - let positionMasterProfileOld: any = null; - if (posMaster.next_holder != null) { - positionMasterProfileOld = posMaster.next_holder.current_holders.find( - (x) => x.orgRevisionId == orgRevisionActive.id, - ); - } - - let positionMasterOld: any = null; - let profilePositionName: any = []; - let profilePosType: any = []; - let profilePosLevel: any = []; - let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { - positionMasterOld = orgRevisionActive.posMasters.find( - (x: any) => - x.orgRevisionId == orgRevisionActive.id && - x.ancestorDNA == posMaster.ancestorDNA, - ); - profilePositionName = [ - ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), - ]; - profilePosType = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posType != null) - .map((x: any) => x.posType.posTypeName), - ), - ]; - profilePosLevel = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posLevel != null) - .map((x: any) => x.posLevel.posLevelName), - ), - ]; - profilePosExecutive = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posExecutive != null) - .map((x: any) => x.posExecutive.posExecutiveName), - ), - ]; - } - let education: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileEducations != null && - posMaster.next_holder.profileEducations.length > 0 - ) { - let _education: any = posMaster.next_holder.profileEducations.sort( - (a, b) => - (b.finishDate == null ? 0 : b.finishDate.getTime()) - - (a.finishDate == null ? 0 : a.finishDate.getTime()), - ); - if (_education.length > 0) { - education = _education[0]; - } - } - let salary: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileSalary != null && - posMaster.next_holder.profileSalary.length > 0 - ) { - let _salary: any = posMaster.next_holder.profileSalary.sort( - (a, b) => - (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - - (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), - ); - if (_salary.length > 0) { - salary = _salary[0]; - } - } - - let node = { - posMasterOrder: posMaster.posMasterOrder, // - isSit: posMaster.isSit, // - orgTreeName: orgChild4.orgChild4Name, - orgTreeShortName: orgChild4.orgChild4ShortName, - posMasterNo: posMaster.posMasterNo, - positionName: - posMaster.next_holder == null - ? positionName.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.positionName - : posMaster.next_holder.position, - posType: - posMaster.next_holder == null - ? posType.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posType?.posTypeName - : posMaster.next_holder.posType == null - ? "-" - : posMaster.next_holder.posType.posTypeName, - posLevel: - posMaster.next_holder == null - ? posLevel.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posLevel?.posLevelName - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - posExecutive: - posMaster.next_holder == null - ? posExecutive.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posExecutive?.posExecutiveName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.positions.find( - (x: any) => x.positionIsSelected == true, - )?.posExecutive?.posExecutiveName, - - profileOrgName: - posMaster.next_holder == null - ? orgChild4.orgChild4Name - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4Name - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3Name - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2Name - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1Name - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootName - : "-", - profileOrgShortName: - posMaster.next_holder == null - ? orgChild4.orgChild4ShortName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4ShortName - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3ShortName - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2ShortName - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1ShortName - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootShortName - : "-", - profileFullname: - posMaster.next_holder == null - ? "- ว่าง -" - : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, - profilePosMasterNo: - posMaster.next_holder == null - ? positionMasterOld == null - ? "-" - : positionMasterOld.posMasterNo - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.posMasterNo, - profilePositionName: - posMaster.next_holder == null - ? positionMasterOld == null - ? positionName.join(" หรือ ") - : profilePositionName.join(" หรือ ") - : posMaster.next_holder.position, - profilePosType: - posMaster.next_holder == null - ? positionMasterOld == null - ? posType.join(" หรือ ") - : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null - ? "-" - : posMaster.next_holder.posType.posTypeName, - profilePosLevel: - posMaster.next_holder == null - ? positionMasterOld == null - ? posLevel.join(" หรือ ") - : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - profilePosExecutive: - posMaster.next_holder == null - ? positionMasterOld == null - ? posExecutive.join(" หรือ ") - : profilePosExecutive.join(" หรือ ") - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.positions.find( - (x: any) => x.positionIsSelected == true, - )?.posExecutive?.posExecutiveName, - education: education == "" ? "" : education.degree, - salary: salary == "" ? "" : salary.amount, - reason: posMaster.reason, - }; - if (_node == null) { - const head = { - posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), - posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber( - node.profileOrgShortName.toString(), - ), - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - reason: "", - }; - data.push(head); - const _head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null - ? "" - : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null - ? "" - : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber( - node.profilePosMasterNo.toString(), - ), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null - ? "" - : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary - ? Extension.ToThaiNumber(node.salary.toLocaleString()) - : "", - reason: - node.reason == null - ? "" - : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName || - node.profileOrgShortName != _node.profileOrgShortName || - node.profileOrgName != _node.profileOrgName - ) { - const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName - ? "" - : node.orgTreeShortName, - profileFullname: - node.profileOrgName == _node.profileOrgName - ? "" - : node.profileOrgName, - posExecutive: - node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: - node.profileOrgShortName == _node.profileOrgShortName - ? "" - : node.profileOrgShortName, - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - reason: "", - }; - data.push(head); - _node == null; - } - const head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null - ? "" - : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null - ? "" - : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber( - node.profilePosMasterNo.toString(), - ), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null - ? "" - : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary - ? Extension.ToThaiNumber(node.salary.toLocaleString()) - : "", - reason: - node.reason == null - ? "" - : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(head); - } - no += 1; - _node = node; - }), - ); - _node = null; - } } } } } + } // const metaData = { template: "report2", reportName: "report2", data: { data } }; // sendWebSocket(metaData); diff --git a/src/services/webSocket.ts b/src/services/webSocket.ts index c78b6428..5f088555 100644 --- a/src/services/webSocket.ts +++ b/src/services/webSocket.ts @@ -1,43 +1,43 @@ -import { WebSocketServer } from "ws"; +// import { WebSocketServer } from "ws"; -let wss: WebSocketServer; +// let wss: WebSocketServer; -export function initWebSocket() { - wss = new WebSocketServer({ port: 13002, path: "/api/v1/org-socket" }); +// export function initWebSocket() { +// wss = new WebSocketServer({ port: 13002, path: "/api/v1/org-socket" }); - // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket - wss.on("upgrade", (request: any, socket: any, head: any) => { - console.log("🔹 Handling upgrade request..."); - wss.handleUpgrade(request, socket, head, (ws: any) => { - console.log("🔹 WebSocket connection established"); - wss.emit("connection", ws, request); - }); - }); +// // การจัดการคำขออัปเกรดจาก HTTP เป็น WebSocket +// wss.on("upgrade", (request: any, socket: any, head: any) => { +// console.log("🔹 Handling upgrade request..."); +// wss.handleUpgrade(request, socket, head, (ws: any) => { +// console.log("🔹 WebSocket connection established"); +// wss.emit("connection", ws, request); +// }); +// }); - wss.on("connection", (ws: any) => { - console.log("✅ Client connected to WebSocket"); +// wss.on("connection", (ws: any) => { +// console.log("✅ Client connected to WebSocket"); - ws.on("close", () => { - console.log("❌ Client disconnected"); - }); +// ws.on("close", () => { +// console.log("❌ Client disconnected"); +// }); - ws.on("error", (error: any) => { - console.error("WebSocket error:", error); - }); - }); -} +// ws.on("error", (error: any) => { +// console.error("WebSocket error:", error); +// }); +// }); +// } -export async function sendWebSocket(data: any) { - if (!wss) initWebSocket(); - wss.clients.forEach((client: any) => { - if (client.readyState === WebSocket.OPEN) { - const message = JSON.stringify(data); - console.log("📤 Sending data to client:", message); - client.send(message, (err: any) => { - if (err) { - console.error("❌ Error sending message:", err); - } - }); - } - }); -} +// export async function sendWebSocket(data: any) { +// if (!wss) initWebSocket(); +// wss.clients.forEach((client: any) => { +// if (client.readyState === WebSocket.OPEN) { +// const message = JSON.stringify(data); +// console.log("📤 Sending data to client:", message); +// client.send(message, (err: any) => { +// if (err) { +// console.error("❌ Error sending message:", err); +// } +// }); +// } +// }); +// }