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\``); + } + +}